
    %h/                       S SK Jr  S SKrS SKJr  S SKrS SKrSSK	J
r
   " S S\
\\\4      5      r\R                  " S5      rSS jr " S	 S
\5      r\R                  " S5      rSS jr " S S\5      r " S S\5      rg)    )annotationsN   )ImmutableListc                    ^  \ rS rSrSr S   SU 4S jjjrSS jrSS jr\R                  SS j5       r
\R                  SS j5       r
\R                  SS j5       r
    SS	 jr
SS
 jrS S jrS!S jrS"S jrS"S jrS#S jrS!S jrS!S jrS$S jr\R                  S%S j5       r\R                  S&S'S jj5       r S(     S)S jjr\S*S j5       rSrU =r$ )+Accept   a?  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.

c                   >^  Uc  [         TT ]  5         ST l        g [        U[        5      (       a!  UR                  T l        [         TT ]  U5        g ST l        [        UU 4S jSS9n[         TT ]  U5        g )NFTc                6   > TR                  U S   5      U S   4$ )Nr   r   )_specificity)xselfs    V/var/www/auris/envauris/lib/python3.13/site-packages/werkzeug/datastructures/accept.py<lambda>!Accept.__init__.<locals>.<lambda>;   s    t'8'81'>!&E    )keyreverse)super__init__provided
isinstancer   sorted)r   values	__class__s   ` r   r   Accept.__init__/   si     >G!DM''"OODMGV$ DMEtF GV$r   c                    US:g  4$ )z3Returns a tuple describing the value's specificity.* r   values     r   r   Accept._specificity?   s    r   c                \    US:H  =(       d!    UR                  5       UR                  5       :H  $ )z-Check if a value matches a given accept item.r   )lowerr   r    items      r   _value_matchesAccept._value_matchesC   s"    s{;djjlekkm;;r   c                    g Nr   r   r   s     r   __getitem__Accept.__getitem__G   s    .1r   c                    g r)   r   r*   s     r   r+   r,   I   s    FIr   c                    g r)   r   r*   s     r   r+   r,   K   s    BEr   c                x    [        U[        5      (       a  U R                  U5      $ [        R	                  X5      $ )zBesides 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   strqualitylistr+   r*   s     r   r+   r,   M   s1     c3<<$$**r   c                N    U  H  u  p#U R                  X5      (       d  M  Us  $    g)zReturns 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   r&   )r   r   r%   r1   s       r   r1   Accept.qualityX   s+     "MD""3-- " r   c                J    U  H  u  p#U R                  X5      (       d  M    g   g)NTFr4   )r   r    r%   _qualitys       r   __contains__Accept.__contains__d   s'    "ND""5// # r   c                h    SR                  S U  5       5      n[        U 5      R                   SU S3$ )N, c              3  :   #    U  H  u  pS U< SU S3v   M     g7f)(r;   )Nr   ).0r   ys      r   	<genexpr>"Accept.__repr__.<locals>.<genexpr>k   s      ?$$!!b1o$s   z([z]))jointype__name__)r   	pairs_strs     r   __repr__Accept.__repr__j   s4    II?$??	t*%%&b266r   c                    [        U[        5      (       a<  [        U 5       H"  u  nu  p4U R                  X5      (       d  M   Us  $    [	        U5      e[
        R                  X5      $ )zGet 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.
)r   r0   	enumerater&   
ValueErrorr2   index)r   r   idxr%   r7   s        r   rL   Accept.indexn   sX     c3)24%%d&&s11J *9 S/!zz$$$r   c                F     U R                  U5      $ ! [         a     gf = f)zQGet the position of an entry or return -1.

:param key: The key to be looked up.
)rL   rK   r*   s     r   findAccept.find~   s'    
	::c?" 		s    
  c              #  ,   #    U  H
  nUS   v   M     g7f)zIterate over all values.r   Nr   )r   r%   s     r   r   Accept.values   s     Dq'M s   c                z    / nU  H#  u  p#US:w  a  U SU 3nUR                  U5        M%     SR                  U5      $ )z2Convert the header set into an HTTP header string.r   z;q=,)appendrC   )r   resultr    r1   s       r   	to_headerAccept.to_header   sG    "NE!| 'WI.MM%  # xxr   c                "    U R                  5       $ r)   )rY   r   s    r   __str__Accept.__str__   s    ~~r   c                P    U  H   u  p#U R                  X5      (       d  M  X#4s  $    g r)   r4   )r   matchclient_itemr1   s       r   _best_single_matchAccept._best_single_match   s.    $( K""566"++ %) r   c                    g r)   r   r   matchess     r   
best_matchAccept.best_match       EHr   c                    g r)   r   r   rf   defaults      r   rg   rh          RUr   c                    UnSnSnU HQ  nU R                  U5      nU(       d  M  Uu  pU R                  U5      n
U	S::  d  X:  a  M?  X:  d  X:  d  MK  UnU	nU
nMS     U$ )a.  Returns 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
rP   )rP   r   )rb   r   )r   rf   rl   rX   best_qualitybest_specificityserver_itemr`   ra   r1   specificitys              r   rg   rh      s}      .3"K++K8E#( K++K8K!|w5%)G$&#.  # r   c                "    U (       a  U S   S   $ g)zThe best match as value.r   Nr   r\   s    r   bestAccept.best   s     71:r   )r   )r   )r   z0Accept | cabc.Iterable[tuple[str, float]] | NonereturnNoner    r0   rv   ztuple[bool, ...]r    r0   r%   r0   rv   bool)r   r0   rv   float)r   zt.SupportsIndexrv   ztuple[str, float])r   slicerv   zlist[tuple[str, float]])r   zstr | t.SupportsIndex | slicerv   z3float | tuple[str, float] | list[tuple[str, float]])r    r0   rv   rz   )rv   r0   )r   zstr | tuple[str, float]rv   int)rv   zcabc.Iterator[str])r`   r0   rv   ztuple[str, float] | Nonerf   cabc.Iterable[str]rv   
str | None.rf   r   rl   r0   rv   r0   r)   rf   r   rl   r   rv   r   )rv   r   )rE   
__module____qualname____firstlineno____doc__r   r   r&   toverloadr+   r1   r8   rG   rL   rQ   r   rY   r]   rb   rg   propertyrt   __static_attributes____classcell__r   s   @r   r   r      s   !H JL%F%	% % < ZZ1 1ZZI IZZE E	+0	+	<	+
7% 
   ZZH HZZU UAE)4>	8  r   r   z/|(?:\s*;\s*)c                H    [         R                  U R                  5       5      $ r)   )_mime_split_resplitr#   r    s    r   _normalize_mimer      s    ..r   c                  h    \ rS rSrSrS
S jrSS jr\SS j5       r\SS j5       r	\SS j5       r
Srg	)
MIMEAccept   zJLike :class:`Accept` but with special methods and behavior for
mimetypes.
c                L    [        S [        R                  U5       5       5      $ )Nc              3  *   #    U  H	  oS :g  v   M     g7f)r   Nr   )r?   r   s     r   rA   *MIMEAccept._specificity.<locals>.<genexpr>   s     C'B!#X'Bs   )tupler   r   r   s     r   r   MIMEAccept._specificity   s    C~';';E'BCCCr   c                   SU;  a  gSU;  a  [        SU< 35      e[        U5      nUS S u  pE[        USS  5      nUS:X  a  US:w  a  [        SU< 35      e[        U5      nUS S u  p[        USS  5      n
US:X  a  U	S:w  a  gUS:H  =(       a    U	S:H  =(       d    US:H  =(       a    US:H  =(       d2    X:H  =(       a'    U	S:H  =(       d    US:H  =(       d    X:H  =(       a    X:H  $ )N/Fzinvalid mimetype    r   )rK   r   r   )r   r    r%   normalized_value
value_typevalue_subtypevalue_paramsnormalized_item	item_typeitem_subtypeitem_paramss              r   r&   MIMEAccept._value_matches   s'   d? e0	:;; +51$4Ra$8!
.qr23 #!50	:;; *$/"1"1"5	_QR01  3 #5,#"5 <c!:ms&:

 # # S C'S 1Qk6Q
	
r   c                2    SU ;   =(       d    U R                   $ )z!True if this object accepts HTML.z	text/html)accept_xhtmlr\   s    r   accept_htmlMIMEAccept.accept_html   s     d"7d&7&77r   c                $    SU ;   =(       d    SU ;   $ )z"True if this object accepts XHTML.zapplication/xhtml+xmlzapplication/xmlr   r\   s    r   r   MIMEAccept.accept_xhtml  s     '$.K2Ct2KKr   c                    SU ;   $ )z!True if this object accepts JSON.zapplication/jsonr   r\   s    r   accept_jsonMIMEAccept.accept_json
  s     "T))r   r   Nrx   ry   )rv   rz   )rE   r   r   r   r   r   r&   r   r   r   r   r   r   r   r   r   r      sQ    D&
P 8 8 L L * *r   r   z[_-]c                H    [         R                  U R                  5       5      $ )z$Process a language tag for matching.)_locale_delim_rer   r#   r   s    r   _normalize_langr     s    !!%++-00r   c                     ^  \ rS rSrSrSS jr\R                  S	S j5       r\R                  S
SS jj5       r S     SU 4S jjjrSr	U =r
$ )LanguageAccepti  z>Like :class:`Accept` but with normalization for language tags.c                H    US:H  =(       d    [        U5      [        U5      :H  $ )Nr   )r   r$   s      r   r&   LanguageAccept._value_matches  s     s{Moe48MMMr   c                    g r)   r   re   s     r   rg   LanguageAccept.best_match  ri   r   c                    g r)   r   rk   s      r   rg   r      rm   r   c           	       >^ [         TU ]  U5      mTb  T$ [        U  Vs/ s H$  n[        R	                  US   S5      S   US   4PM&     sn5      nUR                  U5      mTb  T$ U Vs/ s H  n[        R	                  US5      S   PM     nn[         TU ]  U5      mTb  [        U4S jU 5       5      $ U$ s  snf s  snf )aH  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.
r   r   c              3  V   >#    U  H  oR                  T5      (       d  M  Uv   M      g 7fr)   )
startswith)r?   r%   rX   s     r   rA   ,LanguageAccept.best_match.<locals>.<genexpr>O  s     LOOF4Ks   )	))r   rg   r   r   r   next)r   rf   rl   r%   fallbackfallback_matchesrX   r   s         @r   rg   r   "  s    * #G,M
 JNO$$$$T!Wa03T!W=$O
 $$W-M LSS74,224;A>7S#$45 LLLL# P Ts   +B:,#B?r   ry   r~   r   r   r)   r   )rE   r   r   r   r   r&   r   r   rg   r   r   r   s   @r   r   r     sW    HN ZZH HZZU UAE/)/4>/	/ /r   r   c                  "    \ rS rSrSrSS jrSrg)CharsetAcceptiT  z9Like :class:`Accept` but with normalization for charsets.c                F    SS jnUS:H  =(       d    U" U5      U" U5      :H  $ )Nc                     [         R                  " U 5      R                  $ ! [         a    U R	                  5       s $ f = fr)   )codecslookupnameLookupErrorr#   )r   s    r   
_normalize0CharsetAccept._value_matches.<locals>._normalizeX  s7    $}}T*/// $zz|#$s   " ??r   )r   r0   rv   r0   r   )r   r    r%   r   s       r   r&   CharsetAccept._value_matchesW  s'    	$ s{Cj/:d3CCCr   r   Nry   )rE   r   r   r   r   r&   r   r   r   r   r   r   T  s    CDr   r   )r    r0   rv   z	list[str])
__future__r   r   collections.abcabccabcretypingr   
structuresr   r   r0   r{   r   compiler   r   r   r   r   r   r   r   r   r   <module>r      s    "   	  %{]5e,- {| ,-/=* =*@ ::g& 1
9V 9x
DF 
Dr   