Mc@sdZddlZddlZddlmZdddddgZd Zead Z i'd d 6d d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6dUdV6dWdX6Z de fdYYZ de fdZYZee d[Zd\e d]Zd\d^ZdS(_s2Core locale representation and locale data access.iN(t localedatatUnknownLocaleErrortLocaletdefault_localetnegotiate_localet parse_localesrestructuredtext encCstdkrrtjjtjjt}tjj|d}t|d}ztj |aWd|j Xntj |iS(sReturn the dictionary for the given key in the global data. The global data is stored in the ``babel/global.dat`` file and contains information independent of individual locales. >>> get_global('zone_aliases')['UTC'] 'Etc/GMT' >>> get_global('zone_territories')['Europe/Berlin'] 'DE' :param key: the data key :return: the dictionary found in the global data under the given key :rtype: `dict` :since: version 0.9 s global.dattrbN( t _global_datatNonetostpathtjointdirnamet__file__topentpickletloadtclosetget(tkeyR tfilenametfileobj((s./usr/lib/python2.7/site-packages/babel/core.pyt get_globals tar_SYtartbg_BGtbgtbs_BAtbstca_EStcatcs_CZtcstda_DKtdatde_DEtdetel_GRtelten_UStentes_EStestet_EEtettfa_IRtfatfi_FItfitfr_FRtfrtgl_EStglthe_ILthethu_HUthutid_IDtidtis_IStistit_ITtittja_JPtjatkm_KHtkmtko_KRtkotlt_LTtlttlv_LVtlvtmk_MKtmktnl_NLtnltnn_NOtnntnb_NOtnotpl_PLtpltpt_PTtpttro_ROtrotru_RUtrutsk_SKtsktsl_SItsltsv_SEtsvtth_THtthttr_TRttrtuk_UAtukcBseZdZdZRS(s[Exception thrown when a locale is requested for which no locale data is available. cCs!tj|d|||_dS(srCreate the exception. :param identifier: the identifier string of the unsupported locale sunknown locale %rN(t Exceptiont__init__t identifier(tselfRg((s./usr/lib/python2.7/site-packages/babel/core.pyRfHs(t__name__t __module__t__doc__Rf(((s./usr/lib/python2.7/site-packages/babel/core.pyRCscBseZdZdDdDdDdZdDedZeeZdedZeeZddZ ee Z dZ dZ dZ d Z d ZeeZdDd Zeed d ZdZeed dZdZeed dZdZeed dZdZeed dZdZeed dZdZeed dZdZeed dZdZeed dZdZeed dZd Zeed d!Zd"Zeed d#Zd$Zeed d%Zd&Zeed d'Zd(Zeed d)Zd*Z ee d d+Z d,Z!ee!d d-Z!d.Z"ee"d d/Z"d0Z#ee#d d1Z#d2Z$ee$d d3Z$d4Z%ee%d d5Z%d6Z&ee&d d7Z&d8Z'ee'd d9Z'd:Z(ee(d d;Z(d<Z)ee)d d=Z)d>Z*ee*d d?Z*d@Z+ee+d dAZ+dBZ,ee,d dCZ,RS(EsxRepresentation of a specific locale. >>> locale = Locale('en', 'US') >>> repr(locale) '' >>> locale.display_name u'English (United States)' A `Locale` object can also be instantiated from a raw locale string: >>> locale = Locale.parse('en-US', sep='-') >>> repr(locale) '' `Locale` objects provide access to a collection of locale data, such as territory and language names, number and date format patterns, and more: >>> locale.number_symbols['decimal'] u'.' If a locale is requested for which no locale data is available, an `UnknownLocaleError` is raised: >>> Locale.parse('en_DE') Traceback (most recent call last): ... UnknownLocaleError: unknown locale 'en_DE' :see: `IETF RFC 3066 `_ cCs[||_||_||_||_d|_t|}tj|sWt |ndS(sInitialize the locale object from the given identifier components. >>> locale = Locale('en', 'US') >>> locale.language 'en' >>> locale.territory 'US' :param language: the language code :param territory: the territory (country or region) code :param script: the script code :param variant: the variant code :raise `UnknownLocaleError`: if no locale data is available for the requested locale N( tlanguaget territorytscripttvariantRt _Locale__datatstrRtexistsR(RhRlRmRnRoRg((s./usr/lib/python2.7/site-packages/babel/core.pyRfqs      cCs|t|d|S(sxReturn the system default locale for the specified category. >>> for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE']: ... os.environ[name] = '' >>> os.environ['LANG'] = 'fr_FR.UTF-8' >>> Locale.default('LC_MESSAGES') :param category: one of the ``LC_XXX`` environment variable names :param aliases: a dictionary of aliases for locale identifiers :return: the value of the variable, or any of the fallbacks (``LANGUAGE``, ``LC_ALL``, ``LC_CTYPE``, and ``LANG``) :rtype: `Locale` :see: `default_locale` taliases(R(tclstcategoryRs((s./usr/lib/python2.7/site-packages/babel/core.pytdefaultst_cCs8t||d|d|}|r4tj|d|SdS(s Find the best match between available and requested locale strings. >>> Locale.negotiate(['de_DE', 'en_US'], ['de_DE', 'de_AT']) >>> Locale.negotiate(['de_DE', 'en_US'], ['en', 'de']) >>> Locale.negotiate(['de_DE', 'de'], ['en_US']) You can specify the character used in the locale identifiers to separate the differnet components. This separator is applied to both lists. Also, case is ignored in the comparison: >>> Locale.negotiate(['de-DE', 'de'], ['en-us', 'de-de'], sep='-') :param preferred: the list of locale identifers preferred by the user :param available: the list of locale identifiers available :param aliases: a dictionary of aliases for locale identifiers :return: the `Locale` object for the best match, or `None` if no match was found :rtype: `Locale` :see: `negotiate_locale` tsepRsN(RRtparse(Rtt preferredt availableRxRsRg((s./usr/lib/python2.7/site-packages/babel/core.pyt negotiates cCs)t|tr%|t|d|S|S(sLCreate a `Locale` instance for the given locale identifier. >>> l = Locale.parse('de-DE', sep='-') >>> l.display_name u'Deutsch (Deutschland)' If the `identifier` parameter is not a string, but actually a `Locale` object, that object is returned: >>> Locale.parse(l) :param identifier: the locale identifier string :param sep: optional component separator :return: a corresponding `Locale` instance :rtype: `Locale` :raise `ValueError`: if the string does not appear to be a valid locale identifier :raise `UnknownLocaleError`: if no locale data is available for the requested locale :see: `parse_locale` Rx(t isinstancet basestringR(RtRgRx((s./usr/lib/python2.7/site-packages/babel/core.pyRyscCst|t|kS(N(Rq(Rhtother((s./usr/lib/python2.7/site-packages/babel/core.pyt__eq__scCs|j| S(N(R(RhR((s./usr/lib/python2.7/site-packages/babel/core.pyt__ne__scCsdt|S(Ns (Rq(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyt__repr__scCs.djtd|j|j|j|jgS(NRw(R tfilterRRlRnRmRo(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyt__str__scCs:|jdkr3tjtjt||_n|jS(N(RpRRtLocaleDataDictRRq(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyt_datas$cCs|dkr|}ntj|}|jj|j}|jsT|jsT|jrg}|jr|j |j j|jn|jr|j |j j|jn|jr|j |j j|jnt d|}|r|ddj|7}qn|S(sReturn the display name of the locale using the given locale. The display name will include the language, territory, script, and variant, if those are specified. >>> Locale('zh', 'CN', script='Hans').get_display_name('en') u'Chinese (Simplified Han, China)' :param locale: the locale to use :return: the display name s (%s)u, N(RRRyt languagesRRlRmRnRotappendtscriptst territoriestvariantsRR (Rhtlocaletretvaltdetails((s./usr/lib/python2.7/site-packages/babel/core.pytget_display_names     tdocs& The localized display name of the locale. >>> Locale('en').display_name u'English' >>> Locale('en', 'US').display_name u'English (United States)' >>> Locale('sv').display_name u'svenska' :type: `unicode` cCs|jtdS(NR((RR(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyt english_namess The english display name of the locale. >>> Locale('de').english_name u'German' >>> Locale('de', 'DE').english_name u'German (Germany)' :type: `unicode` cCs |jdS(NR(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyR$ss Mapping of language codes to translated language names. >>> Locale('de', 'DE').languages['ja'] u'Japanisch' :type: `dict` :see: `ISO 639 `_ cCs |jdS(NR(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyR0ss Mapping of script codes to translated script names. >>> Locale('en', 'US').scripts['Hira'] u'Hiragana' :type: `dict` :see: `ISO 15924 `_ cCs |jdS(NR(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyR<ss Mapping of script codes to translated script names. >>> Locale('es', 'CO').territories['DE'] u'Alemania' :type: `dict` :see: `ISO 3166 `_ cCs |jdS(NR(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRHss Mapping of script codes to translated script names. >>> Locale('de', 'DE').variants['1901'] u'Alte deutsche Rechtschreibung' :type: `dict` cCs |jdS(Ntcurrency_names(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyt currenciesUss Mapping of currency codes to translated currency names. >>> Locale('en').currencies['COP'] u'Colombian Peso' >>> Locale('de', 'DE').currencies['COP'] u'Kolumbianischer Peso' :type: `dict` cCs |jdS(Ntcurrency_symbols(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRbss Mapping of currency codes to symbols. >>> Locale('en', 'US').currency_symbols['USD'] u'$' >>> Locale('es', 'CO').currency_symbols['USD'] u'US$' :type: `dict` cCs |jdS(Ntnumber_symbols(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRoss Symbols used in number formatting. >>> Locale('fr', 'FR').number_symbols['decimal'] u',' :type: `dict` cCs |jdS(Ntdecimal_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRzss Locale patterns for decimal number formatting. >>> Locale('en', 'US').decimal_formats[None] :type: `dict` cCs |jdS(Ntcurrency_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss\ Locale patterns for currency number formatting. >>> print Locale('en', 'US').currency_formats[None] :type: `dict` cCs |jdS(Ntpercent_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale patterns for percent number formatting. >>> Locale('en', 'US').percent_formats[None] :type: `dict` cCs |jdS(Ntscientific_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale patterns for scientific number formatting. >>> Locale('en', 'US').scientific_formats[None] :type: `dict` cCs |jdS(Ntperiods(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale display names for day periods (AM/PM). >>> Locale('en', 'US').periods['am'] u'AM' :type: `dict` cCs |jdS(Ntdays(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale display names for weekdays. >>> Locale('de', 'DE').days['format']['wide'][3] u'Donnerstag' :type: `dict` cCs |jdS(Ntmonths(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale display names for months. >>> Locale('de', 'DE').months['format']['wide'][10] u'Oktober' :type: `dict` cCs |jdS(Ntquarters(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale display names for quarters. >>> Locale('de', 'DE').quarters['format']['wide'][1] u'1. Quartal' :type: `dict` cCs |jdS(Nteras(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale display names for eras. >>> Locale('en', 'US').eras['wide'][1] u'Anno Domini' >>> Locale('en', 'US').eras['abbreviated'][0] u'BC' :type: `dict` cCs |jdS(Nt time_zones(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss' Locale display names for time zones. >>> Locale('en', 'US').time_zones['Europe/London']['long']['daylight'] u'British Summer Time' >>> Locale('en', 'US').time_zones['America/St_Johns']['city'] u"St. John's" :type: `dict` cCs |jdS(Nt meta_zones(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss Locale display names for meta time zones. Meta time zones are basically groups of different Olson time zones that have the same GMT offset and daylight savings time. >>> Locale('en', 'US').meta_zones['Europe_Central']['long']['daylight'] u'Central European Summer Time' :type: `dict` :since: version 0.9 cCs |jdS(Nt zone_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss(\ Patterns related to the formatting of time zones. >>> Locale('en', 'US').zone_formats['fallback'] u'%(1)s (%(0)s)' >>> Locale('pt', 'BR').zone_formats['region'] u'Hor\xe1rio %s' :type: `dict` :since: version 0.9 cCs|jddS(Nt week_datat first_day(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pytfirst_week_day ss The first day of a week, with 0 being Monday. >>> Locale('de', 'DE').first_week_day 0 >>> Locale('en', 'US').first_week_day 6 :type: `int` cCs|jddS(NRt weekend_start(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRss The day the weekend starts, with 0 being Monday. >>> Locale('de', 'DE').weekend_start 5 :type: `int` cCs|jddS(NRt weekend_end(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyR#ss The day the weekend ends, with 0 being Monday. >>> Locale('de', 'DE').weekend_end 6 :type: `int` cCs|jddS(NRtmin_days(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyt min_week_days.ss The minimum number of days in a week so that the week is counted as the first week of a year or month. >>> Locale('de', 'DE').min_week_days 4 :type: `int` cCs |jdS(Nt date_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyR:ss Locale patterns for date formatting. >>> Locale('en', 'US').date_formats['short'] >>> Locale('fr', 'FR').date_formats['long'] :type: `dict` cCs |jdS(Nt time_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRGss Locale patterns for time formatting. >>> Locale('en', 'US').time_formats['short'] >>> Locale('fr', 'FR').time_formats['long'] :type: `dict` cCs |jdS(Ntdatetime_formats(R(Rh((s./usr/lib/python2.7/site-packages/babel/core.pyRTss Locale patterns for datetime formatting. >>> Locale('en').datetime_formats[None] u'{1} {0}' >>> Locale('th').datetime_formats[None] u'{1}, {0}' :type: `dict` N(-RiRjRkRRftLOCALE_ALIASESRvt classmethodR|RyRRRRRtpropertyRt display_nameRRRRRRRRRRRRRRRRRRRRRRRRRRR(((s./usr/lib/python2.7/site-packages/babel/core.pyRQs                                                                                  cCs|ddddf}xtd |D]}tj|}|r%|dkrnd|krn|jdd}n|d krd }n|r||kr||}ny d jtd t|SWqtk rqXq%q%Wd S( sReturns the system default locale for a given category, based on environment variables. >>> for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE']: ... os.environ[name] = '' >>> os.environ['LANG'] = 'fr_FR.UTF-8' >>> default_locale('LC_MESSAGES') 'fr_FR' The "C" or "POSIX" pseudo-locales are treated as aliases for the "en_US_POSIX" locale: >>> os.environ['LC_MESSAGES'] = 'POSIX' >>> default_locale('LC_MESSAGES') 'en_US_POSIX' :param category: one of the ``LC_XXX`` environment variable names :param aliases: a dictionary of aliases for locale identifiers :return: the value of the variable, or any of the fallbacks (``LANGUAGE``, ``LC_ALL``, ``LC_CTYPE``, and ``LANG``) :rtype: `str` tLANGUAGEtLC_ALLtLC_CTYPEtLANGt:itCtPOSIXt en_US_POSIXRwN(RR(RRR tgetenvtsplitR Rt ValueError(RuRstvarnamestnameR((s./usr/lib/python2.7/site-packages/babel/core.pyRbs     Rwc Csg|D]}|r|j^q}x|D]}|j}||krN|S|r|j|}|r|jd|}|j|kr|Sqn|j|}t|dkr,|dj|kr,|dSq,WdS(s Find the best match between available and requested locale strings. >>> negotiate_locale(['de_DE', 'en_US'], ['de_DE', 'de_AT']) 'de_DE' >>> negotiate_locale(['de_DE', 'en_US'], ['en', 'de']) 'de' Case is ignored by the algorithm, the result uses the case of the preferred locale identifier: >>> negotiate_locale(['de_DE', 'en_US'], ['de_de', 'de_at']) 'de_DE' >>> negotiate_locale(['de_DE', 'en_US'], ['de_de', 'de_at']) 'de_DE' By default, some web browsers unfortunately do not include the territory in the locale identifier for many locales, and some don't even allow the user to easily add the territory. So while you may prefer using qualified locale identifiers in your web-application, they would not normally match the language-only locale sent by such browsers. To workaround that, this function uses a default mapping of commonly used langauge-only locale identifiers to identifiers including the territory: >>> negotiate_locale(['ja', 'en_US'], ['ja_JP', 'en_US']) 'ja_JP' Some browsers even use an incorrect or outdated language code, such as "no" for Norwegian, where the correct locale identifier would actually be "nb_NO" (Bokmål) or "nn_NO" (Nynorsk). The aliases are intended to take care of such cases, too: >>> negotiate_locale(['no', 'sv'], ['nb_NO', 'sv_SE']) 'nb_NO' You can override this default mapping by passing a different `aliases` dictionary to this function, or you can bypass the behavior althogher by setting the `aliases` parameter to `None`. :param preferred: the list of locale strings preferred by the user :param available: the list of locale strings available :param sep: character that separates the different parts of the locale strings :param aliases: a dictionary of aliases for locale identifiers :return: the locale identifier for the best match, or `None` if no match was found :rtype: `str` RwiiN(tlowerRtreplaceRtlenR( RzR{RxRstaRtlltaliastparts((s./usr/lib/python2.7/site-packages/babel/core.pyRs1%    ( c Csd|kr%|jddd}nd|krJ|jddd}n|j|}|jdj}|jstd|nd }}}|rt|ddkr|djr|jdj}qn|rat|ddkr&|djr&|jdj}qat|ddkra|dj ra|jd}qan|rt|ddkr|ddj st|dd kr|ddjr|j}qn|rtd |n||||fS( sParse a locale identifier into a tuple of the form:: ``(language, territory, script, variant)`` >>> parse_locale('zh_CN') ('zh', 'CN', None, None) >>> parse_locale('zh_Hans_CN') ('zh', 'CN', 'Hans', None) The default component separator is "_", but a different separator can be specified using the `sep` parameter: >>> parse_locale('zh-CN', sep='-') ('zh', 'CN', None, None) If the identifier cannot be parsed into a locale, a `ValueError` exception is raised: >>> parse_locale('not_a_LOCALE_String') Traceback (most recent call last): ... ValueError: 'not_a_LOCALE_String' is not a valid locale identifier Encoding information and locale modifiers are removed from the identifier: >>> parse_locale('it_IT@euro') ('it', 'IT', None, None) >>> parse_locale('en_US.UTF-8') ('en', 'US', None, None) >>> parse_locale('de_DE.iso885915@euro') ('de', 'DE', None, None) :param identifier: the locale identifier string :param sep: character that separates the different components of the locale identifier :return: the ``(language, territory, script, variant)`` tuple :rtype: `tuple` :raise `ValueError`: if the string does not appear to be a valid locale identifier :see: `IETF RFC 4646 `_ t.iit@sexpected only letters, got %riiiis#%r is not a valid locale identifierN( RtpopRtisalphaRRRttitletuppertisdigit(RgRxRtlangRnRmRo((s./usr/lib/python2.7/site-packages/babel/core.pyRs0+   &&&**(RkR RtbabelRt__all__t __docformat__RRRRReRtobjectRRRR(((s./usr/lib/python2.7/site-packages/babel/core.pyts0     #######(A