Files
aitsc/.venv/Lib/site-packages/werkzeug/datastructures/__pycache__/accept.cpython-312.pyc

125 lines
16 KiB
Plaintext
Raw Normal View History

2025-02-23 09:07:52 +08:00
<EFBFBD>
2025-08-17 18:52:05 +08:00
-<2D><>h<EFBFBD>0<00><01><00>ddlmZddlZddlmZddlZddlZddl m
2025-02-23 09:07:52 +08:00
Z
Gd<05>de
e e e f<00>Zejd<07>Zdd<08>ZGd <09>d
e<0E>Zejd <0B>Zdd <0C>ZGd <0A>de<0E>ZGd<0F>de<0E>Zy)<12>)<01> annotationsN<73>)<01> ImmutableListc<01>~<00><00>eZdZdZ d d<17>fd<02> Zdd<03>Zdd<04>Zejdd<05><04>Z ejdd<06><04>Z ejdd<07><04>Z dd<08>Z dd <09>Z
dd
<EFBFBD>Z dd <0B>Z d d <0C>Z d d <0A>Zd!d<0E>Zdd<0F>Zdd<10>Zd"d<11>Zejd#d<12><04>Zejd$d%d<13><05>Z d& d'd<14>Zed(d<15><04>Z<15>xZS))<29>Accepta<74>An :class:`Accept` object is just a list subclass for lists of
``(value, quality)`` tuples. It is automatically sorted by specificity
and quality.
All :class:`Accept` objects work similar to a list but provide extra
functionality for working with the data. Containment checks are
normalized to the rules of that header:
>>> a = CharsetAccept([('ISO-8859-1', 1), ('utf-8', 0.7)])
>>> a.best
'ISO-8859-1'
>>> 'iso-8859-1' in a
True
>>> 'UTF8' in a
True
>>> 'utf7' in a
False
To get the quality for an item you can use normal item lookup:
>>> print a['utf-8']
0.7
>>> a['utf7']
0
.. versionchanged:: 0.5
:class:`Accept` objects are forced immutable now.
.. versionchanged:: 1.0.0
:class:`Accept` internal values are no longer ordered
alphabetically for equal quality tags. Instead the initial
order is preserved.
2025-08-16 19:28:45 +08:00
c<01><><00><01><00>|<01>t<00><02><00><00>d<01>_yt|t<00>r!|j<00>_t<00><02><00>|<01>yd<02>_t |<01>fd<03>d<02><04>}t<00><02><00>|<01>y)NFTc<01>6<00><01><00>j|d<00>|dfS)Nrr)<01> _specificity)<02>x<>selfs <20><>BD:\aitsc\.venv\Lib\site-packages\werkzeug\datastructures\accept.py<70><lambda>z!Accept.__init__.<locals>.<lambda>;s<00><><00>t<EFBFBD>'8<>'8<><11>1<EFBFBD><14>'><3E><01>!<21><04>&E<>)<02>key<65>reverse)<06>super<65>__init__<5F>provided<65>
2025-02-23 09:07:52 +08:00
isinstancer<00>sorted)r <00>values<65> __class__s` <20>r rzAccept.__init__/sf<00><><00> <12>><3E> <11>G<EFBFBD> <1C> <1E>!<21>D<EFBFBD>M<EFBFBD> <17><06><06> '<27>"<22>O<EFBFBD>O<EFBFBD>D<EFBFBD>M<EFBFBD> <11>G<EFBFBD> <1C>V<EFBFBD> $<24> <20>D<EFBFBD>M<EFBFBD><1B><16>E<>t<EFBFBD><0E>F<EFBFBD> <12>G<EFBFBD> <1C>V<EFBFBD> $rc<01><00>|dk7fS)z3Returns a tuple describing the value's specificity.<2E>*<2A><00>r <00>values r r
zAccept._specificity?s<00><00><15><13> <0C><EFBFBD>rc<01>R<00>|dk(xs!|j<00>|j<00>k(S)z-Check if a value matches a given accept item.r)<01>lower<65>r r<00>items r <00>_value_matcheszAccept._value_matchesCs"<00><00><13>s<EFBFBD>{<7B>;<3B>d<EFBFBD>j<EFBFBD>j<EFBFBD>l<EFBFBD>e<EFBFBD>k<EFBFBD>k<EFBFBD>m<EFBFBD>;<3B>;rc<01><00>y<00>Nr<00>r rs r <00> __getitem__zAccept.__getitem__Gs<00><00>.1rc<01><00>yr$rr%s r r&zAccept.__getitem__Is<00><00>FIrc<01><00>yr$rr%s r r&zAccept.__getitem__Ks<00><00>BErc<01>p<00>t|t<00>r|j|<01>Stj ||<01>S)z<>Besides index lookup (getting item n) you can also pass it a string
to get the quality for the item. If the item is not in the list, the
returned quality is ``0``.
)r<00>str<74>quality<74>listr&r%s r r&zAccept.__getitem__Ms0<00><00> <16>c<EFBFBD>3<EFBFBD> <1F><17><<3C><<3C><03>$<24> $<24><13><1F><1F><04>c<EFBFBD>*<2A>*rc<01>D<00>|D]\}}|j||<02>s<01>|cSy)z<>Returns the quality of the key.
.. versionadded:: 0.6
In previous versions you had to use the item-lookup syntax
(eg: ``obj[key]`` instead of ``obj.quality(key)``)
r<00>r")r rr!r+s r r+zAccept.qualityXs,<00><00>"<22>M<EFBFBD>D<EFBFBD>'<27><13>"<22>"<22>3<EFBFBD><04>-<2D><1E><0E>"<22>rc<01>@<00>|D]\}}|j||<02>s<01>yy)NTFr.)r rr!<00>_qualitys r <00> __contains__zAccept.__contains__ds(<00><00>"<22>N<EFBFBD>D<EFBFBD>(<28><13>"<22>"<22>5<EFBFBD>$<24>/<2F><1B>#<23>rc<01>h<00>djd<02>|D<00><00>}t|<00>j<00>d|<01>d<04>S)N<>, c3<01>4K<00>|]\}}d|<01>d|<02>d<02><05><01><00>y<03>w)<04>(r3<00>)Nr)<03>.0r <00>ys r <00> <genexpr>z"Accept.__repr__.<locals>.<genexpr>ks#<00><00><><00>?<3F>$<24>$<24>!<21>Q<EFBFBD><01>!<21><15>b<EFBFBD><11><03>1<EFBFBD>o<EFBFBD>$<24>s<00>z([z]))<03>join<69>type<70>__name__)r <00> pairs_strs r <00>__repr__zAccept.__repr__js4<00><00><18>I<EFBFBD>I<EFBFBD>?<3F>$<24>?<3F>?<3F> <09><16>t<EFBFBD>*<2A>%<25>%<25>&<26>b<EFBFBD><19> <0B>2<EFBFBD>6<>6rc<01><><00>t|t<00>r7t|<00>D]\}\}}|j||<03>s<01>|cSt |<01><00>t
j ||<01>S)z<>Get the position of an entry or raise :exc:`ValueError`.
:param key: The key to be looked up.
.. versionchanged:: 0.5
This used to raise :exc:`IndexError`, which was inconsistent
with the list API.
)rr*<00> enumerater"<00>
ValueErrorr,<00>index)r r<00>idxr!r0s r rBz Accept.indexnsX<00><00> <16>c<EFBFBD>3<EFBFBD> <1F>)2<>4<EFBFBD><1F>%<25><03>%<25>d<EFBFBD>H<EFBFBD><17>&<26>&<26>s<EFBFBD>D<EFBFBD>1<><1E>J<EFBFBD>*9<><1D>S<EFBFBD>/<2F> !<21><13>z<EFBFBD>z<EFBFBD>$<24><03>$<24>$rc<01>D<00> |j|<01>S#t$rYywxYw)zaGet the position of an entry or return -1.
:param key: The key to be looked up.
<20><><EFBFBD><EFBFBD><EFBFBD>)rBrAr%s r <00>findz Accept.find~s'<00><00>
 <16><17>:<3A>:<3A>c<EFBFBD>?<3F> "<22><><19> <16><15> <16>s <00><00> <03>c#<01>(K<00>|D] }|d<00><01><00> y<02>w)zIterate over all values.rNr)r r!s r rz Accept.values<65>s<00><00><><00><18>D<EFBFBD><16>q<EFBFBD>'<27>M<EFBFBD><19>s<00>c<01>v<00>g}|D]"\}}|dk7r|<02>d|<03><00>}|j|<02><00>$dj|<01>S)z2Convert the header set into an HTTP header string.rz;q=<3D>,)<02>appendr:)r <00>resultrr+s r <00> to_headerzAccept.to_header<65>sI<00><00><13><06>"<22>N<EFBFBD>E<EFBFBD>7<EFBFBD><16>!<21>|<7C> <20>'<27><13>W<EFBFBD>I<EFBFBD>.<2E><05> <12>M<EFBFBD>M<EFBFBD>%<25> <20>#<23><13>x<EFBFBD>x<EFBFBD><06><1F>rc<01>"<00>|j<00>Sr$)rL<00>r s r <00>__str__zAccept.__str__<5F>s<00><00><13>~<7E>~<7E><1F>rc<01>H<00>|D]\}}|j||<02>s<01>||fcSyr$r.)r <00>match<63> client_itemr+s r <00>_best_single_matchzAccept._best_single_match<63>s1<00><00>$(<28> <20>K<EFBFBD><17><13>"<22>"<22>5<EFBFBD>+<2B>6<>"<22>G<EFBFBD>+<2B>+<2B>%)<29>rc<01><00>yr$r<00>r <00>matchess r <00>
best_matchzAccept.best_match<63><00><00><00>EHrc<01><00>yr$r<00>r rV<00>defaults r rWzAccept.best_match<63><00><00><00>RUrc<01><><00>|}d}d}|D]H}|j|<06>}|s<01>|\}} |j|<08>}
| dks| |kr<01>8| |kDs|
|kDs<01>C|}| }|
}<05>J|S)aVReturns the best match from a list of possible matches based
on the specificity and quality of the client. If two items have the
same quality and specificity, the one is returned that comes first.
:param matches: a list of matches to check for
:param default: the value that is returned if none match
rE)rEr)rSr
) r rVr[rK<00> best_quality<74>best_specificity<74> server_itemrQrRr+<00> specificitys r rWzAccept.best_match<63>s<><00><00><19><06> <20> <0C>.3<EFBFBD><18>"<22>K<EFBFBD><18>+<2B>+<2B>K<EFBFBD>8<>E<EFBFBD><18><18>#(<28> <20>K<EFBFBD><17><1E>+<2B>+<2B>K<EFBFBD>8<>K<EFBFBD><16>!<21>|<7C>w<EFBFBD><1C>5<><18><16><1C>%<25><1B>7G<37>)G<>$<24><06>&<26> <0C>#.<2E> <20>#<23><16> rc<01><00>|r|ddSy)zThe best match as value.rNrrNs r <00>bestz Accept.best<73>s<00><00> <10><17><01>7<EFBFBD>1<EFBFBD>:<3A> <1D>r)r)rz0Accept | cabc.Iterable[tuple[str, float]] | None<6E>return<72>None<6E>rr*rdztuple[bool, ...]<5D>rr*r!r*rd<00>bool)rr*rd<00>float)rzt.SupportsIndexrdztuple[str, float])r<00>slicerdzlist[tuple[str, float]])rzstr | t.SupportsIndex | slicerdz3float | tuple[str, float] | list[tuple[str, float]])rr*rdrh)rdr*)rzstr | tuple[str, float]rd<00>int)rdzcabc.Iterator[str])rQr*rdztuple[str, float] | None<6E>rV<00>cabc.Iterable[str]rd<00>
str | None<6E>.<2E>rVrmr[r*rdr*r$<00>rVrmr[rnrdrn)rdrn)r<<00>
__module__<EFBFBD> __qualname__<5F>__doc__rr
r"<00>t<>overloadr&r+r1r>rBrFrrLrOrSrW<00>propertyrc<00> __classcell__<5F>rs@r rr s<00><><00>!<08>HJL<01>%<25>F<>%<25> <0A>%<25> <1F><<3C><07>Z<EFBFBD>Z<EFBFBD>1<><10>1<><06>Z<EFBFBD>Z<EFBFBD>I<><10>I<><06>Z<EFBFBD>Z<EFBFBD>E<><10>E<> +<2B>0<> +<2B> <<3C> +<2B>
<11><15> 7<>%<25> <16><1A>
 <20> <20><14><07>Z<EFBFBD>Z<EFBFBD>H<><10>H<><06>Z<EFBFBD>Z<EFBFBD>U<><10>U<>AE<41><16>)<29><16>4><3E><16> <13><16>8<0E><14><0E>rrz /|(?:\s*;\s*)c<01>H<00>tj|j<00><00>Sr$)<03>_mime_split_re<72>splitr<00>rs r <00>_normalize_mimer~<00>s<00><00> <19> <1F> <1F><05> <0B> <0B> <0A> .<2E>.rc<01>V<00>eZdZdZdd<02>Zd d<03>Zed
d<04><04>Zed
d<05><04>Zed
d<06><04>Z y) <0B>
MIMEAcceptzRLike :class:`Accept` but with special methods and behavior for
mimetypes.
c<01>L<00>td<01>tj|<01>D<00><00>S)Nc3<01>&K<00>|] }|dk7<00><01><00> y<01>w)rNr)r7r s r r9z*MIMEAccept._specificity.<locals>.<genexpr><3E>s<00><00><><00>C<>'B<>!<21>Q<EFBFBD>#<23>X<EFBFBD>'B<>s<00>)<03>tupler{r|rs r r
zMIMEAccept._specificity<74>s<00><00><14>C<>~<7E>';<3B>';<3B>E<EFBFBD>'B<>C<>C<>Crc<01>t<00>d|vryd|vrtd|<01><02><02><00>t|<01>}|dd\}}t|dd<00>}|dk(r|dk7rtd|<01><02><02><00>t|<02>}|dd\}} t|dd<00>}
|dk(r| dk7ry|dk(xr| dk(xs |dk(xr|dk(xs!||k(xr| dk(xs|dk(xs | |k(xr|
|k(S)N<>/Fzinvalid mimetype <20>r)rAr~r) r rr!<00>normalized_value<75>
value_type<EFBFBD> value_subtype<70> value_params<6D>normalized_item<65> item_type<70> item_subtype<70> item_paramss r r"zMIMEAccept._value_matches<65>s1<00><00> <0E>d<EFBFBD>?<3F><18> <0F>e<EFBFBD> <1B><1C>0<><15> <09>:<3A>;<3B> ;<3B>+<2B>5<EFBFBD>1<><18>$4<>R<EFBFBD>a<EFBFBD>$8<>!<21>
<EFBFBD>M<EFBFBD><1D>.<2E>q<EFBFBD>r<EFBFBD>2<>3<> <0C> <16><13> <1C><1D>#<23>!5<><1C>0<><15> <09>:<3A>;<3B> ;<3B>*<2A>$<24>/<2F><0F>"1<>"<22>1<EFBFBD>"5<><1F> <09><<3C><1C>_<EFBFBD>Q<EFBFBD>R<EFBFBD>0<>1<> <0B> <15><03> <1B> <0C><03> 3<><18><17>#<23> <1D> 5<>,<2C>#<23>"5<> <<3C><1A>c<EFBFBD>!<21>:<3A>m<EFBFBD>s<EFBFBD>&:<3A>

<EFBFBD> <16><1A> #<23> <0E><1C><03>#<23>S<01> <20>C<EFBFBD>'<27>S<01> <20>M<EFBFBD>1<>Q<>k<EFBFBD>\<5C>6Q<36>
rc<01>&<00>d|vxs |jS)z!True if this object accepts HTML.z text/html)<01> accept_xhtmlrNs r <00> accept_htmlzMIMEAccept.accept_htmls<00><00><1B>d<EFBFBD>"<22>7<>d<EFBFBD>&7<>&7<>7rc<01><00>d|vxsd|vS)z"True if this object accepts XHTML.zapplication/xhtml+xmlzapplication/xmlrrNs r r<>zMIMEAccept.accept_xhtmls<00><00>'<27>$<24>.<2E>K<>2C<32>t<EFBFBD>2K<32>Krc<01>
<00>d|vS)z!True if this object accepts JSON.zapplication/jsonrrNs r <00> accept_jsonzMIMEAccept.accept_json
s<00><00>"<22>T<EFBFBD>)<29>)rNrfrg)rdrh)
r<rrrsrtr
r"rwr<>r<>r<>rrr r<>r<><00>sQ<00><00><08>D<01>&
<EFBFBD>P<0E>8<><0E>8<><0E>L<01><0E>L<01><0E>*<2A><0E>*rr<>z[_-]c<01>H<00>tj|j<00><00>S)z$Process a language tag for matching.)<03>_locale_delim_rer|rr}s r <00>_normalize_langr<67>s<00><00> <1B> !<21> !<21>%<25>+<2B>+<2B>-<2D> 0<>0rc<01><><00><00>eZdZdZdd<02>Zej dd<03><04>Zej dd d<04><05>Z d
d <0B>fd<05> Z<07>xZS) <0C>LanguageAcceptz>Like :class:`Accept` but with normalization for language tags.c<01>><00>|dk(xst|<01>t|<02>k(S)Nr)r<>r s r r"zLanguageAccept._value_matchess <00><00><13>s<EFBFBD>{<7B>M<>o<EFBFBD>e<EFBFBD>4<><0F><04>8M<38>M<>Mrc<01><00>yr$rrUs r rWzLanguageAccept.best_matchrXrc<01><00>yr$rrZs r rWzLanguageAccept.best_match r\rc <01>t<00><01><06>t<00>|<00>|<01><00><06><06><02>St|D<00>cgc]#}tj |dd<02>d|df<02><02>%c}<03>}|j|<01><00><06><06><02>S|D<00>cgc]}tj |d<02>d<00><02>}}t<00>|<00>|<05><00><06><06>t <00>fd<03>|D<00><00>S|Scc}wcc}w)a<>Given a list of supported values, finds the best match from
the list of accepted values.
Language tags are normalized for the purpose of matching, but
are returned unchanged.
If no exact match is found, this will fall back to matching
the first subtag (primary language only), first with the
accepted values then with the match values. This partial is not
applied to any other language subtags.
The default is returned if no exact or fallback match is found.
:param matches: A list of supported languages to find a match.
:param default: The value that is returned if none match.
rrc3<01>F<00>K<00>|]}|j<00><02>s<01>|<01><01><00>y<00>wr$)<01>
startswith)r7r!rKs <20>r r9z,LanguageAccept.best_match.<locals>.<genexpr>Os<00><><00><><00>L<><17><14>D<EFBFBD>O<EFBFBD>O<EFBFBD>F<EFBFBD>4K<34><04><17>s<00>!<01>!)rrWrr<>r|<00>next)r rVr[r!<00>fallback<63>fallback_matchesrKrs @<40>r rWzLanguageAccept.best_match"s<><00><><00>*<17><17>#<23>G<EFBFBD>,<2C><06> <11> <1D><19>M<EFBFBD>
<1A>JN<4A> O<>$<24>$<24><1E>$<24>$<24>T<EFBFBD>!<21>W<EFBFBD>a<EFBFBD>0<><11>3<>T<EFBFBD>!<21>W<EFBFBD> =<3D>$<24> O<>
<EFBFBD><08><1A>$<24>$<24>W<EFBFBD>-<2D><06> <11> <1D><19>M<EFBFBD>LS<01>S<>7<EFBFBD>4<EFBFBD>,<2C>2<>2<>4<EFBFBD><11>;<3B>A<EFBFBD>><3E>7<EFBFBD><18>S<><16><17>#<23>$4<>5<><06> <12> <1D><17>L<><17>L<>L<> L<><16><0E><># P<01><>Ts <00>(B0<08>' B5rgrlrorpr$rq) r<rrrsrtr"rurvrWrxrys@r r<>r<>sW<00><><00>H<>N<01><07>Z<EFBFBD>Z<EFBFBD>H<><10>H<><06>Z<EFBFBD>Z<EFBFBD>U<><10>U<>AE<41>/<17>)<29>/<17>4><3E>/<17> <13>/<17>/rr<>c<01><00>eZdZdZdd<02>Zy)<05> CharsetAcceptz9Like :class:`Accept` but with normalization for charsets.c<01>:<00>dd<01>}|dk(xs||<01>||<02>k(S)Nc<01><><00> tj|<00>jS#t$r|j <00>cYSwxYwr$)<05>codecs<63>lookup<75>name<6D> LookupErrorr)r<>s r <00>
_normalizez0CharsetAccept._value_matches.<locals>._normalizeXs7<00><00> $<24><1D>}<7D>}<7D>T<EFBFBD>*<2A>/<2F>/<2F>/<2F><><1E> $<24><1B>z<EFBFBD>z<EFBFBD>|<7C>#<23> $<24>s <00>!<00>=<03>=r)r<>r*rdr*r)r rr!r<>s r r"zCharsetAccept._value_matchesWs'<00><00> $<24> <14>s<EFBFBD>{<7B>C<>j<EFBFBD><15>/<2F>:<3A>d<EFBFBD>3C<33>C<>CrNrg)r<rrrsrtr"rrr r<>r<>Ts <00><00>C<>Drr<>)rr*rdz list[str])<17>
__future__rr<><00>collections.abc<62>abc<62>cabc<62>re<72>typingru<00>
structuresrr<>r*rir<00>compiler{r~r<>r<>r<>r<>r<>rrr <00><module>r<>s<><00><01>"<22> <0A><1E> <09><12>%<25>{<14>]<5D>5<EFBFBD><13>e<EFBFBD><1A>,<2C> -<2D>{<14>|<1C><12><1A><1A>,<2C>-<2D><0E>/<2F>=*<2A><16>=*<2A>@<1E>2<EFBFBD>:<3A>:<3A>g<EFBFBD>&<26><10>1<>
9<17>V<EFBFBD>9<17>x
D<01>F<EFBFBD>
Dr