
    MhC                    2   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j        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!dS )    )annotationsN)OrderedDict)Enumauto)RLock)Protocol)Selfc                      e Zd ZddZd	dZdS )
HasGettableStringKeysreturntyping.Iterator[str]c                    d S N selfs    T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/urllib3/_collections.pykeyszHasGettableStringKeys.keys             keystrc                    d S r   r   r   r   s     r   __getitem__z!HasGettableStringKeys.__getitem__   r   r   Nr   r   r   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r   r      s(        3333333333r   r   RecentlyUsedContainerHTTPHeaderDict_KT_VT_DTc                  "    e Zd Z e            ZdS )	_SentinelN)r   r   r    r   
not_passedr   r   r   r'   r'   '   s        JJJr   r'   	potentialobjectr   ValidHTTPHeaderSource | Nonec                   t          | t                    r| S t          | t          j                  r1t          j        t          j        t
          t
          f         |           S t          | t          j                  r<t          j        t          j        t          t
          t
          f                  |           S t          | d          r%t          | d          rt          j        d|           S d S )Nr   r   r   )	
isinstancer"   typingMappingcastr   Iterabletuplehasattr)r)   s    r   %ensure_can_construct_http_header_dictr4   +   s     )^,, 	Iv~	.	.  {6>#s(3Y???	Iv	/	/  {6?5c?;YGGG	F	#	# 	=(I(I {2I>>>tr   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   lock
   Nmaxsizer   Nonec                    t                                                       || _        || _        t	                      | _        t                      | _        d S r   )super__init__r8   r:   r   r6   r   r;   )r   r=   r:   	__class__s      r   rA   zRecentlyUsedContainer.__init__R   sD    
 	(%--GG			r   r   r#   r$   c                    | j         5  | j                            |          }|| j        |<   |cd d d            S # 1 swxY w Y   d S r   )r;   r6   pop)r   r   items      r   r   z!RecentlyUsedContainer.__getitem__]   s    Y 	 	?&&s++D#'DOC 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   &;??valuec                   d }| j         5  	 || j                            |          f}|| j        |<   nR# t          $ rE || j        |<   t	          | j                  | j        k    r| j                            d          }Y nw xY wd d d            n# 1 swxY w Y   |#| j        r|\  }}|                     |           d S d S d S )NF)last)r;   r6   rD   KeyErrorlenr8   popitemr:   )r   r   rG   evicted_item_evicted_values         r   __setitem__z!RecentlyUsedContainer.__setitem__d   sH   Y 	G 	GG  #DO$7$7$<$<<',$$ G G G (-$t''$-77 $(?#:#:#:#F#FLG	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G& #(9#+A}m,,,,, $###s2   B&3BAB?BBBBBc                    | j         5  | j                            |          }d d d            n# 1 swxY w Y   | j        r|                     |           d S d S r   )r;   r6   rD   r:   )r   r   rG   s      r   __delitem__z!RecentlyUsedContainer.__delitem__}   s    Y 	- 	-O'',,E	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-  	%e$$$$$	% 	%s   /33c                l    | j         5  t          | j                  cd d d            S # 1 swxY w Y   d S r   )r;   rK   r6   r   s    r   __len__zRecentlyUsedContainer.__len__   s{    Y 	( 	(t''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   )--typing.NoReturnc                     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                                         d d d            n# 1 swxY w Y   | j        r|D ]}|                     |           d S d S r   )r;   listr6   valuesclearr:   )r   r[   rG   s      r   r\   zRecentlyUsedContainer.clear   s    Y 	$ 	$$/002233FO!!###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$
  	) ) )!!%((((	) 	)) )s   A AAAset[_KT]c                    | j         5  t          | j                                                  cd d d            S # 1 swxY w Y   d S r   )r;   setr6   r   r   s    r   r   zRecentlyUsedContainer.keys   s    Y 	/ 	/t++--..	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/rF   )r<   N)r=   r7   r:   r9   r   r>   )r   r#   r   r$   )r   r#   rG   r$   r   r>   )r   r#   r   r>   r   r7   )r   rU   )r   r>   )r   r]   )r   r   r    __doc____annotations__rA   r   rP   rR   rT   rX   r\   r   __classcell__rB   s   @r   r!   r!   ?   s          -,,,MMM5555KKK <@	 	 	 	 	 	 	   - - - -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dS )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"   _headersheadersr   r>   c                    || _         d S r   )rg   )r   rh   s     r   rA   zHTTPHeaderDictItemView.__init__   s    r   r7   c                h    t          t          | j                                                            S r   )rK   rZ   rg   	iteritemsr   s    r   rT   zHTTPHeaderDictItemView.__len__   s&    4//1122333r    typing.Iterator[tuple[str, str]]c                4    | j                                         S r   )rg   rk   r   s    r   rX   zHTTPHeaderDictItemView.__iter__   s    }&&(((r   rE   r*   boolc                    t          |t                    r]t          |          dk    rJ|\  }}t          |t                    r0t          |t                    r| j                            ||          S dS )N   F)r-   r2   rK   r   rg   _has_value_for_header)r   rE   
passed_key
passed_vals       r   __contains__z#HTTPHeaderDictItemView.__contains__   so    dE"" 	Ss4yyA~~%)"J
*c** Sz*c/J/J S}:::zRRRur   N)rh   r"   r   r>   r`   r   rl   )rE   r*   r   rn   )	r   r   r    ra   rb   rA   rT   rX   rt   r   r   r   rf   rf      s~          8        4 4 4 4) ) ) )     r   rf   c                  `    e Zd ZU dZded<   d=d> fd	Zd?dZd@dZdAdZdBdZ	dCdD fdZ
dEdZdEdZdFdZdGdZdAdZdd dHd"ZdId%Zej        dJd'            Zej        dKd*            Zej        fdLd,ZdMd.ZeZeZeZeZdNd/ZdOd0ZdMd1ZdPd3ZdPd4Z dQd6Z!dRd9Z"dSd:Z#dTd;Z$dTd<Z% xZ&S )Ur"   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]]r6   Nrh   r+   kwargsr   c                   t                                                       i | _        |@t          |t                    r|                     |           n|                     |           |r|                     |           d S d S r   )r@   rA   r6   r-   r"   
_copy_fromextend)r   rh   rw   rB   s      r   rA   zHTTPHeaderDict.__init__   s    '>22 %((((G$$$ 	 KK	  	 r   r   valr   r>   c                    t          |t                    r|                    d          }||g| j        |                                <   d S )Nlatin-1)r-   bytesdecoder6   lowerr   r   r{   s      r   rP   zHTTPHeaderDict.__setitem__   sC    c5!! 	(**Y''C(+Sz		$$$r   c                z    | j         |                                         }d                    |dd                    S )N,    r6   r   joinr   s      r   r   zHTTPHeaderDict.__getitem__  s0    ociikk*yyQRR!!!r   c                :    | j         |                                = d S r   r6   r   r   s     r   rR   zHTTPHeaderDict.__delitem__  s    OCIIKK(((r   r*   rn   c                f    t          |t                    r|                                | j        v S dS )NF)r-   r   r   r6   r   s     r   rt   zHTTPHeaderDict.__contains__  s.    c3 	299;;$/11ur    defaultc                H    t                                          ||          S r   )r@   
setdefault)r   r   r   rB   s      r   r   zHTTPHeaderDict.setdefault  s    ww!!#w///r   otherc                    t          |          }|dS  t          |           |          }d |                                 D             d |                                D             k    S )NFc                >    i | ]\  }}|                                 |S r   r   .0kvs      r   
<dictcomp>z)HTTPHeaderDict.__eq__.<locals>.<dictcomp>  s&    ;;;A		1;;;r   c                >    i | ]\  }}|                                 |S r   r   r   s      r   r   z)HTTPHeaderDict.__eq__.<locals>.<dictcomp>  s9     @
 @
 @
!QAGGIIq@
 @
 @
r   )r4   type
itermerged)r   r   maybe_constructableother_as_http_header_dicts       r   __eq__zHTTPHeaderDict.__eq__  s    CEJJ&5(2T

3F(G(G%;;):):;;; @
 @
%>%I%I%K%K@
 @
 @
 
 	
r   c                .    |                      |           S r   )r   )r   r   s     r   __ne__zHTTPHeaderDict.__ne__  s    ;;u%%%%r   r7   c                *    t          | j                  S r   )rK   r6   r   s    r   rT   zHTTPHeaderDict.__len__  s    4?###r   r   c              #  V   K   | j                                         D ]}|d         V  d S )Nr   )r6   r[   )r   valss     r   rX   zHTTPHeaderDict.__iter__!  s<      O**,, 	 	Dq'MMMM	 	r   c                0    	 | |= d S # t           $ r Y d S w xY wr   )rJ   r   s     r   discardzHTTPHeaderDict.discard&  s4    	S			 	 	 	DD	s    
F)combiner   c               J   t          |t                    r|                    d          }|                                }||g}| j                            ||          }||urAt          |          dk    sJ |r|d         dz   |z   |d<   dS |                    |           dS dS )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')]
        r}   rp   r   N)r-   r~   r   r   r6   r   rK   append)r   r   r{   r   	key_lowernew_valsr   s          r   addzHTTPHeaderDict.add,  s    ( c5!! 	(**Y''CIIKK	:)))X>>4 t99>>>> !8d?S0RC       r   argsValidHTTPHeaderSourcec                   t          |          dk    r t          dt          |           d          t          |          dk    r|d         nd}t          |t                    r2|                                D ]\  }}|                     ||           nt          |t          j                  r1|                                D ]\  }}|                     ||           nt          |t          j	                  r[t          j
        t          j	        t          t          t          f                  |          }|D ]\  }}|                     ||           nSt          |d          rCt          |d          r3|                                D ]}|                     |||                    |                                D ]\  }}|                     ||           dS )	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)rK   	TypeErrorr-   r"   rk   r   r.   r/   itemsr1   r0   r2   r   r3   r   )r   r   rw   r   r   r{   rG   s          r   rz   zHTTPHeaderDict.extendO  s   
 t99q==T#d))TTT   t99>>Qre^,, 	*!OO-- # #Sc""""#v~.. 	*!KKMM # #Sc""""#v// 	*Kc3h @%HHE# % %
Ue$$$$%UF## 	*}(E(E 	* zz|| * *eCj)))) ,,.. 	! 	!JCHHS%    	! 	!r   	list[str]c                    d S r   r   r   s     r   getlistzHTTPHeaderDict.getlistp  s    .1cr   r%   list[str] | _DTc                    d S r   r   )r   r   r   s      r   r   zHTTPHeaderDict.getlists  s    BE#r   _Sentinel | _DTc                    	 | 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)r6   r   rJ   r'   r(   )r   r   r   r   s       r   r   zHTTPHeaderDict.getlistv  sg    
	?399;;/D 8O  	 	 	)...			NNN	s   + AAAr	   c                B    g d}|D ]}|                      |           | 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                t    t          |           j         dt          |                                            dS )N())r   r   dictr   r   s    r   __repr__zHTTPHeaderDict.__repr__  s4    t**%BBT__->->(?(?BBBBr   c                x    |D ]6}|                     |          }|g|| j        |                                <   7d S r   )r   r6   r   )r   r   r   r{   s       r   ry   zHTTPHeaderDict._copy_from  sI     	7 	7C--$$C,/;#;DOCIIKK((	7 	7r   c                ^     t          |                       }|                    |            |S r   )r   ry   )r   clones     r   copyzHTTPHeaderDict.copy  s,    T

r   rl   c              #     K   | D ]:}| j         |                                         }|dd         D ]}|d         |fV  ;dS )z8Iterate over all header lines, including duplicate ones.r   Nr   r   )r   r   r   r{   s       r   rk   zHTTPHeaderDict.iteritems  sf       	# 	#C?399;;/DABBx # #1gsl""""#	# 	#r   c              #     K   | D ]H}| j         |                                         }|d         d                    |dd                   fV  IdS )z:Iterate over all headers, merging duplicate ones together.r   r   r   Nr   r   s      r   r   zHTTPHeaderDict.itermerged  s_       	- 	-C/#))++.Ca&$))CG,,,,,,,	- 	-r   rf   c                     t          |           S r   )rf   r   s    r   r   zHTTPHeaderDict.items  s    %d+++r   header_namepotential_valuec                `    || v r)|| j         |                                         dd          v S dS )Nr   Fr   )r   r   r   s      r   rq   z$HTTPHeaderDict._has_value_for_header  s9    $"dok6G6G6I6I&J122&NNNur   c                `    t          |          }|t          S |                     |           | S r   )r4   NotImplementedrz   )r   r   r   s      r   __ior__zHTTPHeaderDict.__ior__  s7     DEJJ&!!'(((r   c                    t          |          }|t          S |                                 }|                    |           |S r   )r4   r   r   rz   r   r   r   results       r   __or__zHTTPHeaderDict.__or__  sD     DEJJ&!!)***r   c                    t          |          }|t          S  t          |           |          }|                    |            |S r   )r4   r   r   rz   r   s       r   __ror__zHTTPHeaderDict.__ror__  sL     DEJJ&!!d/00dr   r   )rh   r+   rw   r   )r   r   r{   r   r   r>   r   )r   r   r   r>   )r   r*   r   rn   )r   )r   r   r   r   r   r   )r   r*   r   rn   r`   r   )r   r   r{   r   r   rn   r   r>   )r   r   rw   r   r   r>   )r   r   r   r   )r   r   r   r%   r   r   )r   r   r   r   r   r   )r   r	   )r   r   )r   r"   r   r>   ru   )r   rf   )r   r   r   r   r   rn   )r   r*   r   r"   )r   r*   r   r	   )'r   r   r    ra   rb   rA   rP   r   rR   rt   r   r   r   rT   rX   r   r   rz   r.   overloadr   r'   r(   r   
getheadersgetallmatchingheadersigetget_allr   ry   r   rk   r   r   rq   r   r   r   rc   rd   s   @r   r"   r"      s         B 6555	  	  	  	  	  	  	 2 2 2 2" " " ") ) ) )   
0 0 0 0 0 0 0	
 	
 	
 	
& & & &$ $ $ $   
    :? !! !! !! !! !! !!F! ! ! !B _111 _1_EEE _E 4=3G    $   & J#D GC C C C7 7 7 7
   
# # # #- - - -, , , ,   
             r   )r)   r*   r   r+   )"
__future__r   r.   collectionsr   enumr   r   	threadingr   TYPE_CHECKINGr   typing_extensionsr	   r   __all__TypeVarr#   r$   r%   Unionr/   r   r1   r2   r   r'   r4   GenericMutableMappingr!   r_   rf   r"   r   r   r   <module>r      s>   " " " " " "  # # # # # #              	 
4  &&&&&&4 4 4 4 4 4 4 4 #$4
5 fnUfnUfnU
N38
OE#s(O$           (Z/ Z/ Z/ Z/ Z/FN384f6KCQTH6U Z/ Z/ Z/z- - - - -SsCx1 - - -`S S S S SV*384 S S S S Sr   