MCPcopy
hub / github.com/django/django / check_for_language

Function check_for_language

django/utils/translation/trans_real.py:466–482  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

464
465@functools.lru_cache(maxsize=1000)
466def 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

Callers 2

Calls 4

to_localeFunction · 0.85
all_locale_pathsFunction · 0.85
searchMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected