Check whether there is a global language file for the given language code. This is used to decide whether a user-provided language is available. lru_cache should have a maxsize to prevent from memory exhaustion attacks, as the provided language codes are taken from the HTTP req
(lang_code)
| 464 | |
| 465 | @functools.lru_cache(maxsize=1000) |
| 466 | def check_for_language(lang_code): |
| 467 | """ |
| 468 | Check whether there is a global language file for the given language |
| 469 | code. This is used to decide whether a user-provided language is |
| 470 | available. |
| 471 | |
| 472 | lru_cache should have a maxsize to prevent from memory exhaustion attacks, |
| 473 | as the provided language codes are taken from the HTTP request. See also |
| 474 | <https://www.djangoproject.com/weblog/2007/oct/26/security-fix/>. |
| 475 | """ |
| 476 | # First, a quick check to make sure lang_code is well-formed (#21458) |
| 477 | if lang_code is None or not language_code_re.search(lang_code): |
| 478 | return False |
| 479 | return any( |
| 480 | gettext_module.find("django", path, [to_locale(lang_code)]) is not None |
| 481 | for path in all_locale_paths() |
| 482 | ) |
| 483 | |
| 484 | |
| 485 | @functools.lru_cache |
no test coverage detected