BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib64/python3.6/site-packages/tornado/__pycache__/locale.cpython-36.opt-1.pyc
3

	��fQ�@sdZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZmZmZmZdaiaetg�adad	Zed
d�dd
�Zedd�dd�Zdeedd�dd�Zeedd�dd�Zeed�dd�ZGdd
�d
e�ZGdd�de�Z Gdd�de�Z!dS) a�Translation methods for generating localized strings.

To load a locale and generate a translated string::

    user_locale = tornado.locale.get("es_LA")
    print(user_locale.translate("Sign out"))

`tornado.locale.get()` returns the closest matching locale, not necessarily the
specific locale you requested. You can support pluralization with
additional arguments to `~Locale.translate()`, e.g.::

    people = [...]
    message = user_locale.translate(
        "%(list)s is online", "%(list)s are online", len(people))
    print(message % {"list": user_locale.list(people)})

The first string is chosen if ``len(people) == 1``, otherwise the second
string is chosen.

Applications should call one of `load_translations` (which uses a simple
CSV format) or `load_gettext_translations` (which uses the ``.mo`` format
supported by `gettext` and related tools).  If neither method is called,
the `Locale.translate` method will simply return the original string.
�N)�escape)�gen_log)�LOCALE_NAMES)�Iterable�Any�Union�Dict�en_USF��Locale)�locale_codes�returncGs
tj|�S)a�Returns the closest match for the given locale codes.

    We iterate over all given locale codes in order. If we have a tight
    or a loose match for the code (e.g., "en" for "en_US"), we return
    the locale. Otherwise we move to the next code in the list.

    By default we return ``en_US`` if no translations are found for any of
    the specified locales. You can change the default locale with
    `set_default_locale()`.
    )r�get_closest)r�r�/usr/lib64/python3.6/locale.py�get?sr)�coder
cCs|atttj��tg�adS)a7Sets the default locale.

    The default locale is assumed to be the language used for all strings
    in the system. The translations loaded from disk are mappings from
    the default locale to the destination locale. Consequently, you don't
    need to create a translation file for the default locale.
    N)�_default_locale�	frozenset�list�
_translations�keys�_supported_locales)rrrr�set_default_localeMs
r)�	directory�encodingr
cCs�ia�xntj|�D�]^}|jd�s$q|jd�\}}tjd|�sXtjd|tj	j
||��qtj	j
||�}|dkr�t|d��}|jt
tj��}WdQRX|tjtjfkr�d}nd}t||d	���}it|<x�ttj|��D]�\}	}
|
s�t
|
�d
kr�q�dd�|
D�}
|
dd
�\}}t
|
�d
k�r,|
d
�p(d
}
nd
}
|
dk�rPtjd|
||	d�q�|t|j|
i�|<q�WWdQRXqWtttj��tg�atjdtt��dS)uwLoads translations from CSV files in a directory.

    Translations are strings with optional Python-style named placeholders
    (e.g., ``My name is %(name)s``) and their associated translations.

    The directory should have translation files of the form ``LOCALE.csv``,
    e.g. ``es_GT.csv``. The CSV files should have two or three columns: string,
    translation, and an optional plural indicator. Plural indicators should
    be one of "plural" or "singular". A given string can have both singular
    and plural forms. For example ``%(name)s liked this`` may have a
    different verb conjugation depending on whether %(name)s is one
    name or a list of names. There should be two rows in the CSV file for
    that string, one with plural indicator "singular", and one "plural".
    For strings with no verbs that would change on translation, simply
    use "unknown" or the empty string (or don't include the column at all).

    The file is read using the `csv` module in the default "excel" dialect.
    In this format there should not be spaces after the commas.

    If no ``encoding`` parameter is given, the encoding will be
    detected automatically (among UTF-8 and UTF-16) if the file
    contains a byte-order marker (BOM), defaulting to UTF-8 if no BOM
    is present.

    Example translation ``es_LA.csv``::

        "I love you","Te amo"
        "%(name)s liked this","A %(name)s les gustó esto","plural"
        "%(name)s liked this","A %(name)s le gustó esto","singular"

    .. versionchanged:: 4.3
       Added ``encoding`` parameter. Added support for BOM-based encoding
       detection, UTF-16, and UTF-8-with-BOM.
    z.csv�.z[a-z]+(_[A-Z]+)?$z!Unrecognized locale %r (path: %s)N�rbzutf-16z	utf-8-sig)r�cSsg|]}tj|�j��qSr)rZ
to_unicode�strip)�.0�crrr�
<listcomp>�sz%load_translations.<locals>.<listcomp>�unknown�plural�singularz.Unrecognized plural indicator %r in %s line %d�zSupported locales: %s)r$r%r#)r�os�listdir�endswith�split�re�matchr�error�path�join�open�read�len�codecs�BOM_UTF16_LE�BOM_UTF16_BE�	enumerate�csv�reader�
setdefaultrrrrr�debug�sorted)rrr.�locale�	extension�	full_pathZbf�data�f�i�rowZenglish�translationr$rrr�load_translations[sL%


&rD)r�domainr
cCs�ddl}iax�tj|�D]�}|jd�r(qtjjtjj||��r@qy6tjtjj||d|d��|j	|||gd�t|<Wqt
k
r�}ztjd|t
|��wWYdd}~XqXqWtttj��tg�adatjd	tt��dS)
aLoads translations from `gettext`'s locale tree

    Locale tree is similar to system's ``/usr/share/locale``, like::

        {directory}/{lang}/LC_MESSAGES/{domain}.mo

    Three steps are required to have your app translated:

    1. Generate POT translation file::

        xgettext --language=Python --keyword=_:1,2 -d mydomain file1.py file2.html etc

    2. Merge against existing POT file::

        msgmerge old.po mydomain.po > new.po

    3. Compile::

        msgfmt mydomain.po -o {directory}/pt_BR/LC_MESSAGES/mydomain.mo
    rNr�LC_MESSAGESz.mo)Z	languagesz$Cannot load translation for '%s': %sTzSupported locales: %s)�gettextrr'r(�
startswithr.�isfiler/�statrC�	Exceptionrr-�strrrrrr�_use_gettextr:r;)rrErGZlang�errr�load_gettext_translations�s"
rO)r
cCstS)z1Returns a list of all the supported locale codes.)rrrrr�get_supported_locales�srPc@s�eZdZdZiZeedd�dd��Zeedd�dd��Zedd�d	d
�Z	d eee
ed�dd
�Zd!eeee
ed�dd�Zd"e
e
eejfe
eeeed�dd�Zd#eje
eed�dd�Zeed�dd�Ze
ed�dd�ZdS)$rz�Object representing a locale.

    After calling one of `load_translations` or `load_gettext_translations`,
    call `get` or `get_closest` to get a Locale object.
    )rr
cGs�x�|D]�}|sq|jdd�}|jd�}t|�dkr6qn(t|�dkr^|dj�d|dj�}|tkrp|j|�S|dj�tkr|j|dj��SqW|jt�S)z4Returns the closest match for the given locale code.�-�_rrr&)�replacer*r2�lower�upperrrr)�clsrr�partsrrrr�s


zLocale.get_closest)rr
cCsX||jkrNtj|d�}|dkr*t|i�}ntr:t||�}n
t||�}||j|<|j|S)znReturns the Locale for the given locale code.

        If it is not supported, we raise an exception.
        N)�_cacherr�	CSVLocalerM�
GettextLocale)rVr�translationsr<rrrr�s


z
Locale.getNc
Cs�||_tj|i�jdd�|_d|_x dD]}|jj|�r(d|_Pq(W|j}|d�|d	�|d
�|d�|d�|d
�|d�|d�|d�|d�|d�|d�g|_|d�|d�|d�|d�|d�|d�|d�g|_dS)N�nameZUnknownF�fa�ar�heTZJanuaryZFebruaryZMarchZAprilZMayZJuneZJulyZAugustZ	SeptemberZOctoberZNovemberZDecemberZMondayZTuesdayZ	WednesdayZThursdayZFridayZSaturdayZSunday)r]r^r_)	rrrr\ZrtlrH�	translate�_months�	_weekdays)�selfr�prefixrRrrr�__init__s6
zLocale.__init__)�message�plural_message�countr
cCs
t��dS)a&Returns the translation for the given message for this locale.

        If ``plural_message`` is given, you must also provide
        ``count``. We return ``plural_message`` when ``count != 1``,
        and we return the singular form for the given message when
        ``count == 1``.
        N)�NotImplementedError)rcrfrgrhrrrr`4s
zLocale.translate)�contextrfrgrhr
cCs
t��dS)N)ri)rcrjrfrgrhrrr�pgettext@szLocale.pgettextrTF)�date�
gmt_offset�relative�shorter�full_formatr
cCslt|ttf�rtjj|�}tjj�}||krH|rD||jdkrD|}nd}|tj|d�}|tj|d�}|tjdd�}	||}
|
j}|
j}|j	}
d}|�s�|o�|dk�r|dkr�|
d	d
|�d|iS|d+kr�t
|d�}|
d
d|�d|iSt
|d,�}|
dd|�d|iS|dk�r"|
d�}nx|dk�rX|j|	jk�rX|�rX|�rN|
d�n|
d�}nB|dk�rz|�rp|
d�n|
d�}n |dk�r�|�r�|
d�n|
d�}|dk�r�|�r�|
d�n|
d�}|jd-k}|�r�d"|j
|jf}nZ|jd!k�rd#d.|j
d&k|j
d&�pd&|jf}n&d'|j
d&�p d&|jd/|j
d&kf}||j|jd|j|j�t|j�t|j�|d*�S)0a�Formats the given date (which should be GMT).

        By default, we return a relative time (e.g., "2 minutes ago"). You
        can return an absolute date string with ``relative=False``.

        You can force a full format date ("July 10, 1980") with
        ``full_format=True``.

        This method is primarily intended for dates in the past.
        For dates in the future, we fall back to full format.
        �<T)�minutes�)�hoursNr�2z1 second agoz%(seconds)d seconds ago�secondsgN@z1 minute agoz%(minutes)d minutes agorrz
1 hour agoz%(hours)d hours agortz%(time)sr&Z	yesterdayzyesterday at %(time)s�z%(weekday)sz%(weekday)s at %(time)siNz%(month_name)s %(day)sz"%(month_name)s %(day)s at %(time)sz %(month_name)s %(day)s, %(year)sz,%(month_name)s %(day)s, %(year)s at %(time)s�enr	�zh_CNz%d:%02dz	%s%d:%02d�上午�下午�z
%d:%02d %s�am�pm)�
month_name�weekday�day�yearZtimei�g �@)rxr	ry)rzr{)r}r~)�
isinstance�int�float�datetimeZutcfromtimestampZutcnowrv�	timedelta�daysr`�roundr�rZhourZminutera�monthrbr�rLr�)rcrlrmrnrorpZnow�
local_dateZ	local_nowZlocal_yesterday�
differencervr�rR�formatrrrtZtfhour_clockZstr_timerrr�format_dateEsp










zLocale.format_date)rlrm�dowr
cCsr|tj|d�}|j}|rJ|d�|j|jd|j|j�t|j�d�S|d�|j|jdt|j�d�SdS)z�Formats the given date as a day of week.

        Example: "Monday, January 22". You can remove the day of week with
        ``dow=False``.
        )rrz#%(weekday)s, %(month_name)s %(day)sr&)rr�r�z%(month_name)s %(day)s)rr�N)	r�r�r`rar�rbr�rLr�)rcrlrmr�r�rRrrr�
format_day�szLocale.format_day)rWr
cCsj|j}t|�dkrdSt|�dkr*|dS|jjd�r:dnd}|d�|j|dd
��|t|�dd	�S)z�Returns a comma-separated list for the given list of parts.

        The format is, e.g., "A, B and C", "A and B" or just "A" for lists
        of size 1.
        r�r&r]u و z, z%(commas)s and %(last)sN)ZcommasZlast���)r`r2rrHr/)rcrWrRZcommarrrr�szLocale.list)�valuer
cCsT|jdkrt|�St|�}g}x&|rD|j|dd��|dd�}q Wdjt|��S)	z7Returns a comma-separated number for the given integer.rxr	�N�,)rxr	���r�)rrL�appendr/�reversed)rcr��srWrrr�friendly_number�s
zLocale.friendly_number)NN)NN)rTFF)rT)�__name__�
__module__�__qualname__�__doc__rX�classmethodrLrrrer�r`rkrr�r��boolr�r�rrr�rrrrr�s($
^
csheZdZdZeeeeeeffdd��fdd�Zdeeeed�dd�Zd
eeeeed	�d
d�Z	�Z
S)rYz=Locale implementation using tornado's CSV translation format.N)rr[r
cs||_tt|�j|�dS)N)r[�superrYre)rcrr[)�	__class__rrre�szCSVLocale.__init__)rfrgrhr
cCsN|dk	r4|dkr$|}|jjdi�}qB|jjdi�}n|jjdi�}|j||�S)Nr&r$r%r#)r[r)rcrfrgrhZmessage_dictrrrr`�szCSVLocale.translate)rjrfrgrhr
cCs|jrtjd�|j|||�S)Nz&pgettext is not supported by CSVLocale)r[rZwarningr`)rcrjrfrgrhrrrrk�s
zCSVLocale.pgettext)NN)NN)r�r�r�r�rLrrer�r`rk�
__classcell__rr)r�rrY�s&
rYcsZeZdZdZeejdd��fdd�Zdeeeed�dd�Z	d
eeeeed	�d
d�Z
�ZS)rZz1Locale implementation using the `gettext` module.N)rr[r
cs$|j|_|j|_tt|�j|�dS)N)�ngettextrGr�rZre)rcrr[)r�rrre�szGettextLocale.__init__)rfrgrhr
cCs$|dk	r|j|||�S|j|�SdS)N)r�rG)rcrfrgrhrrrr`szGettextLocale.translate)rjrfrgrhr
cCsv|dk	rJd|t|fd|t|f|f}|j|�}t|krF|j|||�}|Sd|t|f}|j|�}t|krn|}|SdS)a?Allows to set context for translation, accepts plural forms.

        Usage example::

            pgettext("law", "right")
            pgettext("good", "right")

        Plural message example::

            pgettext("organization", "club", "clubs", len(clubs))
            pgettext("stick", "club", "clubs", len(clubs))

        To generate POT file with context, add following options to step 1
        of `load_gettext_translations` sequence::

            xgettext [basic options] --keyword=pgettext:1c,2 --keyword=pgettext:1c,2,3

        .. versionadded:: 4.2
        Nz%s%s%s)�CONTEXT_SEPARATORr�rG)rcrjrfrgrhZmsgs_with_ctxt�resultZ
msg_with_ctxtrrrrks

zGettextLocale.pgettext)NN)NN)r�r�r�r�rLrGZNullTranslationsrer�r`rkr�rr)r�rrZ�s
rZ)N)"r�r3r7r�rGr'r+ZtornadorZtornado.logrZtornado._locale_datarZtypingrrrrrrrrrMr�rLrrrDrOrP�objectrrYrZrrrr�<module>(s0
W-y