o
    ­}”eøC  ã                   @  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
r5d 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jeef  d	f ZG dd„ deƒZddd„ZG dd
„ d
ejeef ejeef ƒZG dd„ dejej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„Zddd„Zd	S )ÚHasGettableStringKeysÚreturnútyping.Iterator[str]c                 C  ó   d S ©N© ©Úselfr   r   ú]/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/urllib3/_collections.pyÚkeys   ó   zHasGettableStringKeys.keysÚkeyÚstrc                 C  r   r   r   ©r   r   r   r   r   Ú__getitem__   r   z!HasGettableStringKeys.__getitem__N©r
   r   ©r   r   r
   r   )Ú__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"   Ú	potentialÚobjectr
   úValidHTTPHeaderSource | Nonec                 C  s|   t | tƒr| S t | tjƒrt tjttf | ¡S t | tjƒr,t tjtjttf  | ¡S t| dƒr<t| dƒr<t 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&‡ fdd„Zd'dd„Zd(dd„Zd)dd„Zd*dd„Z	d+dd„Z
d,d d!„Z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Ú_maxsizeú#typing.Callable[[_VT], None] | NoneÚdispose_funcr   Úlocké
   NÚmaxsizer
   ÚNonec                   s*   t ƒ  ¡  || _|| _tƒ | _tƒ | _d S r   )ÚsuperÚ__init__r1   r3   r   r/   r   r4   )r   r6   r3   ©Ú	__class__r   r   r9   T   s
   
zRecentlyUsedContainer.__init__r   r   r    c                 C  sD   | j � | j |¡}|| j|< |W  d   ƒ S 1 sw   Y  d S r   )r4   r/   Úpop)r   r   Úitemr   r   r   r   _   s
   
$ýz!RecentlyUsedContainer.__getitem__Úvaluec              	   C  s°   d }| j �5 z|| j |¡f}|| j|< W n ty2   || j|< t| jƒ| jkr0| jjdd�}Y nw W d   ƒ n1 s=w   Y  |d urT| jrV|\}}|  |¡ d S d S d S )NF)Úlast)r4   r/   r<   ÚKeyErrorÚlenr1   Úpopitemr3   )r   r   r>   Zevicted_itemÚ_Úevicted_valuer   r   r   Ú__setitem__f   s"   
€ø€øþz!RecentlyUsedContainer.__setitem__c                 C  sJ   | j � | j |¡}W d   ƒ n1 sw   Y  | jr#|  |¡ d S d S r   )r4   r/   r<   r3   )r   r   r>   r   r   r   Ú__delitem__   s   ÿÿz!RecentlyUsedContainer.__delitem__c                 C  s4   | j � t| jƒW  d   ƒ S 1 sw   Y  d S r   )r4   rA   r/   r   r   r   r   Ú__len__†   s   $ÿzRecentlyUsedContainer.__len__útyping.NoReturnc                 C  s   t dƒ‚)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 sw   Y  | jr,|D ]	}|  |¡ q$d S d S r   )r4   Úlistr/   ÚvaluesÚclearr3   )r   rL   r>   r   r   r   rM   �   s   ýþzRecentlyUsedContainer.clearúset[_KT]c                 C  s8   | j � t| j ¡ ƒW  d   ƒ S 1 sw   Y  d S r   )r4   Úsetr/   r   r   r   r   r   r   ™   s   $ÿzRecentlyUsedContainer.keys)r5   N)r6   r0   r3   r2   r
   r7   )r   r   r
   r    )r   r   r>   r    r
   r7   )r   r   r
   r7   ©r
   r0   )r
   rH   )r
   r7   )r
   rN   )r   r   r   Ú__doc__Ú__annotations__r9   r   rE   rF   rG   rJ   rM   r   Ú__classcell__r   r   r:   r   r   A   s    
 ý






c                   @  sB   e Zd ZU dZded< ddd„Zdd
d„Zddd„Z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   Ú_headersÚheadersr
   r7   c                 C  s
   || _ d S r   )rU   )r   rV   r   r   r   r9   ½   ó   
zHTTPHeaderDictItemView.__init__r0   c                 C  s   t t| j ¡ ƒƒS r   )rA   rK   rU   Ú	iteritemsr   r   r   r   rG   À   s   zHTTPHeaderDictItemView.__len__ú typing.Iterator[tuple[str, str]]c                 C  s
   | j  ¡ S r   )rU   rX   r   r   r   r   rJ   Ã   rW   zHTTPHeaderDictItemView.__iter__r=   r%   Úboolc                 C  sD   t |tƒr t|ƒdkr |\}}t |tƒr t |tƒr | j ||¡S dS )Né   F)r'   ÚtuplerA   r   rU   Ú_has_value_for_header)r   r=   Z
passed_keyZ
passed_valr   r   r   Ú__contains__Æ   s
   z#HTTPHeaderDictItemView.__contains__N)rV   r   r
   r7   rP   ©r
   rY   )r=   r%   r
   rZ   )	r   r   r   rQ   rR   r9   rG   rJ   r^   r   r   r   r   rT   ž   s   
 


rT   c                      s`  e Zd ZU dZded< dVdW‡ fd	d
„ZdXdd„ZdYdd„ZdZdd„Zd[dd„Z	d\d]‡ fdd„Z
d^dd„Zd^d d!„Zd_d#d$„Zd`d&d'„ZdZd(d)„Zd*d+œdad-d.„Zdbd1d2„Zejdcd4d5„ƒZejddd8d5„ƒZejfded:d5„Zdfd<d=„ZeZeZeZeZdgd>d?„Zdhd@dA„ZdidBdC„ZdjdEdF„ZdjdGdH„Z dkdJdK„Z!dldNdO„Z"dmdPdQ„Z#dmdRdS„Z$dmdTdU„Z%‡  Z&S )nr   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/   NrV   r&   Úkwargsr   c                   sN   t ƒ  ¡  i | _|d urt|tƒr|  |¡ n|  |¡ |r%|  |¡ d S d S r   )r8   r9   r/   r'   r   Ú
_copy_fromÚextend)r   rV   r`   r:   r   r   r9   ò   s   


ÿzHTTPHeaderDict.__init__r   Úvalr
   r7   c                 C  s*   t |tƒr
| d¡}||g| j| ¡ < d S )Núlatin-1)r'   ÚbytesÚdecoder/   Úlower©r   r   rc   r   r   r   rE   ý   s   

zHTTPHeaderDict.__setitem__c                 C  s    | j | ¡  }d |dd … ¡S )Nú, é   ©r/   rg   Újoinrh   r   r   r   r     s   zHTTPHeaderDict.__getitem__c                 C  s   | j | ¡ = d S r   ©r/   rg   r   r   r   r   rF     s   zHTTPHeaderDict.__delitem__r%   rZ   c                 C  s   t |tƒr| ¡ | jv S dS )NF)r'   r   rg   r/   r   r   r   r   r^   
  s   
zHTTPHeaderDict.__contains__Ú Údefaultc                   s   t ƒ  ||¡S r   )r8   Ú
setdefault©r   r   ro   r:   r   r   rp     s   zHTTPHeaderDict.setdefaultÚotherc                 C  sD   t |ƒ}|d u r
dS t| ƒ|ƒ}dd„ |  ¡ D ƒdd„ | ¡ D ƒkS )NFc                 S  s   i | ]	\}}|  ¡ |“qS r   )rg   )Ú.0ÚkÚvr   r   r   Ú
<dictcomp>  s    z)HTTPHeaderDict.__eq__.<locals>.<dictcomp>)r.   ÚtypeÚ
itermerged)r   rr   Úmaybe_constructableZother_as_http_header_dictr   r   r   Ú__eq__  s   ÿzHTTPHeaderDict.__eq__c                 C  s   |   |¡ S r   )rz   )r   rr   r   r   r   Ú__ne__  s   zHTTPHeaderDict.__ne__r0   c                 C  s
   t | jƒS r   )rA   r/   r   r   r   r   rG      rW   zHTTPHeaderDict.__len__r   c                 c  s    � | j  ¡ D ]}|d V  qd S )Nr   )r/   rL   )r   Úvalsr   r   r   rJ   #  s   €ÿzHTTPHeaderDict.__iter__c                 C  s"   z| |= W d S  t y   Y d S w r   )r@   r   r   r   r   Údiscard(  s
   ÿzHTTPHeaderDict.discardF)Úcombiner~   c                C  sx   t |tƒr
| d¡}| ¡ }||g}| j ||¡}||ur:t|ƒdks%J ‚|r3|d d | |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')]
        rd   r[   éÿÿÿÿri   N)r'   re   rf   rg   r/   rp   rA   Úappend)r   r   rc   r~   Ú	key_lowerÚnew_valsr|   r   r   r   Úadd.  s   

ùzHTTPHeaderDict.addÚargsÚValidHTTPHeaderSourcec                 O  s&  t |ƒdkrtdt |ƒ› d�ƒ‚t |ƒdkr|d nd}t|tƒr1| ¡ D ]
\}}|  ||¡ q%nQt|tjƒrG| ¡ D ]
\}}|  ||¡ q;n;t|tj	ƒrit 
tj	tjttf  |¡}|D ]
\}}|  ||¡ q]nt|dƒr‚t|dƒr‚| ¡ D ]
}|  ||| ¡ qw| ¡ 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__
        rj   z/extend() takes at most 1 positional arguments (z given)r   r   r   r   N)rA   Ú	TypeErrorr'   r   rX   rƒ   r(   r)   Úitemsr+   r*   r,   r   r-   r   )r   r„   r`   rr   r   rc   r>   r   r   r   rb   Q  s0   ÿ
ÿÿÿÿzHTTPHeaderDict.extendú	list[str]c                 C  r   r   r   r   r   r   r   Úgetlistr  ó   zHTTPHeaderDict.getlistr!   úlist[str] | _DTc                 C  r   r   r   rq   r   r   r   r‰   v  rŠ   ú_Sentinel | _DTc                 C  sH   z	| j | ¡  }W n ty   |tju rg  Y S | Y S w |dd… S )zmReturns a list of all the values for the named field. Returns an
        empty list if the key doesn't exist.rj   N)r/   rg   r@   r"   r#   )r   r   ro   r|   r   r   r   r‰   z  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)r}   )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ú(ú))rw   r   Údictrx   r   r   r   r   Ú__repr__¦  s   zHTTPHeaderDict.__repr__c                 C  s,   |D ]}|  |¡}|g|¢| j| ¡ < qd S r   )r‰   r/   rg   )r   rr   r   rc   r   r   r   ra   ©  s   
þzHTTPHeaderDict._copy_fromc                 C  s   t | ƒƒ }| | ¡ |S r   )rw   ra   )r   Úcloner   r   r   Úcopy®  s   

zHTTPHeaderDict.copyrY   c                 c  s>   � | D ]}| j | ¡  }|dd… D ]	}|d |fV  qqdS )z8Iterate over all header lines, including duplicate ones.rj   Nr   rm   )r   r   r|   rc   r   r   r   rX   ³  s   €ÿþzHTTPHeaderDict.iteritemsc                 c  s:   � | D ]}| j | ¡  }|d d |dd… ¡fV  qdS )z:Iterate over all headers, merging duplicate ones together.r   ri   rj   Nrk   rh   r   r   r   rx   º  s
   €þzHTTPHeaderDict.itermergedrT   c                 C  s   t | ƒS r   )rT   r   r   r   r   r‡   À  s   zHTTPHeaderDict.itemsÚheader_nameÚpotential_valuec                 C  s&   || v r|| j | ¡  dd … v S dS )Nrj   Frm   )r   r•   r–   r   r   r   r]   Ã  s   z$HTTPHeaderDict._has_value_for_headerc                 C  s"   t |ƒ}|d u r
tS |  |¡ | S r   )r.   ÚNotImplementedrb   )r   rr   ry   r   r   r   Ú__ior__È  s
   
zHTTPHeaderDict.__ior__c                 C  s*   t |ƒ}|d u r
tS |  ¡ }| |¡ |S r   )r.   r—   r”   rb   ©r   rr   ry   Úresultr   r   r   Ú__or__Ñ  s   
zHTTPHeaderDict.__or__c                 C  s.   t |ƒ}|d u r
tS t| ƒ|ƒ}| | ¡ |S r   )r.   r—   rw   rb   r™   r   r   r   Ú__ror__Û  s   
zHTTPHeaderDict.__ror__r   )rV   r&   r`   r   )r   r   rc   r   r
   r7   r   )r   r   r
   r7   )r   r%   r
   rZ   )rn   )r   r   ro   r   r
   r   )rr   r%   r
   rZ   rP   r   )r   r   rc   r   r~   rZ   r
   r7   )r„   r…   r`   r   r
   r7   )r   r   r
   rˆ   )r   r   ro   r!   r
   r‹   )r   r   ro   rŒ   r
   r‹   )r
   r   )r
   r   )rr   r   r
   r7   )r
   r   r_   )r
   rT   )r•   r   r–   r   r
   rZ   )rr   r%   r
   r   )'r   r   r   rQ   rR   r9   rE   r   rF   r^   rp   rz   r{   rG   rJ   r}   rƒ   rb   r(   Úoverloadr‰   r"   r#   rŽ   Ú
getheadersÚgetallmatchingheadersÚigetÚget_allr’   ra   r”   rX   rx   r‡   r]   r˜   r›   rœ   rS   r   r   r:   r   r   Î   sJ   
 !









#!ÿ









	
)r$   r%   r
   r&   )"Ú
__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   ÚSetrT   r   r   r   r   r   Ú<module>   s2    


ýÿ
& ]0