
    MhR                     t   d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZmZmZ dai a et(          g          adad	Zd
eddfdZdeddfdZddedee         ddfdZdededdfdZdee         fdZ G d d          Z  G d de           Z! G d de           Z"dS )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Localec                      t          j        |  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   s    N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/locale.pygetr   >   s     |,,    codec                     | a t          t          t                                                    t           gz             adS )a7  Sets 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)r   s    r   set_default_localer   L   s9     O"4(:(:(<(<#=#=@Q#QRRr   	directoryencodingc           
         i a t          j        |           D ]}|                    d          s|                    d          \  }}t          j        d|          s5t          j        d|t          j	        
                    | |                     {t          j	        
                    | |          }|st          |d          5 }|                    t          t          j                            }ddd           n# 1 swxY w Y   |t          j        t          j        fv rd}nd}t          ||	          5 }i t           |<   t#          t%          j        |                    D ]\  }	}
|
rt          |
          d
k     rd |
D             }
|
dd
         \  }}t          |
          d
k    r|
d
         pd}nd}|dvrt          j        d|||	dz              s|t           |                             |i           |<   	 ddd           n# 1 swxY w Y   t+          t-          t                                                     t0          gz             at          j        dt7          t2                               dS )uw  Loads 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rbzutf-16z	utf-8-sig)r      c                 Z    g | ](}t          j        |                                          )S  )r   
to_unicodestrip).0cs     r   
<listcomp>z%load_translations.<locals>.<listcomp>   s/    AAAv(++1133AAAr   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
setdefaultr   r   r   r   r   debugsorted)r   r   r7   locale	extension	full_pathbfdatafirowenglishtranslationr,   s                 r   load_translationsrO   Z   s   J M
9%% ,T ,T}}V$$ 	 JJsOO	x+V44 	M3Y--  
 GLLD11	i&& 9"wws6#677889 9 9 9 9 9 9 9 9 9 9 9 9 9 9+V-@AAA#
 ' )h/// 	T1$&M&!#CJqMM22 T T3 c#hhllAASAAA'*2A2w$s88a<< V0yFF&F!BBBMHA	   HSf%00<<WEE#T	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T( #4(:(:(<(<#=#=@Q#QRRM)62D+E+EFFFFFs%   -C==D	D	8CH		H	H	domainc           	         i a t          j        t          j                            | dd|dz                       D ]}t          j                            t          j                            t          j                            |                              }	 t          j        || |g          t           |<   }# t          $ r-}t          j        d|t          |                     Y d}~d}~ww xY wt          t          t                                                     t           gz             adat          j        dt)          t"                               dS )	a  Loads 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   globr0   r7   r8   basenamedirnamegettextrN   	Exceptionr   r6   strr   r   r   r   r   _use_gettextrC   rD   )r   rP   filenamelanges        r   load_gettext_translationsr_      s9   0 MI
Y]FUNCC  
 
 w0I0I J JKK	")"5	dV# # #M$  	 	 	M@$AOOOHHHH	 #4(:(:(<(<#=#=@Q#QRRLM)62D+E+EFFFFFs    B77
C.#C))C.c                      t           S )z1Returns a list of all the supported locale codes.)r   r%   r   r   get_supported_localesra      s    r   c                   b   e Zd ZdZi Zededd fd            Zededd fd            ZdeddfdZ		 	 dd	ed
e
e         de
e         defdZ	 	 dded	ed
e
e         de
e         def
dZ	 	 	 	 ddeeeej        f         dededededefdZ	 d dej        dededefdZdedefdZdedefdZdS )!r   zObject 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   c                 >   |D ] }|s|                     dd          }|                    d          }t          |          dk    rEt          |          dk    r8|d                                         dz   |d                                         z   }|t
          v r|                     |          c S |d                                         t
          v r/|                     |d                                                   c S |                     t                    S )z4Returns the closest match for the given locale code.-_r#   r   r.   )replacer3   r;   lowerupperr   r   r   )clsr   r   partss       r   r   zLocale.get_closest   s    ! 	1 	1D <<S))DJJsOOE5zzA~~UqQx~~''#-a0@0@@)))wwt}}$$$Qx~~#555wwuQx~~//00000 6ww'''r   r   c                    || j         vrk|t          v sJ t                              |d          }|t	          |i           }n(t
          rt          ||          }nt	          ||          }|| j         |<   | j         |         S )znReturns the Locale for the given locale code.

        If it is not supported, we raise an exception.
        N)_cacher   r   r   	CSVLocaler[   GettextLocale)ri   r   translationsrE   s       r   r   z
Locale.get   s     sz!!-----(,,T488L#"4,, 7&t\::"466%CJtz$r   Nc                 t   || _         t          j        |i                               dd          | _        d| _        dD ]%}| j                             |          r	d| _         n&| j        } |d           |d           |d           |d	           |d
           |d           |d           |d           |d           |d           |d           |d          g| _         |d           |d           |d           |d           |d           |d           |d          g| _        d S )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)	r   r   r   rq   rtl
startswith	translate_months	_weekdays)selfr   prefixre   s       r   __init__zLocale.__init__  s^   	 $T2..2269EE	( 	 	Fy##F++ 
 NAiLLAjMMAgJJAgJJAeHHAfIIAfIIAhKKAkNNAiLLAjMMAjMM
 AhKKAiLLAkNNAjMMAhKKAjMMAhKK
r   messageplural_messagecountc                     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   s       r   r   zLocale.translate0  s     "###r   contextc                     t                      Nr   r   r   r   r   r   s        r   pgettextzLocale.pgettext?  s     "###r   r   TFdate
gmt_offsetrelativeshorterfull_formatc                    t          |t          t          f          r/t          j                            |t          j        j                  }|j        %|                    t          j        j                  }t          j        	                    t          j        j                  }||k    r|r||z
  j
        dk     r|}nd}|t          j        |          z
  }|t          j        |          z
  }|t          j        d          z
  }	||z
  }
|
j
        }|
j        }| j        }d}|s|rl|dk    rf|d	k     r |d
d|          d|iz  S |dk     r$t          |dz            } |dd|          d|iz  S t          |dz            } |dd|          d|iz  S |dk    r |d          }nn|dk    r+|j        |	j        k    r|r|r |d          n
 |d          }n=|dk     r|r |d          n
 |d          }n|dk     r|r |d          n
 |d          }||r |d           n
 |d!          }| j        d"v}|rd#|j        |j        fz  }nX| j        d$k    r'd%d&|j        d'k             |j        d'z  pd'|j        fz  }n&d(|j        d'z  pd'|j        d)|j        d'k             fz  }|| j        |j        dz
           | j        |                                         t/          |j                  t/          |j                  |d*z  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   2   z1 second agoz%(seconds)d seconds agosecondsi  g      N@z1 minute agoz%(minutes)d minutes agor   g      @z
1 hour agoz%(hours)d hours agor   z%(time)sr.   	yesterdayzyesterday 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   rf   nowr   	timedeltadaysr   roundr   r   hourminuter   monthr   r   rZ   r   )r   r   r   r   r   r   r   
local_date	local_nowlocal_yesterday
differencer   r   re   formatr   r   tfhour_clockstr_times                      r   format_datezLocale.format_dateH  s   . dS%L)) 	P$2249J9NOOD;<<x'8'<<==D##H$5$9::#:: #TCZ0255  #H.zBBBB
(,Z@@@@	#h&8r&B&B&BB4Z
$N 	 XDAIIR<<1^-FPP!7T   W$$#GdN33G1^-FPP!7T   g344q'<eDDQVGWWWqyy:z~1DDDD+2R;:Q8R8R-4V=)))!!<U:V:V AAA.///?@@  > G4555QEFF  y(@@ 	 JOZ5F#GGHHY'!!"0B1FG"$*!& HH $"$*!Z_23' H ,z'7!';<~j&8&8&:&:;z~&&
((
 
 
 	
r   dowc                 X   |t          j        |          z
  }| j        }|rT |d          | j        |j        dz
           | j        |                                         t          |j                  dz  S  |d          | j        |j        dz
           t          |j                  dz  S )zFormats 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   r   r   r   r   r   rZ   r   )r   r   r   r   r   re   s         r   
format_dayzLocale.format_day  s     H.zBBBB
N 
	1:;;"l:+;a+?@>**<*<*>*>?:>**? ?   1-.."l:+;a+?@:>**2 2  r   rj   c                 0   | j         }t          |          dk    rdS t          |          dk    r|d         S | j                            d          rdnd} |d          |                    |dd	                   |t          |          dz
           d
z  S )zReturns 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.   rs   u    و z, z%(commas)s and %(last)sN)commaslast)r   r;   r   r   r8   )r   rj   re   commas       r   r   zLocale.list  s     Nu::??2u::??8O"i22488B

dq*++jjss,,#e**q.)/
 /
 
 	
r   valuec                     | j         dvrt          |          S t          |          }g }|r)|                    |dd                    |dd         }|)d                    t	          |                    S )z7Returns a comma-separated number for the given integer.)r   r   N,)r   rZ   appendr8   reversed)r   r   srj   s       r   friendly_numberzLocale.friendly_number  s~    9O++u::JJ 	LL233   #2#A  	 xx(((r   NN)r   TFF)r   T)__name__
__module____qualname____doc__rl   classmethodrZ   r   r   r   r
   r   r   r   r   r   r   boolr   r   r   r   r   r%   r   r   r   r      sM         F( ( ( ( ( [("  s  x       [ "!
S !
T !
 !
 !
 !
L )-#	$ $$ !$ }	$
 
$ $ $ $& )-#$ $$ $ !	$
 }$ 
$ $ $ $ !h
 h
C 112h
 h
 	h

 h
 h
 
h
 h
 h
 h
V IM %36AE	   ,
# 
# 
 
 
 
"	)S 	)S 	) 	) 	) 	) 	) 	)r   c                        e Zd ZdZdedeeeeef         f         ddf fdZ	 	 ddedee         d	ee         defd
Z		 	 ddededee         d	ee         def
dZ
 xZS )rm   z=Locale implementation using tornado's CSV translation format.r   ro   r   Nc                 X    || _         t                                          |           d S r   )ro   superr   r   r   ro   	__class__s      r   r   zCSVLocale.__init__  s)    (r   r   r   r   c                     |D|J |dk    r|}| j                             di           }n7| j                             di           }n| j                             di           }|                    ||          S )Nr.   r,   r-   r+   )ro   r   )r   r   r   r   message_dicts        r   r   zCSVLocale.translate  s     %$$$zz(#044XrBB#044ZDD,00B??L111r   r   c                 f    | j         rt          j        d           |                     |||          S )Nz&pgettext is not supported by CSVLocale)ro   r   warningr   r   s        r   r   zCSVLocale.pgettext  s7      	FODEEE~~g~u===r   r   )r   r   r   r   rZ   r	   r   r
   r   r   r   __classcell__r   s   @r   rm   rm     s       GGS S$sCx.5H0I d       )-#	2 22 !2 }	2
 
2 2 2 2* )-#	> 	>	> 	> !		>
 }	> 
	> 	> 	> 	> 	> 	> 	> 	>r   rm   c                        e Zd ZdZdedej        ddf fdZ	 	 ddedee         d	ee	         defd
Z
	 	 ddededee         d	ee	         def
dZ xZS )rn   z1Locale implementation using the `gettext` module.r   ro   r   Nc                 z    |j         | _         |j        | _        t                                          |           d S r   )ngettextrX   r   r   r   s      r   r   zGettextLocale.__init__  s7    $-#+ 	r   r   r   r   c                 f    ||J |                      |||          S |                     |          S r   )r   rX   r   s       r   r   zGettextLocale.translate  s>     %$$$==.%@@@<<(((r   r   c                     |K|J | t            | | t            | |f} | j        | }t           |v r|                     |||          }|S | t            | }|                     |          }t           |v r|}|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
        )CONTEXT_SEPARATORr   rX   )r   r   r   r   r   msgs_with_ctxtresultmsg_with_ctxts           r   r   zGettextLocale.pgettext  s    4 %$$$8-8w88?-?~??N
 #T]N3F F**wFFM&D(9D7DDM\\-00F F** Mr   r   )r   r   r   r   rZ   rX   NullTranslationsr   r
   r   r   r   r   r   s   @r   rn   rn   	  s       ;;S 0H T       )-#	
) 
)
) !
) }	
)
 

) 
) 
) 
)  )-#, ,, , !	,
 }, 
, , , , , , , ,r   rn   r   )#r   r<   r@   r   rX   rU   r0   r4   tornador   tornado.logr   tornado._locale_datar   typingr   r   r   r	   r
   r   r   r   r   r[   r   rZ   r   r   rO   r_   ra   r   rm   rn   r%   r   r   <module>r      sO   2  



    				 				             - - - - - - 7 7 7 7 7 7 7 7 7 7 7 7 7 7Y011  -s -x - - - -SS ST S S S STG TG TG TG TG TG TG TGn'G 'Gc 'Gd 'G 'G 'G 'GTx}    
B) B) B) B) B) B) B) B)J!> !> !> !> !> !> !> !>HB B B B BF B B B B Br   