HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/tornado/__pycache__/locale.cpython-310.pyc
o

we�R�@s2dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZdaiaetg�adad	Zd
eddfd
d�Zdeddfdd�Zd dedeeddfdd�Zdededdfdd�Zdeefdd�ZGdd�de �Z!Gdd�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�Optional�en_USF��locale_codes�return�LocalecGs
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�G/home/arjun/projects/env/lib/python3.10/site-packages/tornado/locale.py�get>s
r�codecCs|attt���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_localeLs
r�	directory�encodingc
Cs�iat�|�D]�}|�d�sq|�d�\}}t�d|�s)t�d|tj	�
||��qtj	�
||�}|dur^t|d��}|�t
tj��}Wd�n1sLwY|tjtjfvr\d}nd}t||d	��X}it|<tt�|��D]D\}	}
|
r|t
|
�d
kr}qpdd�|
D�}
|
dd
�\}}t
|
�d
kr�|
d
p�d
}
nd
}
|
dvr�t�d|
||	d�qp|t|�|
i�|<qpWd�n1s�wYqttt���tg�at�dtt��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|]	}t�|����qSr)r�
to_unicode�strip)�.0�crrr�
<listcomp>�sz%load_translations.<locals>.<listcomp>�unknown)�plural�singularr%z.Unrecognized plural indicator %r in %s line %d��Supported locales: %s)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)rrr1�locale�	extension�	full_path�bf�data�f�i�row�english�translationr&rrr�load_translationsZsX%
������rI�domaincCs�iat�tj�|dd|d��D]8}tj�tj�tj�|���}z
tj|||gd�t|<Wqt	yH}zt
�d|t|��WYd}~qd}~wwt
tt���tg�adat
�dtt��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
    �*�LC_MESSAGESz.mo)�	languagesz$Cannot load translation for '%s': %sNTr))r�globr*r1r2�basename�dirname�gettextrH�	Exceptionrr0�strrrrrr�_use_gettextr=r>)rrJ�filename�lang�errr�load_gettext_translations�s"����rXcCstS)z1Returns a list of all the supported locale codes.)rrrrr�get_supported_locales�srYc
@s"eZdZdZiZededdfdd��Zededdfdd��Zdedd	fd
d�Z					d'ded
e
ede
edefdd�Z				d'deded
e
ede
edef
dd�Z
				d(deeeejfdededededefdd�Z	d)dejdededefdd �Zd!edefd"d#�Zd$edefd%d&�Zd	S)*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�|D]I}|sq|�dd�}|�d�}t|�dkrqt|�dkr-|d��d|d��}|tvr8|�|�S|d��tvrK|�|d���Sq|�t�S)z4Returns the closest match for the given locale code.�-�_rrr()�replacer-r5�lower�upperrrr)�clsrr�partsrrrr�s
�
zLocale.get_closestrcCsd||jvr-|tvsJ�t�|d�}|durt|i�}n
tr#t||�}nt||�}||j|<|j|S)znReturns the Locale for the given locale code.

        If it is not supported, we raise an exception.
        N)�_cacherrr�	CSVLocalerT�
GettextLocale)r_r�translationsr?rrrr�s



z
Locale.getNc
Cs�||_t�|i��dd�|_d|_dD]
}|j�|�r d|_nq|j}|d�|d�|d�|d	�|d
�|d�|d�|d
�|d�|d�|d�|d�g|_|d�|d�|d�|d�|d�|d�|d�g|_dS)N�name�UnknownF)�fa�ar�heT�January�February�March�April�May�June�July�August�	September�October�November�December�Monday�Tuesday�	Wednesday�Thursday�Friday�Saturday�Sunday)	rrrre�rtl�
startswith�	translate�_months�	_weekdays)�selfr�prefixr[rrr�__init__
s<��
�zLocale.__init__�message�plural_message�countcC�t��)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``.
        ��NotImplementedError�r�r�r�r�rrrr0s
zLocale.translate�contextcCr��Nr��r�r�r�r�r�rrr�pgettext?szLocale.pgettextrTF�date�
gmt_offset�relative�shorter�full_formatcCsvt|ttf�rtj�|tjj�}|jdur|jtjjd�}tj�	tjj�}||kr7|r5||j
dkr5|}nd}|tj|d�}|tj|d�}|tjdd�}	||}
|
j
}|
j}|j
}
d}|s�|r�|dkr�|d	krt|
d
d|�d|iS|d
kr�t|d�}|
dd|�d|iSt|d�}|
dd|�d|iS|dkr�|
d�}n4|dkr�|j|	jkr�|r�|r�|
d�n|
d�}n|dkr�|r�|
d�n|
d�}n|dkr�|r�|
d�n|
d�}|dur�|r�|
d �n|
d!�}|jd"v}|r�d#|j|jf}n-|jd$k�r
d%d&|jd'k|jd'�pd'|jf}nd(|jd'�pd'|jd)|jd'kf}||j|jd|j|��t|j�t|j�|d*�S)+a)Formats the given date.

        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.

        .. versionchanged:: 6.4
           Aware `datetime.datetime` objects are now supported (naive
           datetimes are still assumed to be UTC).
        N)�tzinfo�<T��minutes�)�hoursr�2z1 second agoz%(seconds)d seconds ago�secondsi�gN@z1 minute agoz%(minutes)d minutes agor�g �@z
1 hour agoz%(hours)d hours agor�z%(time)sr(�	yesterdayzyesterday at %(time)s�z%(weekday)sz%(weekday)s at %(time)siN�%(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:%02dr�z	%s%d:%02d)u上午u下午�z
%d:%02d %s)�am�pm)�
month_name�weekday�day�year�time)�
isinstance�int�float�datetime�
fromtimestamp�timezone�utcr�r\�nowr��	timedelta�daysr�roundr�r�hour�minuter��monthr�r�rSr�)r�r�r�r�r�r�r��
local_date�	local_now�local_yesterday�
differencer�r�r[�formatr�r��tfhour_clock�str_timerrr�format_dateHs�

�
�

��
��
���zLocale.format_date�dowcCsn|tj|d�}|j}|r%|d�|j|jd|j|��t|j�d�S|d�|j|jdt|j�d�S)z�Formats the given date as a day of week.

        Example: "Monday, January 22". You can remove the day of week with
        ``dow=False``.
        r�z#%(weekday)s, %(month_name)s %(day)sr()r�r�r�r�)r�r�)	r�r�rr�r�r�r�rSr�)r�r�r�r�r�r[rrr�
format_day�s��zLocale.format_dayr`cCsj|j}t|�dkrdSt|�dkr|dS|j�d�rdnd}|d�|�|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(rgu و z, z%(commas)s and %(last)sN���)�commas�last)rr5rr~r2)r�r`r[�commarrrr�s�zLocale.list�valuecCsR|jdvr	t|�St|�}g}|r"|�|dd��|dd�}|sd�t|��S)z7Returns a comma-separated number for the given integer.)r�r
���N�,)rrS�appendr2�reversed)r�r��sr`rrr�friendly_number�s
�zLocale.friendly_number�NN)rTFF)rT)�__name__�
__module__�__qualname__�__doc__ra�classmethodrSrrr�r	r�rr�rr�r��boolr�r�rrr�rrrrr�sz&����
������
�������
�k����
�cs�eZdZdZdedeeeeeffddf�fdd�Z		dded	eed
eedefdd�Z			dd
eded	eed
eedef
dd�Z
�ZS)rbz=Locale implementation using tornado's CSV translation format.rrdr
Ncs||_t��|�dSr�)rd�superr��r�rrd��	__class__rrr��szCSVLocale.__init__r�r�r�cCsZ|dur |dus
J�|dkr|}|j�di�}n|j�di�}n|j�di�}|�||�S)Nr(r&r'r%)rdr)r�r�r�r��message_dictrrrr�szCSVLocale.translater�cCs|jrt�d�|�|||�S)Nz&pgettext is not supported by CSVLocale)rdr�warningrr�rrrr��s
zCSVLocale.pgettextr�)r�r�r�r�rSrr�r	r�rr��
__classcell__rrr�rrb�s6*����
�������rbcs�eZdZdZdedejddf�fdd�Z		dded	eed
ee	defdd�Z
		dd
eded	eed
ee	def
dd�Z�ZS)rcz1Locale implementation using the `gettext` module.rrdr
Ncs |j|_|j|_t��|�dSr�)�ngettextrQr�r�r�r�rrr�szGettextLocale.__init__r�r�r�cCs,|dur|dus
J�|�|||�S|�|�Sr�)r�rQr�rrrrs
zGettextLocale.translater�cCs~|dur+|dus
J�d|t|fd|t|f|f}|j|�}t|vr)|�|||�}|Sd|t|f}|�|�}t|vr=|}|S)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�rQ)r�r�r�r�r��msgs_with_ctxt�result�
msg_with_ctxtrrrr�s�

zGettextLocale.pgettextr�)
r�r�r�r�rSrQ�NullTranslationsr�r	r�rr�r�rrr�rrc	s6
����
�������rcr�)$r�r6r:r�rQrNr*r.�tornador�tornado.logr�tornado._locale_datar�typingrrrrr	rrrrrTr�rSrrrIrXrY�objectrrbrcrrrr�<module>s6
W*$