o V\+@sdZddlZddlmZddlmZmZddlmZgdZ da eiZ ddZ d d Z id d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,id-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTZGdUdVdVeZGdWdXdXeZdefdYdZZd[efd\d]Zdbd^d_Zdbd`daZdS)cz babel.core ~~~~~~~~~~ Core locale representation and locale data access. :copyright: (c) 2013-2019 by the Babel Team. :license: BSD, see LICENSE for more details. N) localedata)pickle string_types) PluralRule)UnknownLocaleErrorLocaledefault_localenegotiate_locale parse_localecCstd)NzThe babel data files are not available. This usually happens because you are using a source checkout from Babel and you did not build the data files. Just make sure to run "python setup.py import_cldr" before installing the library.) RuntimeErrorr r ,/usr/lib/python3/dist-packages/babel/core.py_raise_no_data_errorsrcCs|tdur8tjtjt}tj|d}tj|stt|d }t |aWdn1s3wYt |iS)a_Return 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'] u'Etc/UTC' >>> get_global('zone_territories')['Europe/Berlin'] u'DE' The keys available are: - ``all_currencies`` - ``currency_fractions`` - ``language_aliases`` - ``likely_subtags`` - ``parent_exceptions`` - ``script_aliases`` - ``territory_aliases`` - ``territory_currencies`` - ``territory_languages`` - ``territory_zones`` - ``variant_aliases`` - ``windows_zone_mapping`` - ``zone_aliases`` - ``zone_territories`` .. note:: The internal structure of the data may change between versions. .. versionadded:: 0.9 :param key: the data key Nz global.datrb) _global_dataospathjoindirname__file__isfileropenrloadget)keyrfilenamefileobjr r r get_global#s#    rarar_SYbgbg_BGbsbs_BAcaca_EScscs_CZdada_DKdede_DEelel_GRenen_USeses_ESetet_EEfafa_IRfifi_FIfrfr_FRglgl_EShehe_ILhuhu_HUidid_IDisis_ISitit_ITjaja_JPkmkm_KHkoko_KRltlt_LTlvlv_LVmkmk_MKnlnl_NLnnnn_NOnonb_NOplpl_PLptpt_PTroro_ROruru_RUsksk_SKsl_SIsv_SEth_THtr_TRuk_UA)slsvthtrukc@seZdZdZddZdS)rz[Exception thrown when a locale is requested for which no locale data is available. cCst|d|||_dS)zjCreate the exception. :param identifier: the identifier string of the unsupported locale zunknown locale %rN) Exception__init__ identifier)selfrnr r r rmas zUnknownLocaleError.__init__N)__name__ __module__ __qualname____doc__rmr r r r r\s rc@seZdZdZdrddZedefddZedefdd Zedsd d Z d dZ ddZ ddZ ddZ ddZeddZdtddZeeddZdtddZeeddZdtd d!Zeed"dZdtd#d$Zeed%dZed&d'Zed(d)Zed*d+Zed,d-Zed.d/Zed0d1Zed2d3Zed4d5Z ed6d7Z!ed8d9Z"ed:d;Z#edd?Z%ed@dAZ&edBdCZ'edDdEZ(edFdGZ)edHdIZ*edJdKZ+edLdMZ,edNdOZ-edPdQZ.edRdSZ/edTdUZ0edVdWZ1edXdYZ2edZd[Z3ed\d]Z4ed^d_Z5ed`daZ6edbdcZ7edddeZ8edfdgZ9edhdiZ:edjdkZ;edldmZdS)uraYRepresentation of a specific locale. >>> locale = Locale('en', 'US') >>> repr(locale) "Locale('en', territory='US')" >>> 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('en', territory='US')" `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_XX') Traceback (most recent call last): ... UnknownLocaleError: unknown locale 'en_XX' For more information see :rfc:`3066`. NcCs<||_||_||_||_d|_t|}t|st|dS)aInitialize 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) language territoryscriptvariant _Locale__datastrrexistsr)rortrurvrwrnr r r rms zLocale.__init__cCst||d}||S)afReturn the system default locale for the specified category. >>> for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LC_MESSAGES']: ... os.environ[name] = '' >>> os.environ['LANG'] = 'fr_FR.UTF-8' >>> Locale.default('LC_MESSAGES') Locale('fr', territory='FR') The following fallbacks to the variable are always considered: - ``LANGUAGE`` - ``LC_ALL`` - ``LC_CTYPE`` - ``LANG`` :param category: one of the ``LC_XXX`` environment variable names :param aliases: a dictionary of aliases for locale identifiers )aliases)rparse)clscategoryr{ locale_stringr r r defaults  zLocale.default_cCs&t||||d}|rtj||dSdS)a\Find the best match between available and requested locale strings. >>> Locale.negotiate(['de_DE', 'en_US'], ['de_DE', 'de_AT']) Locale('de', territory='DE') >>> Locale.negotiate(['de_DE', 'en_US'], ['en', 'de']) Locale('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='-') Locale('de', territory='DE') :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 )sepr{rN)r rr|)r} preferred availablerr{rnr r r negotiates zLocale.negotiateTcst|durdSt|tr |St|tstd|ft||d}t|}fddfdd}|}|dur9|S|s?t||\}} } } td||}td | | fd } td | | } td | | } | d krnd} | dkrtd} || | | f}t|} td| } | dur|t| }|dur|Std|} | durt| \}}}}||| ||f}|dur|St|)a6Create 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) Locale('de', territory='DE') This also can perform resolving of likely subtags which it does by default. This is for instance useful to figure out the most likely locale for a territory you can use ``'und'`` as the language tag: >>> Locale.parse('und_AT') Locale('de', territory='AT') :param identifier: the locale identifier string :param sep: optional component separator :param resolve_likely_subtags: if this is specified then a locale will have its likely subtag resolved if the locale otherwise does not exist. For instance ``zh_TW`` by itself is not a locale that exists but Babel can automatically expand it to the full form of ``zh_hant_TW``. Note that this expansion is only taking place if no locale exists otherwise. For instance there is a locale ``en`` that can exist by itself. :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 Nz#Unexpected value for identifier: %rrcs z|WStyYdSwN)r)parts)r}r r _try_loads   zLocale.parse.._try_loadcs4|}|dur |S|dd}|dur|SdS)Nr )rlocale)rr r _try_load_reducingsz(Locale.parse.._try_load_reducinglanguage_aliasesterritory_aliasesrscript_aliasesvariant_aliasesZZZzzzlikely_subtags) isinstancerr TypeErrorr get_locale_identifierrrr)r}rnrresolve_likely_subtagsrinput_idrrrtrurvrwnew_id likely_subtag language2rscript2variant2r )rr}r r|sL(         z Locale.parsecCsJdD] }t||s dSq|j|jko$|j|jko$|j|jko$|j|jkS)N)rtrurvrwF)hasattrrtrurvrw)rootherrr r r __eq__Ms     z Locale.__eq__cCs || Sr)r)rorr r r __ne__Vs z Locale.__ne__cCt|j|j|j|jfSr)hashrtrurvrwror r r __hash__YszLocale.__hash__cCsPdg}dD]}t||}|dur|d||fqd|jd|}d|S)N)rurvrwz%s=%rz%r, z Locale(%s))getattrappendrtr)ro parametersrvalueparameter_stringr r r __repr__\s zLocale.__repr__cCrr)rrtrurvrwrr r r __str__es zLocale.__str__cCs&|jdurttt||_|jSr)rxrLocaleDataDictrryrr r r _datais z Locale._datacCs|dur|}t|}|j|j}|rV|js|js|jrVg}|jr,||j |j|jr9||j |j|jrF||j |jt d|}|rV|dd |7}|S)aRReturn 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, China)' :param locale: the locale to use Nz (%s)r)rr| languagesrrtrurvrwrscripts territoriesvariantsfilterr)rorretvaldetailsr r r get_display_nameos    zLocale.get_display_namea 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` )doccC$|dur|}t|}|j|jS)zReturn the language of this locale in the given locale. >>> Locale('zh', 'CN', script='Hans').get_language_name('de') u'Chinesisch' .. versionadded:: 1.0 :param locale: the locale to use N)rr|rrrtrorr r r get_language_names  zLocale.get_language_namezx The localized language name of the locale. >>> Locale('en', 'US').language_name u'English' cCr)z.Return the territory name in the given locale.N)rr|rrrurr r r get_territory_name zLocale.get_territory_namez The localized territory name of the locale if available. >>> Locale('de', 'DE').territory_name u'Deutschland' cCr)z+Return the script name in the given locale.N)rr|rrrvrr r r get_script_namerzLocale.get_script_namez The localized script name of the locale if available. >>> Locale('sr', 'ME', script='Latn').script_name u'latinica' cCs|tdS)zThe english display name of the locale. >>> Locale('de').english_name u'German' >>> Locale('de', 'DE').english_name u'German (Germany)' :type: `unicode`r.)rrrr r r english_names zLocale.english_namecC |jdS)zMapping of language codes to translated language names. >>> Locale('de', 'DE').languages['ja'] u'Japanisch' See `ISO 639 `_ for more information. rrrr r r r zLocale.languagescCr)zMapping of script codes to translated script names. >>> Locale('en', 'US').scripts['Hira'] u'Hiragana' See `ISO 15924 `_ for more information. rrrr r r rrzLocale.scriptscCr)zMapping of script codes to translated script names. >>> Locale('es', 'CO').territories['DE'] u'Alemania' See `ISO 3166 `_ for more information. rrrr r r rrzLocale.territoriescCr)zMapping of script codes to translated script names. >>> Locale('de', 'DE').variants['1901'] u'Alte deutsche Rechtschreibung' rrrr r r r zLocale.variantscCr)aMapping of currency codes to translated currency names. This only returns the generic form of the currency name, not the count specific one. If an actual number is requested use the :func:`babel.numbers.get_currency_name` function. >>> Locale('en').currencies['COP'] u'Colombian Peso' >>> Locale('de', 'DE').currencies['COP'] u'Kolumbianischer Peso' currency_namesrrr r r currencies zLocale.currenciescCr)zMapping of currency codes to symbols. >>> Locale('en', 'US').currency_symbols['USD'] u'$' >>> Locale('es', 'CO').currency_symbols['USD'] u'US$' currency_symbolsrrr r r r zLocale.currency_symbolscCr)zSymbols used in number formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('fr', 'FR').number_symbols['decimal'] u',' number_symbolsrrr r r r rzLocale.number_symbolscCr)zLocale patterns for decimal number formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').decimal_formats[None] decimal_formatsrrr r r r,rzLocale.decimal_formatscCr)a{Locale patterns for currency number formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').currency_formats['standard'] >>> Locale('en', 'US').currency_formats['accounting'] currency_formatsrrr r r r8rzLocale.currency_formatscCr)zLocale patterns for percent number formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').percent_formats[None] percent_formatsrrr r r rFrzLocale.percent_formatscCr)zLocale patterns for scientific number formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').scientific_formats[None] scientific_formatsrrr r r rRrzLocale.scientific_formatscCs,z |jdddWStyiYSw)zrLocale display names for day periods (AM/PM). >>> Locale('en', 'US').periods['am'] u'AM' day_periodsz stand-alonewide)rKeyErrorrr r r periods`s  zLocale.periodscCr)zLocale display names for various day periods (not necessarily only AM/PM). These are not meant to be used without the relevant `day_period_rules`. rrrr r r rls zLocale.day_periodscCs|jdiS)zCDay period rules for the locale. Used by `get_period_id`. day_period_rules)rrrr r r rtszLocale.day_period_rulescCr)z{Locale display names for weekdays. >>> Locale('de', 'DE').days['format']['wide'][3] u'Donnerstag' daysrrr r r rzrz Locale.dayscCr)zyLocale display names for months. >>> Locale('de', 'DE').months['format']['wide'][10] u'Oktober' monthsrrr r r rrz Locale.monthscCr)zLocale display names for quarters. >>> Locale('de', 'DE').quarters['format']['wide'][1] u'1. Quartal' quartersrrr r r rrzLocale.quarterscCr)aLocale display names for eras. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').eras['wide'][1] u'Anno Domini' >>> Locale('en', 'US').eras['abbreviated'][0] u'BC' erasrrr r r rrz Locale.erascCr)ucLocale display names for time zones. .. note:: The format of the value returned may change between Babel versions. >>> 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' time_zonesrrr r r rrzLocale.time_zonescCr)aLocale 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. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').meta_zones['Europe_Central']['long']['daylight'] u'Central European Summer Time' .. versionadded:: 0.9 meta_zonesrrr r r rs zLocale.meta_zonescCr)acPatterns related to the formatting of time zones. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').zone_formats['fallback'] u'%(1)s (%(0)s)' >>> Locale('pt', 'BR').zone_formats['region'] u'Hor\xe1rio %s' .. versionadded:: 0.9 zone_formatsrrr r r r zLocale.zone_formatscC|jddS)zThe first day of a week, with 0 being Monday. >>> Locale('de', 'DE').first_week_day 0 >>> Locale('en', 'US').first_week_day 6 week_data first_dayrrr r r first_week_days zLocale.first_week_daycCr)zqThe day the weekend starts, with 0 being Monday. >>> Locale('de', 'DE').weekend_start 5 r weekend_startrrr r r rzLocale.weekend_startcCr)zmThe day the weekend ends, with 0 being Monday. >>> Locale('de', 'DE').weekend_end 6 r weekend_endrrr r r rrzLocale.weekend_endcCr)zThe 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 rmin_daysrrr r r min_week_daysszLocale.min_week_dayscCr)aJLocale patterns for date formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').date_formats['short'] >>> Locale('fr', 'FR').date_formats['long'] date_formatsrrr r r rrzLocale.date_formatscCr)aLLocale patterns for time formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en', 'US').time_formats['short'] >>> Locale('fr', 'FR').time_formats['long'] time_formatsrrr r r rrzLocale.time_formatscCr)a,Locale patterns for datetime formatting. .. note:: The format of the value returned may change between Babel versions. >>> Locale('en').datetime_formats['full'] u"{1} 'at' {0}" >>> Locale('th').datetime_formats['medium'] u'{1} {0}' datetime_formatsrrr r r rrzLocale.datetime_formatscCr)aALocale patterns for formatting parts of a datetime. >>> Locale('en').datetime_skeletons['MEd'] >>> Locale('fr').datetime_skeletons['MEd'] >>> Locale('fr').datetime_skeletons['H'] datetime_skeletonsrrr r r r#s zLocale.datetime_skeletonscCr)uLocale patterns for interval formatting. .. note:: The format of the value returned may change between Babel versions. How to format date intervals in Finnish when the day is the smallest changing component: >>> Locale('fi_FI').interval_formats['MEd']['d'] [u'E d. – ', u'E d.M.'] .. seealso:: The primary API to use this data is :py:func:`babel.dates.format_interval`. :rtype: dict[str, dict[str, list[str]]] interval_formatsrrr r r r0s zLocale.interval_formatscC|jdtS)aPlural rules for the locale. >>> Locale('en').plural_form(1) 'one' >>> Locale('en').plural_form(0) 'other' >>> Locale('fr').plural_form(0) 'one' >>> Locale('ru').plural_form(100) 'many' plural_formrr_default_plural_rulerr r r rFs zLocale.plural_formcCr)aPatterns for generating lists .. note:: The format of the value returned may change between Babel versions. >>> Locale('en').list_patterns['standard']['start'] u'{0}, {1}' >>> Locale('en').list_patterns['standard']['end'] u'{0}, and {1}' >>> Locale('en_GB').list_patterns['standard']['end'] u'{0} and {1}' list_patternsrrr r r rUrzLocale.list_patternscCr)a?Plural rules for the locale. >>> Locale('en').ordinal_form(1) 'one' >>> Locale('en').ordinal_form(2) 'two' >>> Locale('en').ordinal_form(3) 'few' >>> Locale('fr').ordinal_form(2) 'other' >>> Locale('ru').ordinal_form(100) 'other' ordinal_formrrr r r reszLocale.ordinal_formcCr)zLocalized names for various measurement systems. >>> Locale('fr', 'FR').measurement_systems['US'] u'am\xe9ricain' >>> Locale('en', 'US').measurement_systems['US'] u'US' measurement_systemsrrr r r rvrzLocale.measurement_systemscCr)zThe text direction for the language. >>> Locale('de', 'DE').character_order 'left-to-right' >>> Locale('ar', 'SA').character_order 'right-to-left' character_orderrrr r r rrzLocale.character_ordercCsddd|jdDS)zThe text direction for the language in CSS short-hand form. >>> Locale('de', 'DE').text_direction 'ltr' >>> Locale('ar', 'SA').text_direction 'rtl' rcss|]}|dVqdS)rNr ).0wordr r r sz(Locale.text_direction..-)rrsplitrr r r text_directions zLocale.text_directioncCr)zDisplay names for units of measurement. .. seealso:: You may want to use :py:func:`babel.units.get_unit_name` instead. .. note:: The format of the value returned may change between Babel versions. unit_display_namesrrr r r rrzLocale.unit_display_names)NNN)rTr)?rprqrrrsrm classmethodLOCALE_ALIASESrrr|rrrrrpropertyrr display_namer language_namerterritory_namer script_namerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r rls  o                                                rc Cs|ddddf}td|D]A}t|}|rM|dkr$d|vr$|dd}|ddd vr0d }n |r:||vr:||}z tt|WStyLYq wq dS) aReturns 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' The following fallbacks to the variable are always considered: - ``LANGUAGE`` - ``LC_ALL`` - ``LC_CTYPE`` - ``LANG`` :param category: one of the ``LC_XXX`` environment variable names :param aliases: a dictionary of aliases for locale identifiers LANGUAGELC_ALLLC_CTYPELANGN:r.)CPOSIX en_US_POSIX)rrgetenvrrr ValueError)r~r{varnamesnamerr r r rs"   rrcCsdd|D}|D]@}|}||vr|S|r0||}|r0|d|}||vr0|S||}t|dkrI|d|vrI|dSq dS)ulFind 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 cSsg|]}|r|qSr )lower)rar r r sz$negotiate_locale..rrN)r rreplacerlen)rrrr{rllaliasrr r r r s .     r cCsTd|vr |ddd}d|vr|ddd}||}|d}|s.td|d}}}|rKt|ddkrK|drK|d}|rvt|ddkrc|drc|d}nt|dd krv|drv|d}|rt|ddkr|ddst|dd kr|ddr|}|rtd |||||fS) aParse 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) See :rfc:`4646` for more information. :param identifier: the locale identifier string :param sep: character that separates the different components of the locale identifier :raise `ValueError`: if the string does not appear to be a valid locale identifier rrr@zexpected only letters, got %rNrz#%r is not a valid locale identifier) rpopr isalphar rtitleupperisdigit)rnrrlangrvrurwr r r r s0(        r cCsDt|dd}|ddt|\}}}}|td||||fS)aThe reverse of :func:`parse_locale`. It creates a locale identifier out of a ``(language, territory, script, variant)`` tuple. Items can be set to ``None`` and trailing ``None``\s can also be left out of the tuple. >>> get_locale_identifier(('de', 'DE', None, '1999')) 'de_DE_1999' .. versionadded:: 1.0 :param tup: the tuple as returned by :func:`parse_locale`. :param sep: the separator for the identifier. Nrr)tuplerrr)tuprrrurvrwr r r r^s r)r)rsrbabelr babel._compatrr babel.pluralr__all__rrrrrrlrobjectrrr r rr r r r s   - A- ?K