o
    Ë Ži»D  ã                   @  s4  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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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„Zddd„Zd	S )ÚHasGettableStringKeysÚreturnútyping.Iterator[str]c                 C  ó   d S ©N© ©Úselfr   r   ú^C:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\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  sz   t | tƒr| S t | tjƒrt tjttf | ¡S t | tjƒr+t tjt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   R   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__d   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   ?   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'   r,   rA   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dfdBdC„ZdidEdF„ZdidGdH„Z djdJdK„Z!dkdNdO„Z"dldPdQ„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   rb   r   r   r   rE   û   s   

zHTTPHeaderDict.__setitem__c                 C  s4   t |tƒr
| d¡}| j| ¡  }d |dd … ¡S )Nrd   ú, é   )r'   rf   rg   r/   rh   Újoinri   r   r   r   r     s   

zHTTPHeaderDict.__getitem__c                 C  s$   t |tƒr
| d¡}| j| ¡ = d S rc   re   r   r   r   r   rF     s   

zHTTPHeaderDict.__delitem__r%   rZ   c                 C  s0   t |tƒr
| d¡}t |tƒr| ¡ | jv S dS )Nrd   F)r'   rf   rg   r   rh   r/   r   r   r   r   r]     s
   


zHTTPHeaderDict.__contains__Ú Údefaultc                   s   t ƒ  ||¡S r   )r8   Ú
setdefault©r   r   rn   r:   r   r   ro     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   )rh   )Ú.0ÚkÚvr   r   r   Ú
<dictcomp>  s    z)HTTPHeaderDict.__eq__.<locals>.<dictcomp>)r.   ÚtypeÚ
itermerged)r   rq   Úmaybe_constructableZother_as_http_header_dictr   r   r   Ú__eq__  s   ÿzHTTPHeaderDict.__eq__c                 C  s   |   |¡ S r   )ry   )r   rq   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[   éÿÿÿÿrj   N)r'   rf   rg   rh   r/   ro   rA   Úappend)r   r   rb   r}   Ú	key_lowerÚnew_valsr{   r   r   r   Úadd2  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ƒr0| ¡ D ]X\}}|  ||¡ q%t|tjƒrE| ¡ D ]C\}}|  ||¡ q:t|tj	ƒret 
tj	tttf  |¡}|D ]#\}}|  ||¡ qZt|dƒr~t|dƒr~| ¡ D ]
}|  ||| ¡ qs| ¡ 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__
        rk   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_   rq   r   rb   r>   r   r   r   ra   U  s*   ÿ
ÿzHTTPHeaderDict.extendú	list[str]c                 C  r   r   r   r   r   r   r   Úgetlistv  ó   zHTTPHeaderDict.getlistr!   úlist[str] | _DTc                 C  r   r   r   rp   r   r   r   rˆ   y  r‰   ú_Sentinel | _DTc                 C  s\   t |tƒr
| d¡}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.rd   rk   N)r'   rf   rg   r/   rh   r@   r"   r#   )r   r   rn   r{   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-ModifiedN)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ú(ú))rv   r   Údictrw   r   r   r   r   Ú__repr__ª  s   zHTTPHeaderDict.__repr__c                 C  s,   |D ]}|  |¡}|g|¢| j| ¡ < qd S r   )rˆ   r/   rh   )r   rq   r   rb   r   r   r   r`   ­  s   
þzHTTPHeaderDict._copy_fromc                 C  s   t | ƒƒ }| | ¡ |S r   )rv   r`   )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.rk   Nr   ©r/   rh   )r   r   r{   rb   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   rj   rk   N)r/   rh   rl   ri   r   r   r   rw   ¾  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 )Nrk   Fr”   )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.   ÚNotImplementedra   )r   rq   rx   r   r   r   Ú__ior__Ì  s
   
zHTTPHeaderDict.__ior__c                 C  s*   t |ƒ}|d u r
tS |  ¡ }| |¡ |S r   )r.   r—   r“   ra   ©r   rq   rx   Úresultr   r   r   Ú__or__Õ  s   
zHTTPHeaderDict.__or__c                 C  s.   t |ƒ}|d u r
tS t| ƒ|ƒ}| | ¡ |S r   )r.   r—   rv   ra   r™   r   r   r   Ú__ror__ß  s   
zHTTPHeaderDict.__ror__r   )rV   r&   r_   r   )r   r   rb   r   r
   r7   r   )r   r   r
   r7   )r   r%   r
   rZ   )rm   )r   r   rn   r   r
   r   )rq   r%   r
   rZ   rP   r   )r   r   rb   r   r}   rZ   r
   r7   )rƒ   r„   r_   r   r
   r7   )r   r   r
   r‡   )r   r   rn   r!   r
   rŠ   )r   r   rn   r‹   r
   rŠ   )r
   r   )r
   r   )rq   r   r
   r7   r^   )r
   rT   )r•   r   r–   r   r
   rZ   )rq   r%   r
   r   )rq   r%   r
   r   )'r   r   r   rQ   rR   r9   rE   r   rF   r]   ro   ry   rz   rG   rJ   r|   r‚   ra   r(   Úoverloadrˆ   r"   r#   r�   Ú
getheadersÚgetallmatchingheadersÚigetÚget_allr‘   r`   r“   rX   rw   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   rO   rT   r   r   r   r   r   Ú<module>   s2    


ýÿ
&]0