Mc@sdZddlZddlZyddlZWnek rMddlZnXddlmZdddgZdZ iZ ej Z ej jej jedZd Zd Zed Zd Zd efdYZdeefdYZdS(sLow-level locale data access. :note: The `Locale` class, which uses this module under the hood, provides a more convenient interface for accessing the locale data. iN(t DictMixintexiststlisttloadsrestructuredtext ent localedatacCs3|tkrtStjjtjjtd|S(sCheck whether locale data is available for the given locale. :param name: the locale identifier string :return: `True` if the locale data exists, `False` otherwise :rtype: `bool` s%s.dat(t_cachetTruetostpathRtjoint_dirname(tname((s4/usr/lib/python2.7/site-packages/babel/localedata.pyR$s cCs]ggtjtD]}tjj|^qD]*\}}|dkr/|dkr/|^q/S(sReturn a list of all locale identifiers for which locale data is available. :return: a list of locale identifiers (strings) :rtype: `list` :since: version 0.8.1 s.dattroot(RtlistdirR Rtsplitext(tfilenametstemt extension((s4/usr/lib/python2.7/site-packages/babel/localedata.pyR0s8cCs%tjz tj|}|s|dks5| r>i}nO|jd}t|dkrhd}ndj|d }t|j}t j jt d|}t |d}zH|dkr|rt |tj|ntj|}|t|>> d = load('en_US') >>> d['languages']['sv'] u'Swedish' Note that the results are cached, and subsequent requests for the same locale return the same dictionary: >>> d1 = load('en_US') >>> d2 = load('en_US') >>> d1 is d2 True :param name: the locale identifier string (or "root") :param merge_inherited: whether the inherited data should be merged into the data of the requested locale :return: the locale data :rtype: `dict` :raise `IOError`: if no locale data file is found for the given locale identifer, or one of the locales it inherits from R t_iis%s.dattrbN(t _cache_locktacquireRtgettsplittlenR RtcopyRRR topentmergetpickletclosetrelease(R tmerge_inheritedtdatatpartstparentRtfileobj((s4/usr/lib/python2.7/site-packages/babel/localedata.pyR=s*   cCsx|jD]\}}|dk r |j|}t|tr|dkrXi}nt|trv||f}qt|tr|\}}|j}t||||f}q|j}t||n|}|||>> d = {1: 'foo', 3: 'baz'} >>> merge(d, {1: 'Foo', 2: 'Bar'}) >>> items = d.items(); items.sort(); items [(1, 'Foo'), (2, 'Bar'), (3, 'baz')] :param dict1: the dictionary to merge into :param dict2: the dictionary containing the data that should be merged N( titemstNoneRt isinstancetdicttAliasttupleRR(tdict1tdict2tkeytval2tval1taliastothers((s4/usr/lib/python2.7/site-packages/babel/localedata.pyRus"        R(cBs)eZdZdZdZdZRS(sRepresentation of an alias in the locale data. An alias is a value that refers to some other part of the locale data, as specified by the `keys`. cCst||_dS(N(R)tkeys(tselfR1((s4/usr/lib/python2.7/site-packages/babel/localedata.pyt__init__scCsdt|j|jfS(Ns<%s %r>(ttypet__name__R1(R2((s4/usr/lib/python2.7/site-packages/babel/localedata.pyt__repr__scCsv|}x|jD]}||}qWt|trE|j|}n-t|trr|\}}|j|}n|S(sResolve the alias based on the given data. This is done recursively, so if one alias resolves to a second alias, that second alias will also be resolved. :param data: the locale data :type data: `dict` (R1R&R(tresolveR)(R2R tbaseR,R/R0((s4/usr/lib/python2.7/site-packages/babel/localedata.pyR7s  (R5t __module__t__doc__R3R6R7(((s4/usr/lib/python2.7/site-packages/babel/localedata.pyR(s  tLocaleDataDictcBs,eZdZddZdZdZRS(sUDictionary wrapper that automatically resolves aliases to the actual values. cCs2tj|||dkr%|}n||_dS(N(R'R3R%R8(R2R R8((s4/usr/lib/python2.7/site-packages/babel/localedata.pyR3s  cCstj||}}t|tr:|j|j}nt|tr}|\}}|j|jj}t||nt |tkrt |d|j}n||k r|||s$    ! 8 !!