https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/utils/translation/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/utils/translation/__pycache__/trans_real.cpython-310.pyc
o

��Ih�U�@s�dZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZdd
lmZmZiae	�Zda dZ!dZ"edej#�Z$edej%�Z&ed�Z'ee�dd��Z(Gdd�d�Z)Gdd�dej*�Z+dd�Z,dd�Z-dd�Z.dd �Z/d!d"�Z0d#d$�Z1d%d&�Z2d'd(�Zd)d*�Z3d+d,�Z4d-d.�Z5d/d0�Z6d1d2�Z7d3d4�Z8ej9d5d6�d7d8��Z:e�9�d9d:��Z;ej9d5d6�dFd<d=��Z<dFd>d?�Z=dFd@dA�Z>ej9d5d6�dBdC��Z?dDdE�Z@dS)GzTranslation helper functions.�N)�Local)�apps)�settings)�	LANG_INFO)�AppRegistryNotReady)�setting_changed)�receiver)�_lazy_re_compile)�SafeData�	mark_safe�)�to_language�	to_locale�i�a
        ([A-Za-z]{1,8}(?:-[A-Za-z0-9]{1,8})*|\*)      # "en", "en-au", "x-y-z", "es-419", "*"
        (?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:\.0{,3})?))?  # Optional "q=1.00", "q=0.8"
        (?:\s*,\s*|$)                                 # Multiple accepts per header.
        z3^[a-z]{1,8}(?:-[a-z0-9]{1,8})*(?:@[a-z0-9]{1,20})?$z^/(\w+([@-]\w+)?)(/|$)cKs,|ddvrt��t��t��dSdS)zy
    Reset global state when LANGUAGES setting has been changed, as some
    languages should no longer be accepted.
    �setting)�	LANGUAGES�
LANGUAGE_CODEN)�check_for_language�cache_clear�
get_languages�get_supported_language_variant)�kwargs�r�E/usr/lib/python3/dist-packages/django/utils/translation/trans_real.py�reset_cache7s
�rc@s\eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zdd�ZdS)�TranslationCatalogz�
    Simulate a dict for DjangoTranslation._catalog so as multiple catalogs
    with different plural equations are kept separate.
    NcCs:|r|j��gnig|_|r|jg|_dSdd�g|_dS)NcS�t|dk�S�Nr��int��nrrr�<lambda>J�z-TranslationCatalog.__init__.<locals>.<lambda>)�_catalog�copy�	_catalogs�plural�_plurals)�self�transrrr�__init__Hs"zTranslationCatalog.__init__c	Cs4|jD]}z||WStyYqwt|���N)r&�KeyError)r)�key�catrrr�__getitem__Ls
�zTranslationCatalog.__getitem__cCs||jd|<dS�Nr)r&)r)r.�valuerrr�__setitem__TszTranslationCatalog.__setitem__cst�fdd�|jD��S)Nc3s�|]}�|vVqdSr,r)�.0r/�r.rr�	<genexpr>Xs�z2TranslationCatalog.__contains__.<locals>.<genexpr>)�anyr&)r)r.rr5r�__contains__WszTranslationCatalog.__contains__cc� �|jD]	}|��EdHqdSr,)r&�items�r)r/rrrr:Z��
�zTranslationCatalog.itemsccr9r,)r&�keysr;rrrr=^r<zTranslationCatalog.keyscCs`t|j|j�D]\}}|jj|jkr|�|j�dSq|j�d|j���|j�d|j�dSr1)	�zipr&r(r'�__code__�updater$�insertr%)r)r*r/r'rrrr@bs�zTranslationCatalog.updatecCs2t�}|jD]}|�||�}||ur|Sq|Sr,)�objectr&�get)r)r.�default�missingr/�resultrrrrCls
�zTranslationCatalog.getcCs>t|j|j�D]\}}|�|||�f�}|dur|Sqt�r,)r>r&r(rCr-)r)�msgid�numr/r'�tmsgrrrr'ts�zTranslationCatalog.pluralr,)
�__name__�
__module__�__qualname__�__doc__r+r0r3r8r:r=r@rCr'rrrrrCs


rc@sreZdZdZdZddd�Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�Zdd�ZdS)�DjangoTranslationa]
    Set up the GNUTranslations context with regard to output charset.

    This translation object will be constructed out of multiple GNUTranslations
    objects by merging their catalogs. It will construct an object for the
    requested language and add a fallback to the default language, if it's
    different from the requested language.
    �djangoNcCs�tj�|�|dur
||_||_t|�|_t|�|_d|_	dd�|_
|jdkr7|dur3t�dt
�d}|��|rI|D]}|�|�}|�|�q;n|��|��|jtjkrh|jdkrh|j	durhtdtj��|�|�|j	durxt�|_	dSdS)z8Create a GNUTranslations() using many locale directoriesNcSrrrr rrrr"�r#z,DjangoTranslation.__init__.<locals>.<lambda>rOz.localedirs is ignored when domain is 'django'.z3No translation files found for default language %s.)�gettext_module�GNUTranslationsr+�domain�_DjangoTranslation__languager
�_DjangoTranslation__to_languager�_DjangoTranslation__localer$r'�warnings�warn�RuntimeWarning�_init_translation_catalog�_new_gnu_trans�merge� _add_installed_apps_translations�_add_local_translationsrr�OSError�
_add_fallbackr)r)�languagerR�
localedirs�	localedir�translationrrrr+�s4




� 

�zDjangoTranslation.__init__cCs
d|jS)Nz<DjangoTranslation lang:%s>�rS�r)rrr�__repr__�s
zDjangoTranslation.__repr__TcCstj|j||jg|d�S)z�
        Return a mergeable gettext.GNUTranslations instance.

        A convenience wrapper. By default gettext uses 'fallback=False'.
        Using param `use_null_fallback` to avoid confusion with any other
        references to 'fallback'.
        )rRrb�	languages�fallback)rPrcrRrU)r)rb�use_null_fallbackrrrrZ�s�z DjangoTranslation._new_gnu_transcCs<tjtjj}tj�tj�|�d�}|�	|�}|�
|�dS)z7Create a base catalog using global django translations.�localeN)�sys�modulesrrK�__file__�os�path�join�dirnamerZr[)r)�settingsfilerbrcrrrrY�s
z+DjangoTranslation._init_translation_catalogcCsjz
ttt����}Wntytd��w|D]}tj�|jd�}tj�|�r2|�	|�}|�
|�qdS)z+Merge translations from each installed app.z�The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.rjN)�reversed�listr�get_app_configsrrnrorp�existsrZr[)r)�app_configs�
app_configrbrcrrrr\�s��

��z2DjangoTranslation._add_installed_apps_translationscCs(ttj�D]}|�|�}|�|�qdS)z+Merge translations defined in LOCALE_PATHS.N)rsr�LOCALE_PATHSrZr[)r)rbrcrrrr]�s
�z)DjangoTranslation._add_local_translationscCsR|jtjks|j�d�rdS|jdkrttj�}n	ttj|j|d�}|�|�dS)z=Set the GNUTranslations() fallback with the default language.�enNrO)rRra)rSrr�
startswithrRrcrN�add_fallback)r)ra�default_translationrrrr_�s

�zDjangoTranslation._add_fallbackcCs`t|dd�sdS|jdur|j|_|j��|_t|�|_n|j�|�|jr.|�|j�dSdS)z,Merge another translation into this catalog.r$N)	�getattrr$r'�_infor%rr@�	_fallbackr|)r)�otherrrrr[�s
�zDjangoTranslation.mergecC�|jS)z Return the translation language.rdrerrrr`��zDjangoTranslation.languagecCr�)z%Return the translation language name.)rTrerrrr
�r�zDjangoTranslation.to_languagecCsZz
|j�||�}W|Sty,|jr|j�|||�YS|dkr'|}Y|S|}Y|Swr)r$r'r-r��ngettext)r)�msgid1�msgid2r!rIrrrr��s���zDjangoTranslation.ngettext)NN)Tr,)rJrKrLrMrRr+rfrZrYr\r]r_r[r`r
r�rrrrrN|s
%

rNcCs|tvr
t|�t|<t|S)zE
    Return a translation object in the default 'django' domain.
    )�
_translationsrN�r`rrrrcsrccCs|sdSt|�t_dS)z�
    Fetch the translation object for a given language and install it as the
    current translation object for the current thread.
    N)rc�_activer2r�rrr�activatesr�cCsttd�r	t`dSdS)zz
    Uninstall the active translation object so that further _() calls resolve
    to the default translation object.
    r2N)�hasattrr�r2rrrr�
deactivate s
�r�cCst��t_dd�tj_dS)z�
    Make the active translation object a NullTranslations() instance. This is
    useful when we want delayed translations to appear as the original string
    for some reason.
    cWsdSr,r)�argsrrrr"0sz deactivate_all.<locals>.<lambda>N)rP�NullTranslationsr�r2r
rrrr�deactivate_all)s
r�cCs<ttdd�}|durz|��WStyYtjSwtjS)z'Return the currently selected language.r2N)r~r�r
�AttributeErrorrr��trrr�get_language3s
�r�cCs,t�}|dur	dSt��d�d}|tjvS)zw
    Return selected language's BiDi layout.

    * False = left-to-right layout
    * True = right-to-left layout
    NF�-r)r��splitr�LANGUAGES_BIDI)�lang�	base_langrrr�get_language_bidi?s

r�cCs.ttdd�}|dur|Stdurttj�atS)z�
    Return the current active catalog for further processing.
    This can be used if you need to modify the catalog or want to access the
    whole message catalog instead of just translating one string.
    r2N�r~r��_defaultrcrrr�rrr�catalogNs
r�cCs`|�dd��dd�}|rtpttj�attdt�}|�|�}nt|�d�}t	|t
�r.t|�S|S)z�
    Translate the 'message' string. It uses the current thread to find the
    translation object to use. If no current translation is activated, the
    message will be run through the default translation object.
    z
�
�
r2�)�replacer�rcrrr~r��gettext�type�
isinstancer
r)�message�eol_message�translation_objectrFrrrr�^s
r�cCs<d|t|f}t|�}t|vr|}|St|t�rt|�}|S�Nz%s%s%s)�CONTEXT_SEPARATORr�r�r
r)�contextr��
msg_with_ctxtrFrrr�pgettextxs
�r�cCs|S)z�
    Mark strings for translation but don't translate them now. This can be
    used to store strings in global variables that should stay in the base
    language (because they might be used externally) and will be translated
    later.
    r)r�rrr�gettext_noop�sr�cCsJttdd�}|durt||�|||�Stdurttj�att|�|||�S)Nr2r�)�singularr'�number�translation_functionr�rrr�
do_ntranslate�s
r�cCst|||d�S)zg
    Return a string of the translation of either the singular or plural,
    based on the number.
    r�)r�)r�r'r�rrrr��sr�cCs>d|t|fd|t|f|f}t|�}t|vrt|||�}|Sr�)r�r�)r�r�r'r��msgs_with_ctxtrFrrr�	npgettext�s�r�cCshtj�tj�tjtjj�d�}g}t	�
�D]}tj�|jd�}tj�|�r+|�|�q|gtj
�|�S)zB
    Return a list of paths to user-provides languages files.
    rj)rnrorprqrkrlrrKrmrrurv�appendry)�
globalpath�	app_pathsrx�locale_pathrrr�all_locale_paths�s�
�r�i�)�maxsizecs.�dus	t���sdSt�fdd�t�D��S)a�
    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 request. See also
    <https://www.djangoproject.com/weblog/2007/oct/26/security-fix/>.
    NFc3s(�|]}t�d|t��g�duVqdS)rON)rP�findr)r4ro��	lang_coderrr6�s
��
�z%check_for_language.<locals>.<genexpr>)�language_code_re�searchr7r�r�rr�rr�s
�rcCs
ttj�S)zN
    Cache of settings.LANGUAGES in a dictionary for easy lookups by key.
    )�dictrrrrrrr�s
rFcCs�|rjt|�tkr |s|�ddt�}dkr|d|�}ntd��|g}z|�t|d�Wn	ty7Ynw|�d�d}|�|�t	�}|D]}||vrWt
|�rW|SqI|sj|D]
}|�|d�ri|Sq\t|��)a}
    Return the language code that's listed in supported languages, possibly
    selecting a more generic variant. Raise LookupError if nothing is found.

    If `strict` is False (the default), look for a country-specific variant
    when neither the language code nor its generic variant is found.

    The language code is truncated to a maximum length to avoid potential
    denial of service attacks.

    lru_cache should have a maxsize to prevent from memory exhaustion attacks,
    as the provided language codes are taken from the HTTP request. See also
    <https://www.djangoproject.com/weblog/2007/oct/26/security-fix/>.
    r�rNz/'lang_code' exceeds the maximum accepted lengthrh)
�len�LANGUAGE_CODE_MAX_LENGTH�rfind�
ValueError�extendrr-r�r�rrr{�LookupError)r��strict�index�possible_lang_codes�generic_lang_code�supported_lang_codes�code�supported_coderrrr�s4��
��rcCs>t�|�}|s	dS|d}zt||d�WStyYdSw)z�
    Return the language code if there's a valid language code found in `path`.

    If `strict` is False (the default), look for a country-specific variant
    when neither the language code nor its generic variant is found.
    Nr)r�)�language_code_prefix_re�matchrr�)ror��regex_matchr�rrr�get_language_from_paths
�r�c	Cs�|r
t|j�}|dur
|S|j�tj�}|dur#|t�vr#t|�r#|Szt|�WSt	y1Ynw|j
�dd�}t|�D] \}}|dkrGnt�
|�sMq=zt|�WSt	y]Yq=wzttj�WSt	yptjYSw)a�
    Analyze the request to find what language the user wants the system to
    show. Only languages listed in settings.LANGUAGES are taken into account.
    If the user requests a sublanguage where we have a main language, we send
    out the main language.

    If check_path is True, the URL path prefix will be checked for a language
    code, otherwise this is skipped for backwards compatibility.
    N�HTTP_ACCEPT_LANGUAGEr��*)r��	path_info�COOKIESrCr�LANGUAGE_COOKIE_NAMErrrr��META�parse_accept_lang_headerr�r�r)�request�
check_pathr��accept�accept_lang�unusedrrr�get_language_from_requests8


�
�
�r�cCs�g}t�|���}|drdStdt|�dd�D]"}|||d�\}}}|r+dS|r2t|�}nd}|�||f�q|jdd�d	d
�t|�S)z�
    Parse the lang_string, which is the body of an HTTP Accept-Language
    header, and return a tuple of (lang, q-value), ordered by 'q' values.

    Return an empty tuple if there are any format errors in lang_string.
    ���rrr�g�?cSs|dSrr)�krrrr"Wsz+_parse_accept_lang_header.<locals>.<lambda>T)r.�reverse)	�accept_language_rer��lower�ranger��floatr��sort�tuple)�lang_stringrF�pieces�i�firstr��priorityrrr�_parse_accept_lang_headerBs
r�cCs>t|�tkr
t|�S|�ddt�}|dkrt|d|��SdS)a�
    Parse the value of the Accept-Language header up to a maximum length.

    The value of the header is truncated to a maximum length to avoid potential
    denial of service and memory exhaustion attacks. Excessive memory could be
    used if the raw value is very large as it would be cached due to the use of
    `functools.lru_cache()` to avoid repetitive parsing of common header values.
    �,rNr)r�r�r�r�)r�r�rrrr�[s
r�)F)ArM�	functoolsr�rPrn�rerkrV�
asgiref.localr�django.appsr�django.confr�django.conf.localer�django.core.exceptionsr�django.core.signalsr�django.dispatchr�django.utils.regex_helperr	�django.utils.safestringr
rr�r
rr�r�r�r�r��VERBOSEr��
IGNORECASEr�r�rrrQrNrcr�r�r�r�r�r�r�r�r�r�r�r��	lru_cacherrrr�r�r�r�rrrr�<module>sx��
9

	






0

+


https://t.me/RX1948 - 2025