a
    Aù’i»D  ã                   @  s:  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
rjd dlmZ d dlmZ G dd	„ d	eƒZd
dgZe d¡Ze d¡Ze d¡Zejdejeef ejeeef  d	f ZG dd„ deƒZdddœdd„ZG dd
„ d
ejeef ejeef ƒZG dd„ deeeef  ƒZ G dd„ dejeef ƒZ!dS )é    )ÚannotationsN)ÚOrderedDict)ÚEnumÚauto)ÚRLock)ÚProtocol)ÚSelfc                   @  s*   e Zd Zddœdd„Zdddœdd„Zd	S )
ÚHasGettableStringKeysútyping.Iterator[str]©Úreturnc                 C  s   d S ©N© ©Úselfr   r   úQ/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/urllib3/_collections.pyÚkeys   ó    zHasGettableStringKeys.keysÚstr©Úkeyr   c                 C  s   d S r   r   ©r   r   r   r   r   Ú__getitem__   r   z!HasGettableStringKeys.__getitem__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r	      s   r	   ÚRecentlyUsedContainerÚHTTPHeaderDictÚ_KTÚ_VTÚ_DTc                   @  s   e Zd Zeƒ ZdS )Ú	_SentinelN)r   r   r   r   Ú
not_passedr   r   r   r   r!   '   s   r!   ÚobjectúValidHTTPHeaderSource | None)Ú	potentialr   c                 C  s~   t | tƒr| S t | tjƒr0t tjttf | ¡S t | tjƒrVt tjtttf  | ¡S t| dƒrvt| dƒrvt d| ¡S d S d S )Nr   r   r	   )	Ú
isinstancer   ÚtypingÚMappingÚcastr   ÚIterableÚtupleÚhasattr)r%   r   r   r   Ú%ensure_can_construct_http_header_dict+   s    
r-   c                      s¸   e Zd ZU dZded< ded< ded< ded	< d%ddddœ‡ fdd„Zdddœdd„Zddddœdd„Zdddœdd„Zddœdd„Z	ddœdd„Z
ddœd d!„Zd"dœd#d$„Z‡  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Ú_maxsizez#typing.Callable[[_VT], None] | NoneÚdispose_funcr   Úlocké
   NÚNone)Úmaxsizer1   r   c                   s*   t ƒ  ¡  || _|| _tƒ | _tƒ | _d S r   )ÚsuperÚ__init__r0   r1   r   r.   r   r2   )r   r5   r1   ©Ú	__class__r   r   r7   R   s
    
zRecentlyUsedContainer.__init__r   r   r   c                 C  sD   | j �* | j |¡}|| j|< |W  d   ƒ S 1 s60    Y  d S r   )r2   r.   Úpop)r   r   Úitemr   r   r   r   ]   s    
z!RecentlyUsedContainer.__getitem__)r   Úvaluer   c              	   C  s¨   d }| j �j z|| j |¡f}|| j|< W n: tyd   || j|< t| jƒ| jkr`| jjdd�}Y n0 W d   ƒ n1 sz0    Y  |d ur¤| jr¤|\}}|  |¡ d S )NF)Úlast)r2   r.   r:   ÚKeyErrorÚlenr0   Úpopitemr1   )r   r   r<   Zevicted_itemÚ_Úevicted_valuer   r   r   Ú__setitem__d   s    
2z!RecentlyUsedContainer.__setitem__c                 C  sF   | j � | j |¡}W d   ƒ n1 s(0    Y  | jrB|  |¡ d S r   )r2   r.   r:   r1   )r   r   r<   r   r   r   Ú__delitem__}   s    *z!RecentlyUsedContainer.__delitem__r   c                 C  s4   | j � t| jƒW  d   ƒ S 1 s&0    Y  d S r   )r2   r?   r.   r   r   r   r   Ú__len__„   s    zRecentlyUsedContainer.__len__ztyping.NoReturnc                 C  s   t dƒ‚d S )Nz7Iteration over this class is unlikely to be threadsafe.)ÚNotImplementedErrorr   r   r   r   Ú__iter__ˆ   s    ÿzRecentlyUsedContainer.__iter__c                 C  s\   | j �( t| j ¡ ƒ}| j ¡  W d   ƒ n1 s40    Y  | jrX|D ]}|  |¡ qHd S r   )r2   Úlistr.   ÚvaluesÚclearr1   )r   rI   r<   r   r   r   rJ   �   s    (zRecentlyUsedContainer.clearzset[_KT]c                 C  s8   | j � t| j ¡ ƒW  d   ƒ S 1 s*0    Y  d S r   )r2   Úsetr.   r   r   r   r   r   r   —   s    zRecentlyUsedContainer.keys)r3   N)r   r   r   Ú__doc__Ú__annotations__r7   r   rC   rD   rE   rG   rJ   r   Ú__classcell__r   r   r8   r   r   ?   s   
  ý
c                   @  sV   e Zd ZU dZded< dddœdd„Zdd	œd
d„Zdd	œdd„Zdddœ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   Ú_headersr4   )Úheadersr   c                 C  s
   || _ d S r   )rP   )r   rQ   r   r   r   r7   »   s    zHTTPHeaderDictItemView.__init__r/   r   c                 C  s   t t| j ¡ ƒƒS r   )r?   rH   rP   Ú	iteritemsr   r   r   r   rE   ¾   s    zHTTPHeaderDictItemView.__len__ú typing.Iterator[tuple[str, str]]c                 C  s
   | j  ¡ S r   )rP   rR   r   r   r   r   rG   Á   s    zHTTPHeaderDictItemView.__iter__r#   Úbool)r;   r   c                 C  sD   t |tƒr@t|ƒdkr@|\}}t |tƒr@t |tƒr@| j ||¡S dS )Né   F)r&   r+   r?   r   rP   Ú_has_value_for_header)r   r;   Z
passed_keyZ
passed_valr   r   r   Ú__contains__Ä   s
    z#HTTPHeaderDictItemView.__contains__N)	r   r   r   rL   rM   r7   rE   rG   rW   r   r   r   r   rO   œ   s   
rO   c                      s  e Zd ZU dZded< dTdddœ‡ fdd	„Zddd
dœdd„Zdddœdd„Zdd
dœdd„Zdddœdd„Z	dUddddœ‡ fdd„Z
dddœdd„Zdddœdd„Zd d!œd"d#„Zd$d!œd%d&„Zdd
dœd'd(„Zd)d*œdddd
d+œd,d-„Zd.dd
d/œd0d1„Zejdd2dœd3d4„ƒZejdd5d6dœd7d4„ƒZejfdd8d6dœd9d4„Zd:d!œd;d<„ZeZeZeZeZdd!œd=d>„Zd d
dœd?d@„Zd:d!œdAdB„ZdCd!œdDdE„ZdCd!œdFdG„Z dHd!œdIdJ„Z!ddddKœdLdM„Z"dd dœdNdO„Z#dd:dœdPdQ„Z$dd:dœdRdS„Z%‡  Z&S )Vr   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]]r.   Nr$   r   )rQ   Úkwargsc                   sJ   t ƒ  ¡  i | _|d ur8t|tƒr.|  |¡ n
|  |¡ |rF|  |¡ d S r   )r6   r7   r.   r&   r   Ú
_copy_fromÚextend)r   rQ   rX   r8   r   r   r7   ð   s    


zHTTPHeaderDict.__init__r4   )r   Úvalr   c                 C  s*   t |tƒr| d¡}||g| j| ¡ < d S ©Núlatin-1©r&   ÚbytesÚdecoder.   Úlower©r   r   r[   r   r   r   rC   û   s    

zHTTPHeaderDict.__setitem__r   c                 C  s4   t |tƒr| d¡}| j| ¡  }d |dd … ¡S )Nr]   ú, é   )r&   r_   r`   r.   ra   Újoinrb   r   r   r   r     s    

zHTTPHeaderDict.__getitem__c                 C  s$   t |tƒr| d¡}| j| ¡ = d S r\   r^   r   r   r   r   rD     s    

zHTTPHeaderDict.__delitem__r#   rT   c                 C  s0   t |tƒr| d¡}t |tƒr,| ¡ | jv S dS )Nr]   F)r&   r_   r`   r   ra   r.   r   r   r   r   rW     s
    


zHTTPHeaderDict.__contains__Ú )r   Údefaultr   c                   s   t ƒ  ||¡S r   )r6   Ú
setdefault©r   r   rg   r8   r   r   rh     s    zHTTPHeaderDict.setdefault)Úotherr   c                 C  sD   t |ƒ}|d u rdS t| ƒ|ƒ}dd„ |  ¡ D ƒdd„ | ¡ D ƒkS )NFc                 S  s   i | ]\}}|  ¡ |“qS r   )ra   )Ú.0ÚkÚvr   r   r   Ú
<dictcomp>  r   z)HTTPHeaderDict.__eq__.<locals>.<dictcomp>)r-   ÚtypeÚ
itermerged)r   rj   Úmaybe_constructableZother_as_http_header_dictr   r   r   Ú__eq__  s    ÿzHTTPHeaderDict.__eq__c                 C  s   |   |¡ S r   )rr   )r   rj   r   r   r   Ú__ne__!  s    zHTTPHeaderDict.__ne__r/   r   c                 C  s
   t | jƒS r   )r?   r.   r   r   r   r   rE   $  s    zHTTPHeaderDict.__len__r
   c                 c  s   | j  ¡ D ]}|d V  q
d S )Nr   )r.   rI   )r   Úvalsr   r   r   rG   '  s    zHTTPHeaderDict.__iter__c                 C  s"   z
| |= W n t y   Y n0 d S r   )r>   r   r   r   r   Údiscard,  s    
zHTTPHeaderDict.discardF)Úcombine)r   r[   rv   r   c                C  sr   t |tƒr| d¡}| ¡ }||g}| j ||¡}||urnt|ƒdksJJ ‚|rd|d d | |d< n
| |¡ 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]   rU   éÿÿÿÿrc   N)r&   r_   r`   ra   r.   rh   r?   Úappend)r   r   r[   rv   Ú	key_lowerÚnew_valsrt   r   r   r   Úadd2  s    

zHTTPHeaderDict.addÚValidHTTPHeaderSource)ÚargsrX   r   c                 O  s*  t |ƒdkr tdt |ƒ› d�ƒ‚t |ƒdkr4|d nd}t|tƒrb| ¡ D ]\}}|  ||¡ qJn¤t|tjƒrŽ| ¡ D ]\}}|  ||¡ qvnxt|tj	ƒrÐt 
tj	tttf  |¡}|D ]\}}|  ||¡ q¸n6t|dƒ�rt|dƒ�r| ¡ D ]}|  ||| ¡ qð| ¡ D ]\}}|  ||¡ �qdS )	zÀGeneric 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__
        rd   z/extend() takes at most 1 positional arguments (z given)r   r   r   r   N)r?   Ú	TypeErrorr&   r   rR   r{   r'   r(   Úitemsr*   r)   r+   r   r,   r   )r   r}   rX   rj   r   r[   r<   r   r   r   rZ   U  s(    ÿ
zHTTPHeaderDict.extendz	list[str]c                 C  s   d S r   r   r   r   r   r   Úgetlistv  s    zHTTPHeaderDict.getlistr    zlist[str] | _DTc                 C  s   d S r   r   ri   r   r   r   r€   y  s    z_Sentinel | _DTc                 C  s`   t |tƒr| d¡}z| j| ¡  }W n( tyN   |tju rFg  Y S | Y S 0 |dd… S dS )zmReturns a list of all the values for the named field. Returns an
        empty list if the key doesn't exist.r]   rd   N)r&   r_   r`   r.   ra   r>   r!   r"   )r   r   rg   rt   r   r   r   r€   |  s    



r   c                 C  s    g d¢}|D ]}|   |¡ q| 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-LengthZDigestzLast-Modified)ru   )r   Zcontent_specific_headersÚheaderr   r   r   Ú_prepare_for_method_change�  s    	z)HTTPHeaderDict._prepare_for_method_changec                 C  s   t | ƒj› dt|  ¡ ƒ› d�S )Nú(ú))ro   r   Údictrp   r   r   r   r   Ú__repr__ª  s    zHTTPHeaderDict.__repr__c                 C  s,   |D ]"}|  |¡}|g|¢| j| ¡ < qd S r   )r€   r.   ra   )r   rj   r   r[   r   r   r   rY   ­  s    
zHTTPHeaderDict._copy_fromc                 C  s   t | ƒƒ }| | ¡ |S r   )ro   rY   )r   Úcloner   r   r   Úcopy²  s    

zHTTPHeaderDict.copyrS   c                 c  s<   | D ]2}| j | ¡  }|dd… D ]}|d |fV  q"qdS )z8Iterate over all header lines, including duplicate ones.rd   Nr   ©r.   ra   )r   r   rt   r[   r   r   r   rR   ·  s    zHTTPHeaderDict.iteritemsc                 c  s8   | D ].}| j | ¡  }|d d |dd… ¡fV  qdS )z:Iterate over all headers, merging duplicate ones together.r   rc   rd   N)r.   ra   re   rb   r   r   r   rp   ¾  s    zHTTPHeaderDict.itermergedrO   c                 C  s   t | ƒS r   )rO   r   r   r   r   r   Ä  s    zHTTPHeaderDict.items)Úheader_nameÚpotential_valuer   c                 C  s&   || v r"|| j | ¡  dd … v S dS )Nrd   Fr‰   )r   rŠ   r‹   r   r   r   rV   Ç  s    z$HTTPHeaderDict._has_value_for_headerc                 C  s"   t |ƒ}|d u rtS |  |¡ | S r   )r-   ÚNotImplementedrZ   )r   rj   rq   r   r   r   Ú__ior__Ì  s
    
zHTTPHeaderDict.__ior__c                 C  s*   t |ƒ}|d u rtS |  ¡ }| |¡ |S r   )r-   rŒ   rˆ   rZ   ©r   rj   rq   Úresultr   r   r   Ú__or__Õ  s    
zHTTPHeaderDict.__or__c                 C  s.   t |ƒ}|d u rtS t| ƒ|ƒ}| | ¡ |S r   )r-   rŒ   ro   rZ   rŽ   r   r   r   Ú__ror__ß  s    
zHTTPHeaderDict.__ror__)N)rf   )'r   r   r   rL   rM   r7   rC   r   rD   rW   rh   rr   rs   rE   rG   ru   r{   rZ   r'   Úoverloadr€   r!   r"   r‚   Ú
getheadersÚgetallmatchingheadersÚigetÚget_allr†   rY   rˆ   rR   rp   r   rV   r�   r�   r‘   rN   r   r   r8   r   r   Ì   sH   
!#!ÿ	
)"Ú
__future__r   r'   Úcollectionsr   Úenumr   r   Ú	threadingr   ÚTYPE_CHECKINGr   Ztyping_extensionsr   r	   Ú__all__ÚTypeVarr   r   r    ÚUnionr(   r   r*   r+   r|   r!   r-   ÚGenericÚMutableMappingr   rK   rO   r   r   r   r   r   Ú<module>   s0   


ýÿ&]0