;ò hkDc@s°dkZdkZd„ZeidƒZeidƒZeidƒZd„Zdfd„ƒYZdefd „ƒYZ d fd „ƒYZ d e fd „ƒYZ d„Z dS(NcCst|tƒƒSdS(s Parse an Accept-Language header.N(s_parseshdrs_LanguageSelector(shdr((s lib/accept.pyslanguagess\s*([^\s;,"]+|"[^"]*")+\s*s;\s*([^;,"]+|"[^"]*")+\s*s([^\s=])\s*=\s*(.*)cCsþ| o|Snd}xÝ|t|ƒjoÉti||ƒ}| o tƒ‚n|it i |i dƒƒƒ}|i ƒ}x;no3ti||ƒ}| oPn|i dƒ}|i ƒ}ti|ƒ}| oqŠnt i |i dƒƒ}|djp |djo6yt|i dƒƒ|_Wq¹tj oq¹Xqƒ|djo6yt|i dƒƒ|_Wq¹tj oq¹Xqƒ|djot i |i dƒƒ|_qƒqŠW|i|ƒ|||d!djo|d}qqW|SdS( Niisqsqsislevelscharsets,(shdrsresultsposslens _re_tokensmatchsnamesAcceptParseErrors item_classsstringslowersgroupsasends _re_paramsparams_re_split_paramspnamesfloatsqualitys ValueErrorslevelscharsetsappend(shdrsresultsasnamespossparamspnamesmatch((s lib/accept.pys_parse!sJ !      $ s _AcceptItemcBstZd„Zd„ZRS(NcCs(||_d|_d|_d|_dS(Nf1.0f0.0s(snamesselfsqualityslevelscharset(sselfsname((s lib/accept.pys__init__Rs   cCs€|i}|idjod||if}n|idjod||if}n|iod||if}n|SdS(Nf1.0s %s;q=%.3ff0.0s %s;level=%.3fs %s;charset=%s(sselfsnamesssqualityslevelscharset(sselfss((s lib/accept.pys__str__Xs  (s__name__s __module__s__init__s__str__(((s lib/accept.pys _AcceptItemQs s_LanguageRangecBstZd„ZRS(NcCsR||ijo |iSn|id}|t|ƒ |jo |iSntSdS(sHMatch the tag against self. Returns the qvalue, or None if non-matching.s-N(stagsselfsnamesqualityslensNone(sselfstagsname((s lib/accept.pysmatchescs   (s__name__s __module__smatches(((s lib/accept.pys_LanguageRangebss_LanguageSelectorcBs/tZdZeZd„Zd„Zd„ZRS(s_Instances select an available language based on the user's request. Languages found in the user's request are added to this object with the append() method (they should be instances of _LanguageRange). After the languages have been added, then the caller can use select_from() to determine which user-request language(s) best matches the set of available languages. Strictly speaking, this class is pretty close for more than just language matching. It has been implemented to enable q-value based matching between requests and availability. Some minor tweaks may be necessary, but simply using a new 'item_class' should be sufficient to allow the _parse() function to construct a selector which holds the appropriate item implementations (e.g. _LanguageRange is the concrete _AcceptItem class that handles matching of language tags). cCs g|_dS(N(sselfs requested(sself((s lib/accept.pys__init__‚scCs}g}x—|D]}d}d}x\|iD]Q}|i|ƒ}|t j ot |i ƒ|jo|}t |i ƒ}q)q)W|o|i ||fƒq q W| o |dSn|i ƒ|d\}}| o |dSnt |ƒdjo|dd|jokx!|dd|jo |d=q WxD|iD]5}x,|D]$\}}|i|ƒo|SqEqEWq8Wn|SdS(sBSelect one of the available choices based on the request. Note: if there isn't a match, then the first available choice is considered the default. Also, if a number of matches are equally relevant, then the first-requested will be used. avail is a list of language-tag strings of available languages if0.0iÿÿÿÿiiþÿÿÿN(smatchessavailstagslongestsfinalsselfs requestedswantsqvaluesNoneslensnamesappendssort(sselfsavailsqvaluesmatchesstagslongestswantsfinal((s lib/accept.pys select_from…s> #   (    cCs|ii|ƒdS(N(sselfs requestedsappendsitem(sselfsitem((s lib/accept.pysappendÒs(s__name__s __module__s__doc__s_LanguageRanges item_classs__init__s select_fromsappend(((s lib/accept.pys_LanguageSelectorns   MsAcceptParseErrorcBstZRS(N(s__name__s __module__(((s lib/accept.pysAcceptParseErrorÕscCstdƒ}|idgƒdjpt‚|iddgƒdjpt‚|iddgƒdjpt‚tdƒ}|iddgƒdjpt‚tdƒ}|idgƒdjpt‚|idgƒdjpt‚|iddgƒdjpt‚|iddgƒdjpt‚|iddgƒdjpt‚|id gƒd jpt‚|id dgƒdjpt‚dS( Nsensdesen, jasjas4fr, de;q=0.9, en-gb;q=0.7, en;q=0.6, en-gb-foo;q=0.8s en-gb-foosfrsen-gbsen-bars en-gb-bar(slanguagesss select_fromsAssertionError(ss((s lib/accept.pys_testØs  ## #   ### (sresstringslanguagescompiles _re_tokens _re_params_re_split_params_parses _AcceptItems_LanguageRanges_LanguageSelectors ExceptionsAcceptParseErrors_test( sstringslanguages_LanguageSelectors_re_split_params _AcceptItems_testsAcceptParseErrorsres_LanguageRanges_parses _re_tokens _re_param((s lib/accept.pys?s    0 g