jff8dZddlmZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZddlmZmZmZmZddlmZmZmZmZmZmZe r dd lmZdd lmZGd d ZGd dZGddej Z Gdde ej!Z"dS)a- babel.support ~~~~~~~~~~~~~ Several classes and functions that help with integrating and using Babel in applications. .. note: the code in this module is not used by Babel itself :copyright: (c) 2013-2023 by the Babel Team. :license: BSD, see LICENSE for more details. ) annotationsN)Iterator) TYPE_CHECKINGAnyCallable)Locale) format_dateformat_datetime format_timeformat_timedelta)format_compact_currencyformat_compact_decimalformat_currencyformat_decimalformat_percentformat_scientific)Literal)_PredefinedTimeFormatceZdZdZd6d7d Z d8d9dZ d8d:dZ d8d;dZ dd&Z d6d?d(Z d@dAd/Z dBd1Z d@dCd3Z d6d?d4Zd>d5ZdS)DFormataCWrapper class providing the various date and number formatting functions bound to a specific locale and time-zone. >>> from babel.util import UTC >>> from datetime import date >>> fmt = Format('en_US', UTC) >>> fmt.date(date(2007, 4, 1)) u'Apr 1, 2007' >>> fmt.decimal(1.2345) u'1.234' Nlocale Locale | strtzinfodatetime.tzinfo | NonereturnNonecFtj||_||_dS)zInitialize the formatter. :param locale: the locale identifier or `Locale` instance :param tzinfo: the time-zone info (a `tzinfo` instance or `None`) N)rparserr)selfrrs m/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/babel/support.py__init__zFormat.__init__4s l6**  mediumdatedatetime.date | Noneformat_PredefinedTimeFormat | strstrc0t|||jS)zReturn a date formatted according to the given pattern. >>> from datetime import date >>> fmt = Format('en_US') >>> fmt.date(date(2007, 4, 1)) u'Apr 1, 2007' r)r r)rr$r&s r r$z Format.date=s4 <<<>> from datetime import datetime >>> from babel.dates import get_timezone >>> fmt = Format('en_US', tzinfo=get_timezone('US/Eastern')) >>> fmt.datetime(datetime(2007, 4, 1, 15, 30)) u'Apr 1, 2007, 11:30:00 AM' rr)r rr)rr+r&s r r+zFormat.datetimeKsx DKXXXXr"time(datetime.time | datetime.datetime | Nonec<t|||j|jS)u-Return a time formatted according to the given pattern. >>> from datetime import datetime >>> from babel.dates import get_timezone >>> fmt = Format('en_US', tzinfo=get_timezone('US/Eastern')) >>> fmt.time(datetime(2007, 4, 1, 15, 30)) u'11:30:00 AM' r-)r rr)rr.r&s r r.z Format.timeZs4 DKPPPPr"second333333?longFdeltadatetime.timedelta | int granularityCLiteral['year', 'month', 'week', 'day', 'hour', 'minute', 'second'] thresholdfloat,Literal['narrow', 'short', 'medium', 'long'] add_directionboolc6t||||||jS)zReturn a time delta according to the rules of the given locale. >>> from datetime import timedelta >>> fmt = Format('en_US') >>> fmt.timedelta(timedelta(weeks=11)) u'3 months' )r6r8r&r;r)r r)rr4r6r8r&r;s r timedeltazFormat.timedeltais, ;*3'-]'+{444 4r"numberfloat | decimal.Decimal | strc.t||jS)zReturn an integer number formatted for the locale. >>> fmt = Format('en_US') >>> fmt.number(1099) u'1,099' r*rrrr?s r r?z Format.number}sfT[9999r" str | Nonec0t|||jS)zReturn a decimal number formatted for the locale. >>> fmt = Format('en_US') >>> fmt.decimal(1.2345) u'1.234' r*rBrr?r&s r decimalzFormat.decimalffT[AAAAr"shortr format_typeLiteral['short', 'long']fraction_digitsintc2t||||jS)aReturn a number formatted in compact form for the locale. >>> fmt = Format('en_US') >>> fmt.compact_decimal(123456789) u'123M' >>> fmt.compact_decimal(1234567, format_type='long', fraction_digits=2) '1.23 million' rJrLr)rr)rr?rJrLs r compact_decimalzFormat.compact_decimals'&f+6E-1[::: :r"currencyc0t|||jS)zHReturn a number in the given currency formatted for the locale. r*)rr)rr?rQs r rQzFormat.currencysvx DDDDr"Literal['short']c4t|||||jS)zReturn a number in the given currency formatted for the locale using the compact number format. >>> Format('en_US').compact_currency(1234567, "USD", format_type='short', fraction_digits=2) '$1.23M' rO)r r)rr?rQrJrLs r compact_currencyzFormat.compact_currencys.'vx[8GPTP[]]] ]r"c0t|||jS)zReturn a number formatted as percentage for the locale. >>> fmt = Format('en_US') >>> fmt.percent(0.34) u'34%' r*)rrrFs r percentzFormat.percentrHr"c.t||jS)zLReturn a number formatted using scientific notation for the locale. r*)rrrCs r scientificzFormat.scientifics! <<<r?rGrPrQrUrWrYr"r rr's  &*.6 = = = = = *..6 Y Y Y Y Y":>.6 Q Q Q Q Q$\d?E# 44444(::::BBBBB18 :::::$EEEE)0 ]]]]] BBBBB======r"rcZeZdZUdZgdZerded<ded<ded<d ed <d ed <d ed<ddd?dZed@dZ dAdZ dBdZ dCdZ dDd Z dEd"ZdFd$ZdGd&ZdGd'ZdGd(ZdGd)ZdGd*ZdGd+ZdHd,ZdId-ZdId.ZdId/ZdId0ZdId1ZdId2ZdJd4ZdKd5ZdLd7ZdMd8Z dNd9Z!dOd:Z"dPd;Z#dQd=Z$d>S)R LazyProxyaClass for proxy objects that delegate to a specified function to evaluate the actual object. >>> def greeting(name='world'): ... return 'Hello, %s!' % name >>> lazy_greeting = LazyProxy(greeting, name='Joe') >>> print(lazy_greeting) Hello, Joe! >>> u' ' + lazy_greeting u' Hello, Joe!' >>> u'(%s)' % lazy_greeting u'(Hello, Joe!)' This can be used, for example, to implement lazy translation functions that delay the actual translation until the string is actually used. The rationale for such behavior is that the locale of the user may not always be available. In web applications, you only know the locale when processing a request. The proxy implementation attempts to be as complete as possible, so that the lazy objects should mostly work as expected, for example for sorting: >>> greetings = [ ... LazyProxy(greeting, 'world'), ... LazyProxy(greeting, 'Joe'), ... LazyProxy(greeting, 'universe'), ... ] >>> greetings.sort() >>> for greeting in greetings: ... print(greeting) Hello, Joe! Hello, universe! Hello, world! )_func_args_kwargs_value_is_cache_enabled_attribute_errorCallable[..., Any]rbztuple[Any, ...]rczdict[str, Any]rdr<rfrrezAttributeError | NonergT) enable_cachefuncargsrikwargsrrcVt|d|t|d|t|d|t|d|t|ddt|dddS)Nrbrcrdrfrerg)object __setattr__)rrjrirkrls r r!zLazyProxy.__init__s4$///4$///4F3334!4lCCC440004!3T:::::r"c|jm |j|ji|j}n/#t$r"}t |d|d}~wwxYw|js|St |d||jS)Nrgre)rerbrcrdAttributeErrorrnrorf)rvalueerrors r rrzLazyProxy.values ;  " DJ?$,??!   ""4);UCCC )    tXu 5 5 5{s! A AA keyrnc||jvSrZrrrrts r __contains__zLazyProxy.__contains__ sdj  r"c*t|jSrZ)r<rrrs r __bool__zLazyProxy.__bool__ DJr" list[str]c*t|jSrZ)dirrrrzs r __dir__zLazyProxy.__dir__4:r" Iterator[Any]c*t|jSrZ)iterrrrzs r __iter__zLazyProxy.__iter__r|r"rMc*t|jSrZ)lenrrrzs r __len__zLazyProxy.__len__rr"r(c*t|jSrZ)r(rrrzs r __str__zLazyProxy.__str__rr"otherc|j|zSrZrvrrs r __add__zLazyProxy.__add__zE!!r"c||jzSrZrvrs r __radd__zLazyProxy.__radd__tz!!r"c|j|zSrZrvrs r __mod__zLazyProxy.__mod__!rr"c||jzSrZrvrs r __rmod__zLazyProxy.__rmod__$rr"c|j|zSrZrvrs r __mul__zLazyProxy.__mul__'rr"c||jzSrZrvrs r __rmul__zLazyProxy.__rmul__*rr"c|j|i|SrZrv)rrkrls r __call__zLazyProxy.__call__-stz4*6***r"c|j|kSrZrvrs r __lt__zLazyProxy.__lt__0zE!!r"c|j|kSrZrvrs r __le__zLazyProxy.__le__3zU""r"c|j|kSrZrvrs r __eq__zLazyProxy.__eq__6rr"c|j|kSrZrvrs r __ne__zLazyProxy.__ne__9rr"c|j|kSrZrvrs r __gt__zLazyProxy.__gt__<rr"c|j|kSrZrvrs r __ge__zLazyProxy.__ge__?rr"namec0t|j|dSrZ)delattrrrrrs r __delattr__zLazyProxy.__delattr__Bs D!!!!!r"cH|j|jt|j|SrZ)rggetattrrrrs r __getattr__zLazyProxy.__getattr__Es&  ,' 'tz4(((r"rrc2t|j||dSrZ)setattrrr)rrrrs r rozLazyProxy.__setattr__Js D%(((((r"c|j|=dSrZrvrws r __delitem__zLazyProxy.__delitem__Ms JsOOOr"c|j|SrZrvrws r __getitem__zLazyProxy.__getitem__Psz#r"c||j|<dSrZrv)rrtrrs r __setitem__zLazyProxy.__setitem__Ss 3r"cNt|jg|jRd|ji|jS)Nri)rarbrcrfrdrzs r __copy__zLazyProxy.__copy__VsF J Z   / l    r"memocddlm}t||j|g||j|Rd||j|i||j|S)Nr)deepcopyri)copyrrarbrcrfrd)rrrs r __deepcopy__zLazyProxy.__deepcopy__^s!!!!!! HTZ & & Xdj$ ' '   !$"8$?? ht|T**    r"N) rjrhrkrrir<rlrrr)rr)rtrnrr<)rr<)rr})rr)rrMrr()rrnrr)rkrrlrrr)rrnrr<)rr(rr)rr(rr)rr(rrrrr)rtrrr)rtrrr)rtrrrrrr)rra)rrrra)%r[r\r]r^ __slots__r__annotations__r!propertyrrrxr{rrrrrrrrrrrrrrrrrrrrorrrrrr_r"r raras!!Da``I0!!!! ////RV;;;;;;   X !!!!        """"""""""""""""""""""""++++""""############""""####"""")))) ))))              r"raceZdZUer ded<ded<dZd)d*fd Zd+dZd+dZd+dZ e Z d,dZ d,dZ d,dZ e ZdZd-dZd.dZd/dZd0d Zd1d!Zd/d"Zd2d#Zd3d$ZeZd4d%Zd5d&Zd5d'ZeZd6d(ZejjZ ejj!Z"xZ#S)7NullTranslationszdict[str, str]_infozNullTranslations | None _fallbackNfp"gettext._TranslationsReader | Nonerrc i|_d|_t|t t dt |ddg|_|j|_ i|_ dS)aInitialize a simple translations class which is not backed by a real catalog. Behaves similar to gettext.NullTranslations but also offers Babel's on *gettext methods (e.g. 'dgettext()'). :param fp: a file-like object (ignored in this class) c(t|dkS)N)rM)ns r z+NullTranslations.__init__..{s#aSTf++r"rNr) _catalogpluralsuperr!listfilterrfilesDEFAULT_DOMAINdomain_domains)rr __class__s r r!zNullTranslations.__init__psn;= @U@U  B&FD(A(A'BCCDD ) 57 r"rr(messagec^|j|||S)zULike ``gettext()``, but look the message up in the specified domain. )rgetgettextrrrs r dgettextzNullTranslations.dgettexts*}  ..66w???r"cddl}|dtd|j|||S)zVLike ``lgettext()``, but look the message up in the specified domain. rNz1ldgettext() is deprecated, use dgettext() instead)warningswarnDeprecationWarningrrlgettext)rrrrs r ldgettextzNullTranslations.ldgettextsQ  I(! - - -}  ..77@@@r"c^|j|||S)zVLike ``ugettext()``, but look the message up in the specified domain. )rrugettextrs r udgettextzNullTranslations.udgettexts*}  ..77@@@r"singularrnumrMcb|j|||||S)zVLike ``ngettext()``, but look the message up in the specified domain. )rrngettextrrrrrs r dngettextzNullTranslations.dngettexts.}  ..77&#NNNr"cddl}|dtd|j|||||S)zWLike ``lngettext()``, but look the message up in the specified domain. rNz3ldngettext() is deprecated, use dngettext() insteadr)rrrrr lngettext)rrrrrrs r ldngettextzNullTranslations.ldngettextsU  K(! - - -}  ..8863OOOr"cb|j|||||S)zVLike ``ungettext()`` but look the message up in the specified domain. )rr ungettextrs r udngettextzNullTranslations.udngettexts.}  ..8863OOOr"z%s%scontext str | objectc|j||fz}t}|j||}||ur$|jr|j||S|S|S)aLook up the `context` and `message` id in the catalog and return the corresponding message string, as an 8-bit string encoded with the catalog's charset encoding, if known. If there is no entry in the catalog for the `message` id and `context` , and a fallback has been set, the look up is forwarded to the fallback's ``pgettext()`` method. Otherwise, the `message` id is returned. )CONTEXT_ENCODINGrnrrrpgettext)rrr ctxt_msg_idmissingtmsgs r rzNullTranslations.pgettextsl+w.@@ ((}  g66 7??~ A~..w@@@N r"str | bytes | objectcddl}|dtd|||}t |ddpt j}t|tr| |n|S)zEquivalent to ``pgettext()``, but the translation is returned in the preferred system encoding, if no other encoding was explicitly set with ``bind_textdomain_codeset()``. rNz1lpgettext() is deprecated, use pgettext() insteadr_output_charset) rrrrrrgetpreferredencoding isinstancer(encode)rrrrrencodings r lpgettextzNullTranslations.lpgettexts  I(! - - -}}Wg..4!2D99ZV=X=Z=Z(24(=(=Gt{{8$$$4Gr"c|j||fz} |j|||f}|S#t$r5|jr|j||||cYS|dkr|cYS|cYSwxYw)a^Do a plural-forms lookup of a message id. `singular` is used as the message id for purposes of lookup in the catalog, while `num` is used to determine which plural form to use. The returned message string is an 8-bit string encoded with the catalog's charset encoding, if known. If the message id for `context` is not found in the catalog, and a fallback is specified, the request is forwarded to the fallback's ``npgettext()`` method. Otherwise, when ``num`` is 1 ``singular`` is returned, and ``plural`` is returned in all other cases. r)rrrKeyErrorr npgettext)rrrrrrrs r r zNullTranslations.npgettexts+w.AA  =+t{{3/?/?!@ADK   ~ P~//63OOOOOaxx  s#2.A1"A1,A10A1 str | bytescddl}|dtd|j||fz} |j|||f}t |ddptj}| |S#t$r5|j r|j ||||cYS|dkr|cYS|cYSwxYw)zEquivalent to ``npgettext()``, but the translation is returned in the preferred system encoding, if no other encoding was explicitly set with ``bind_textdomain_codeset()``. rNz3lnpgettext() is deprecated, use npgettext() insteadrrr) rrrrrrrrrrr r lnpgettext) rrrrrrrrrs r r zNullTranslations.lnpgettexts  K(! - - -+w.AA  =+t{{3/?/?!@ADt%6==^A\A^A^H;;x(( (   ~ Q~00(FCPPPPPaxx  sAB .C9CCCc|j||fz}t}|j||}||ur1|jr|j||St |St|t sJ|S)asLook up the `context` and `message` id in the catalog and return the corresponding message string, as a Unicode string. If there is no entry in the catalog for the `message` id and `context`, and a fallback has been set, the look up is forwarded to the fallback's ``upgettext()`` method. Otherwise, the `message` id is returned. )rrnrrr upgettextr(r)rrrctxt_message_idrrs r rzNullTranslations.upgettexts/7G2DD((}  ':: 7??~ B~//AAAw<< $$$$$$ r"c|j||fz} |j|||f}nZ#t$rM|jr|j||||cYS|dkrt |nt |}YnwxYw|S)a$Do a plural-forms lookup of a message id. `singular` is used as the message id for purposes of lookup in the catalog, while `num` is used to determine which plural form to use. The returned message string is a Unicode string. If the message id for `context` is not found in the catalog, and a fallback is specified, the request is forwarded to the fallback's ``unpgettext()`` method. Otherwise, when `num` is 1 `singular` is returned, and `plural` is returned in all other cases. r)rrrr r unpgettextr()rrrrrrrs r rzNullTranslations.unpgettexts/7H2EE >=/4;;s3C3C!DEDD > > >~ Q~00(FCPPPPP$'1HH3x===#f++DDD > s"1.B!$BBc`|j||||S)zVLike `pgettext()`, but look the message up in the specified `domain`. )rrrrrrrs r dpgettextzNullTranslations.dpgettext$s,}  ..77IIIr"c`|j||||S)zWLike `upgettext()`, but look the message up in the specified `domain`. )rrrrs r udpgettextzNullTranslations.udpgettext*s,}  ..88'JJJr"c`|j||||S)zEquivalent to ``dpgettext()``, but the translation is returned in the preferred system encoding, if no other encoding was explicitly set with ``bind_textdomain_codeset()``. )rrrrs r ldpgettextzNullTranslations.ldpgettext2s, }  ..88'JJJr"cd|j||||||S)zWLike ``npgettext``, but look the message up in the specified `domain`. )rrr rrrrrrs r dnpgettextzNullTranslations.dnpgettext9s:}  ..88(9?FF Fr"cd|j||||||S)zXLike ``unpgettext``, but look the message up in the specified `domain`. )rrrrs r udnpgettextzNullTranslations.udnpgettext@s:}  ..99'8:@#GG Gr"cd|j||||||S)zEquivalent to ``dnpgettext()``, but the translation is returned in the preferred system encoding, if no other encoding was explicitly set with ``bind_textdomain_codeset()``. )rrr rs r ldnpgettextzNullTranslations.ldnpgettextIs: }  ..99'8:@#GG Gr"rZ)rrrr)rr(rr(rr() rr(rr(rr(rrMrr()rr(rr(rr)rr(rr(rr) rr(rr(rr(rrMrr() rr(rr(rr(rrMrr )rr(rr(rr()rr(rr(rr(rr)rr(rr(rr(rr()rr(rr(rr(rr) rr(rr(rr(rr(rrMrr() rr(rr(rr(rr(rrMrr )$r[r\r]rrrr!rrr dugettextrrr dungettextrrrr r rrrr dupgettextrrr dunpgettextr rrrrr __classcell__rs@r rrhs5+****N8888888"@@@@ AAAAAAAA IOOOO PPPPPPPP J"" H H H H.*"(JJJJ KKKK JKKKKFFFFGGGGKGGGG'/H(1IIIIIr"rceZdZdZdZddfd ZejjZejj Z e dddZ ddZ dddZddZxZS) Translationsz&An extended translation catalog class.messagesNrrrrDcht||p|j|_dS)zInitialize the translations catalog. :param fp: the file-like object the translation should be read from :param domain: the message domain (default: 'messages') rN)rr!rr)rrrrs r r!zTranslations.__init__Zs3 B3 3 r"dirnamestr | os.PathLike[str] | Nonelocales(list[str] | tuple[str, ...] | str | Nonerrc(|+t|ttfs|g}d|D}|s|j}t j|||}|st St|d5}|||cdddS#1swxYwYdS)apLoad translations from the given directory. :param dirname: the directory containing the ``MO`` files :param locales: the list of locales in order of preference (items in this list can be either `Locale` objects or locale strings) :param domain: the message domain (default: 'messages') Nc,g|]}t|Sr_)r().0rs r z%Translations.load..xs999vs6{{999r"rb)rr)rrtuplerrfindropen)clsr+r-rfilenamers r loadzTranslations.loadfs  ge}55 $")99999G ('F<99 &#%% % (D ! ! -R3"V,,, - - - - - - - - - - - - - - - - - -s- BB B r(cl|jd}dt|jd|dS)Nzproject-id-version)rrtyper[)rversions r __repr__zTranslations.__repr__s8*..!56664::&6676666r"T translationsmerger<cBt|d|j}|r ||jkr||S|j|}|r+t |tr||n||||j|<|S)a!Add the given translations to the catalog. If the domain of the translations is different than that of the current catalog, they are added as a catalog that is only accessible by the various ``d*gettext`` functions. :param translations: the `Translations` instance with the messages to add :param merge: whether translations for message domains that have already been added should be merged with the existing translations r) rrrr@rrrr( add_fallback)rr?r@rexistings r addzTranslations.addsx1DEE  ,Vt{**::l++ +=$$V,,  1Z,77 1 NN< ( ( ( (  % %d + + +$0DM& ! r"ct|tjrS|j|jt|t r|j|j|S)a0Merge the given translations into the catalog. Message translations in the specified catalog override any messages with the same identifier in the existing catalog. :param translations: the `Translations` instance with the messages to merge )rrGNUTranslationsrupdater(rextend)rr?s r r@zTranslations.mergesb lG$; < < 6 M !6 7 7 7, 55 6 !!,"4555 r")NN)rrrrD)NNN)r+r,r-r.rrDrrr)T)r?r(r@r<)r?r()r[r\r]r^rr!rrFrrr classmethodr9r>rDr@r%r&s@r r(r(Us00N4444444&.H'0I26<@! ----[-477774r"r()#r^ __future__rrGrroscollections.abcrtypingrrr babel.corer babel.datesr r r r babel.numbersr rrrrrtyping_extensionsrrrrarrFr(r_r"r rRs  #""""" $$$$$$//////////SSSSSSSSSSSS2))))))111111[=[=[=[=[=[=[=[=|` ` ` ` ` ` ` ` Fj2j2j2j2j2w/j2j2j2ZXXXXX#W%<XXXXXr"