
    
JhC                    6   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 ej                  rd dlmZ d dlmZ  G d d	e      Zd
dgZ ej                   d      Z ej                   d      Z ej                   d      Zej(                  dej*                  eef   ej.                  eeef      d	f   Z G d de      Z	 	 	 	 ddZ G d d
ej8                  eef   ej:                  eef         Z G d deeeef            Z  G d dej:                  eef         Z!y)    )annotationsN)OrderedDict)Enumauto)RLock)Protocol)Selfc                      e Zd ZddZddZy)HasGettableStringKeysc                     y N selfs    H/var/www/test/myenv/lib/python3.12/site-packages/urllib3/_collections.pykeyszHasGettableStringKeys.keys           c                     y r   r   r   keys     r   __getitem__z!HasGettableStringKeys.__getitem__   r   r   Nreturnztyping.Iterator[str]r   strr   r   )__name__
__module____qualname__r   r   r   r   r   r   r      s    33r   r   RecentlyUsedContainerHTTPHeaderDict_KT_VT_DTc                      e Zd Z e       Zy)	_SentinelN)r   r   r   r   
not_passedr   r   r   r&   r&   '   s	    Jr   r&   c                   t        | t              r| S t        | t        j                        r1t        j                  t        j                  t
        t
        f   |       S t        | t        j                        r8t        j                  t        j                  t        t
        t
        f      |       S t        | d      r"t        | d      rt        j                  d|       S y )Nr   r   r   )	
isinstancer!   typingMappingcastr   Iterabletuplehasattr)	potentials    r   %ensure_can_construct_http_header_dictr1   +   s     )^,	Iv~~	. {{6>>#s(3Y??	Iv	/ {{6??5c?;YGG	F	#	=(I{{2I>>r   c                       e Zd ZU dZded<   ded<   ded<   ded	<   	 	 d	 	 	 	 	 d fd
ZddZddZddZddZ	ddZ
ddZddZ xZS )r    a  
    Provides a thread-safe dict-like container which maintains up to
    ``maxsize`` keys while throwing away the least-recently-used keys beyond
    ``maxsize``.

    :param maxsize:
        Maximum number of recent elements to retain.

    :param dispose_func:
        Every time an item is evicted from the container,
        ``dispose_func(value)`` is called.  Callback which will get called
    ztyping.OrderedDict[_KT, _VT]
_containerint_maxsize#typing.Callable[[_VT], None] | Nonedispose_funcr   lockc                z    t         |           || _        || _        t	               | _        t               | _        y r   )super__init__r5   r7   r   r3   r   r8   )r   maxsizer7   	__class__s      r   r;   zRecentlyUsedContainer.__init__R   s1    
 	(%-G	r   c                    | j                   5  | j                  j                  |      }|| j                  |<   |cd d d        S # 1 sw Y   y xY wr   )r8   r3   pop)r   r   items      r   r   z!RecentlyUsedContainer.__getitem__]   sC    YY 	??&&s+D#'DOOC 	 	 	s   ,AAc                   d }| j                   5  	 || j                  j                  |      f}|| j                  |<   d d d        |$| j                  r|\  }}| j                  |       y y y # t        $ rP || j                  |<   t	        | j                        | j
                  kD  r| j                  j                  d      }Y w xY w# 1 sw Y   xY w)NF)last)r8   r3   r?   KeyErrorlenr5   popitemr7   )r   r   valueevicted_item_evicted_values         r   __setitem__z!RecentlyUsedContainer.__setitem__d   s    YY 	GG  #DOO$7$7$<<',$	G& #(9(9+A}m, ):#  G (-$t'$--7 $(??#:#:#:#FLG	G 	Gs)   C,A,,ACCCCCc                    | j                   5  | j                  j                  |      }d d d        | j                  r| j                         y y # 1 sw Y   (xY wr   )r8   r3   r?   r7   )r   r   rF   s      r   __delitem__z!RecentlyUsedContainer.__delitem__}   sP    YY 	-OO'',E	- e$ 	- 	-s   AAc                p    | j                   5  t        | j                        cd d d        S # 1 sw Y   y xY wr   )r8   rD   r3   r   s    r   __len__zRecentlyUsedContainer.__len__   s*    YY 	(t'	( 	( 	(s   ,5c                    t        d      )Nz7Iteration over this class is unlikely to be threadsafe.)NotImplementedErrorr   s    r   __iter__zRecentlyUsedContainer.__iter__   s    !E
 	
r   c                
   | j                   5  t        | j                  j                               }| j                  j	                          d d d        | j
                  rD ]  }| j                  |        y y # 1 sw Y   /xY wr   )r8   listr3   valuesclearr7   )r   rT   rF   s      r   rU   zRecentlyUsedContainer.clear   sr    YY 	$$//0023FOO!!#	$
  )!!%() 	$ 	$s   >A99Bc                    | j                   5  t        | j                  j                               cd d d        S # 1 sw Y   y xY wr   )r8   setr3   r   r   s    r   r   zRecentlyUsedContainer.keys   s3    YY 	/t++-.	/ 	/ 	/s	   #:A)
   N)r<   r4   r7   r6   r   None)r   r"   r   r#   )r   r"   rF   r#   r   rY   )r   r"   r   rY   r   r4   )r   ztyping.NoReturn)r   rY   )r   zset[_KT])r   r   r   __doc____annotations__r;   r   rJ   rL   rN   rQ   rU   r   __classcell__r=   s   @r   r    r    ?   sl     -,M55
K <@		 :	 
		-2%(

)/r   c                  <    e Zd ZU dZded<   d	dZd
dZddZddZy)HTTPHeaderDictItemViewa  
    HTTPHeaderDict is unusual for a Mapping[str, str] in that it has two modes of
    address.

    If we directly try to get an item with a particular name, we will get a string
    back that is the concatenated version of all the values:

    >>> d['X-Header-Name']
    'Value1, Value2, Value3'

    However, if we iterate over an HTTPHeaderDict's items, we will optionally combine
    these values based on whether combine=True was called when building up the dictionary

    >>> d = HTTPHeaderDict({"A": "1", "B": "foo"})
    >>> d.add("A", "2", combine=True)
    >>> d.add("B", "bar")
    >>> list(d.items())
    [
        ('A', '1, 2'),
        ('B', 'foo'),
        ('B', 'bar'),
    ]

    This class conforms to the interface required by the MutableMapping ABC while
    also giving us the nonstandard iteration behavior we want; items with duplicate
    keys, ordered by time of first insertion.
    r!   _headersc                    || _         y r   )ra   )r   headerss     r   r;   zHTTPHeaderDictItemView.__init__   s	    r   c                Z    t        t        | j                  j                                     S r   )rD   rS   ra   	iteritemsr   s    r   rN   zHTTPHeaderDictItemView.__len__   s    4//1233r   c                6    | j                   j                         S r   )ra   re   r   s    r   rQ   zHTTPHeaderDictItemView.__iter__   s    }}&&((r   c                    t        |t              rOt        |      dk(  rA|\  }}t        |t              r,t        |t              r| j                  j                  ||      S y)N   F)r)   r.   rD   r   ra   _has_value_for_header)r   r@   
passed_key
passed_vals       r   __contains__z#HTTPHeaderDictItemView.__contains__   sM    dE"s4yA~%)"J
*c*z*c/J}}:::zRRr   N)rc   r!   r   rY   rZ   r   z typing.Iterator[tuple[str, str]])r@   objectr   bool)	r   r   r   r[   r\   r;   rN   rQ   rl   r   r   r   r`   r`      s#    8  4)r   r`   c                  |    e Zd ZU dZded<   d!d" fdZd#dZd$dZd%dZd&dZ	d'd( fd	Z
d)d
Zd)dZd*dZd+dZd%dZddd,dZd-dZej&                  d.d       Zej&                  d/d       Zej,                  f	 	 	 	 	 d0dZd1dZeZeZeZeZd2dZd3dZd1dZd4dZd4dZ d5dZ!d6dZ"d7dZ#d8dZ$d8d Z% xZ&S )9r!   ap  
    :param headers:
        An iterable of field-value pairs. Must not contain multiple field names
        when compared case-insensitively.

    :param kwargs:
        Additional field-value pairs to pass in to ``dict.update``.

    A ``dict`` like container for storing HTTP Headers.

    Field names are stored and compared case-insensitively in compliance with
    RFC 7230. Iteration provides the first case-sensitive key seen for each
    case-insensitive pair.

    Using ``__setitem__`` syntax overwrites fields that compare equal
    case-insensitively in order to maintain ``dict``'s api. For fields that
    compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add``
    in a loop.

    If multiple fields that are equal case-insensitively are passed to the
    constructor or ``.update``, the behavior is undefined and some will be
    lost.

    >>> headers = HTTPHeaderDict()
    >>> headers.add('Set-Cookie', 'foo=bar')
    >>> headers.add('set-cookie', 'baz=quxx')
    >>> headers['content-length'] = '7'
    >>> headers['SET-cookie']
    'foo=bar, baz=quxx'
    >>> headers['Content-Length']
    '7'
    z%typing.MutableMapping[str, list[str]]r3   c                    t         |           i | _        |3t        |t              r| j                  |       n| j                  |       |r| j                  |       y y r   )r:   r;   r3   r)   r!   
_copy_fromextend)r   rc   kwargsr=   s      r   r;   zHTTPHeaderDict.__init__   sQ    '>2(G$KK r   c                    t        |t              r|j                  d      }||g| j                  |j	                         <   y )Nlatin-1)r)   bytesdecoder3   lowerr   r   vals      r   rJ   zHTTPHeaderDict.__setitem__   s2    c5!**Y'C(+Sz		$r   c                d    | j                   |j                            }dj                  |dd        S )N,    r3   ry   joinrz   s      r   r   zHTTPHeaderDict.__getitem__  s+    oociik*yyQR!!r   c                :    | j                   |j                         = y r   r3   ry   r   s     r   rL   zHTTPHeaderDict.__delitem__  s    OOCIIK(r   c                \    t        |t              r|j                         | j                  v S yNF)r)   r   ry   r3   r   s     r   rl   zHTTPHeaderDict.__contains__  s$    c399;$//11r   c                $    t         |   ||      S r   )r:   
setdefault)r   r   defaultr=   s      r   r   zHTTPHeaderDict.setdefault  s    w!#w//r   c                "   t        |      }|y t        |       |      }| j                         D ci c]  \  }}|j                         | c}}|j                         D ci c]  \  }}|j                         | c}}k(  S c c}}w c c}}w r   )r1   type
itermergedry   )r   othermaybe_constructableother_as_http_header_dictkvs         r   __eq__zHTTPHeaderDict.__eq__  s    CEJ&(2T
3F(G%)-):;A	1;%>%I%I%K@
!QAGGIqL@
 
 	
; @
s   B$Bc                &    | j                  |       S r   )r   )r   r   s     r   __ne__zHTTPHeaderDict.__ne__  s    ;;u%%%r   c                ,    t        | j                        S r   )rD   r3   r   s    r   rN   zHTTPHeaderDict.__len__  s    4??##r   c              #  X   K   | j                   j                         D ]	  }|d     y w)Nr   )r3   rT   )r   valss     r   rQ   zHTTPHeaderDict.__iter__!  s+     OO**, 	Dq'M	s   (*c                *    	 | |= y # t         $ r Y y w xY wr   )rC   r   s     r   discardzHTTPHeaderDict.discard&  s     	S	 		s    	F)combinec                  t        |t              r|j                  d      }|j                         }||g}| j                  j                  ||      }||ur3t        |      dk\  sJ |r|d   dz   |z   |d<   y|j                  |       yy)a  Adds a (name, value) pair, doesn't overwrite the value if it already
        exists.

        If this is called with combine=True, instead of adding a new header value
        as a distinct item during iteration, this will instead append the value to
        any existing header value with a comma. If no existing header value exists
        for the key, then the value will simply be added, ignoring the combine parameter.

        >>> headers = HTTPHeaderDict(foo='bar')
        >>> headers.add('Foo', 'baz')
        >>> headers['foo']
        'bar, baz'
        >>> list(headers.items())
        [('foo', 'bar'), ('foo', 'baz')]
        >>> headers.add('foo', 'quz', combine=True)
        >>> list(headers.items())
        [('foo', 'bar, baz, quz')]
        rv   rh   r}   N)r)   rw   rx   ry   r3   r   rD   append)r   r   r{   r   	key_lowernew_valsr   s          r   addzHTTPHeaderDict.add,  s    ( c5!**Y'CIIK	:)))X>4 t9>!>8d?S0RC   r   c                0   t        |      dkD  rt        dt        |       d      t        |      dk\  r|d   nd}t        |t              r+|j	                         D ]  \  }}| j                  ||        nt        |t        j                        r+|j                         D ]  \  }}| j                  ||        nt        |t        j                        rUt        j                  t        j                  t        t        t        f      |      }|D ]  \  }}| j                  ||        nBt        |d      r6t        |d      r*|j                         D ]  }| j                  |||           |j                         D ]  \  }}| j                  ||        y)	zGeneric import function for any type of header-like object.
        Adapted version of MutableMapping.update in order to insert items
        with self.add instead of self.__setitem__
        r~   z/extend() takes at most 1 positional arguments (z given)r   r   r   r   N)rD   	TypeErrorr)   r!   re   r   r*   r+   itemsr-   r,   r.   r   r/   r   )r   argsrt   r   r   r{   rF   s          r   rs   zHTTPHeaderDict.extendO  s_   
 t9q=A#d)GT  t9>Qre^,!OO- #Sc"#v~~.!KKM #Sc"#v/KKc3h @%HE# %
Ue$%UF#}(E zz| *eCj)* !,,. 	!JCHHS% 	!r   c                     y r   r   r   s     r   getlistzHTTPHeaderDict.getlistp  s    .1r   c                     y r   r   )r   r   r   s      r   r   zHTTPHeaderDict.getlists  s    BEr   c                    	 | j                   |j                            }|dd S # t        $ r |t        j                  u rg cY S |cY S w xY w)zmReturns a list of all the values for the named field. Returns an
        empty list if the key doesn't exist.r~   N)r3   ry   rC   r&   r'   )r   r   r   r   s       r   r   zHTTPHeaderDict.getlistv  sQ    
	??399;/D 8O  	)...	N	s   $ AAAc                >    g d}|D ]  }| j                  |        | S )z
        Remove content-specific header fields before changing the request
        method to GET or HEAD according to RFC 9110, Section 15.4.
        )zContent-EncodingzContent-LanguagezContent-LocationzContent-TypezContent-LengthDigestzLast-Modified)r   )r   content_specific_headersheaders      r   _prepare_for_method_changez)HTTPHeaderDict._prepare_for_method_change  s,    
$
  / 	!FLL 	!r   c                f    t        |       j                   dt        | j                                dS )N())r   r   dictr   r   s    r   __repr__zHTTPHeaderDict.__repr__  s-    t*%%&aT__->(?'@BBr   c                t    |D ]3  }|j                  |      }|g|| j                  |j                         <   5 y r   )r   r3   ry   )r   r   r   r{   s       r   rr   zHTTPHeaderDict._copy_from  s9     	7C--$C,/;#;DOOCIIK(	7r   c                H     t        |              }|j                  |        |S r   )r   rr   )r   clones     r   copyzHTTPHeaderDict.copy  s"    T
r   c              #  z   K   | D ]2  }| j                   |j                            }|dd D ]  }|d   |f  4 yw)z8Iterate over all header lines, including duplicate ones.r~   Nr   r   )r   r   r   r{   s       r   re   zHTTPHeaderDict.iteritems  sL      	#C??399;/DABx #1gsl"#	#s   9;c              #     K   | D ]:  }| j                   |j                            }|d   dj                  |dd       f < yw)z:Iterate over all headers, merging duplicate ones together.r   r}   r~   Nr   rz   s      r   r   zHTTPHeaderDict.itermerged  sG      	-C//#))+.Ca&$))CG,,,	-s   AAc                    t        |       S r   )r`   r   s    r   r   zHTTPHeaderDict.items  s    %d++r   c                P    || v r"|| j                   |j                            dd  v S y)Nr~   Fr   )r   header_namepotential_values      r   ri   z$HTTPHeaderDict._has_value_for_header  s1    $"dook6G6G6I&J12&NNNr   c                N    t        |      }|t        S | j                  |       | S r   )r1   NotImplementedrs   )r   r   r   s      r   __ior__zHTTPHeaderDict.__ior__  s.     DEJ&!!'(r   c                n    t        |      }|t        S | j                         }|j                  |       |S r   )r1   r   r   rs   r   r   r   results       r   __or__zHTTPHeaderDict.__or__  s9     DEJ&!!)*r   c                p    t        |      }|t        S  t        |       |      }|j                  |        |S r   )r1   r   r   rs   r   s       r   __ror__zHTTPHeaderDict.__ror__  s>     DEJ&!!d/0dr   r   )rc   ValidHTTPHeaderSource | Nonert   r   )r   r   r{   r   r   rY   r   )r   r   r   rY   )r   rn   r   ro   ) )r   r   r   r   r   r   )r   rn   r   ro   rZ   r   )r   r   r{   r   r   ro   r   rY   )r   ValidHTTPHeaderSourcert   r   r   rY   )r   r   r   z	list[str])r   r   r   r$   r   list[str] | _DT)r   r   r   z_Sentinel | _DTr   r   )r   r	   )r   r   )r   r!   r   rY   rm   )r   r`   )r   r   r   r   r   ro   )r   rn   r   r!   )r   rn   r   r	   )'r   r   r   r[   r\   r;   rJ   r   rL   rl   r   r   r   rN   rQ   r   r   rs   r*   overloadr   r&   r'   r   
getheadersgetallmatchingheadersigetget_allr   rr   r   re   r   r   ri   r   r   r   r]   r^   s   @r   r!   r!      s    B 65	 2")
0	
&$
 :? !!F!B __1 1__E E 4=3G3G!0	$& J#D GC7

#-,
r   )r0   rn   r   r   )"
__future__r   r*   collectionsr   enumr   r   	threadingr   TYPE_CHECKINGr   typing_extensionsr	   r   __all__TypeVarr"   r#   r$   Unionr+   r   r-   r.   r   r&   r1   GenericMutableMappingr    rW   r`   r!   r   r   r   <module>r      s4   "  #  	  &4 4 #$4
5 fnnUfnnUfnnU
NN38
OOE#s(O$  !(Z/FNN384f6K6KCQTH6U Z/z-SsCx1 -`SV**384 Sr   