o
    'hC                     @  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   P/var/www/html/olx_land/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  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>   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   rM   r>   r   r   r   rN      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
   rI   )r
   r7   )r
   rO   )r   r   r   __doc____annotations__r9   r   rF   rG   rH   rK   rN   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   )rV   )r   rW   r   r   r   r9         
zHTTPHeaderDictItemView.__init__r0   c                 C  s   t t| j S r   )rA   rL   rV   	iteritemsr   r   r   r   rH      s   zHTTPHeaderDictItemView.__len__ typing.Iterator[tuple[str, str]]c                 C  s
   | j  S r   )rV   rY   r   r   r   r   rK      rX   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   rV   _has_value_for_header)r   r=   
passed_key
passed_valr   r   r   __contains__   s
   z#HTTPHeaderDictItemView.__contains__N)rW   r   r
   r7   rQ   r
   rZ   )r=   r%   r
   r[   )	r   r   r   rR   rS   r9   rH   rK   r`   r   r   r   r   rU      s   
 


rU   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/   NrW   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   rW   rb   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   re   r   r   r   rF      s   

zHTTPHeaderDict.__setitem__c                 C  s    | j |  }d|dd  S )N,    r/   ri   joinrj   r   r   r   r     s   zHTTPHeaderDict.__getitem__c                 C  s   | j | = d S r   r/   ri   r   r   r   r   rG     s   zHTTPHeaderDict.__delitem__r%   r[   c                 C  s   t |tr| | jv S dS )NF)r'   r   ri   r/   r   r   r   r   r`     s   
zHTTPHeaderDict.__contains__ defaultc                   s   t  ||S r   )r8   
setdefaultr   r   rq   r:   r   r   rr     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   )ri   ).0kvr   r   r   
<dictcomp>  s    z)HTTPHeaderDict.__eq__.<locals>.<dictcomp>)r.   type
itermerged)r   rt   maybe_constructableother_as_http_header_dictr   r   r   __eq__  s   zHTTPHeaderDict.__eq__c                 C  s   |  | S r   )r}   )r   rt   r   r   r   __ne__  s   zHTTPHeaderDict.__ne__r0   c                 C  s
   t | jS r   )rA   r/   r   r   r   r   rH     rX   zHTTPHeaderDict.__len__r   c                 c  s     | j  D ]}|d V  qd S )Nr   )r/   rM   )r   valsr   r   r   rK   !  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')]
        rf   r\   rk   N)r'   rg   rh   ri   r/   rr   rA   append)r   r   re   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%nPt|tjrG| D ]
\}}| || q;n:t|tj	rht
tj	tttf  |}|D ]
\}}| || q\nt|drt|dr| D ]
}| |||  qv| D ]
\}}| || qd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__
        rl   z/extend() takes at most 1 positional arguments (z given)r   r   r   r   N)rA   	TypeErrorr'   r   rY   r   r(   r)   itemsr+   r*   r,   r   r-   r   )r   r   rb   rt   r   re   r>   r   r   r   rd   O  s0   
zHTTPHeaderDict.extend	list[str]c                 C  r   r   r   r   r   r   r   getlistp     zHTTPHeaderDict.getlistr!   list[str] | _DTc                 C  r   r   r   rs   r   r   r   r   s  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.rl   N)r/   ri   r@   r"   r#   )r   r   rq   r   r   r   r   r   v  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-LengthDigestzLast-Modified)r   )r   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())ry   r   dictrz   r   r   r   r   __repr__  s   zHTTPHeaderDict.__repr__c                 C  s,   |D ]}| |}|g|| j| < qd S r   )r   r/   ri   )r   rt   r   re   r   r   r   rc     s   
zHTTPHeaderDict._copy_fromc                 C  s   t |  }||  |S r   )ry   rc   )r   cloner   r   r   copy  s   

zHTTPHeaderDict.copyrZ   c                 c  s>    | D ]}| j |  }|dd D ]	}|d |fV  qqdS )z8Iterate over all header lines, including duplicate ones.rl   Nr   ro   )r   r   r   re   r   r   r   rY     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   rk   rl   Nrm   rj   r   r   r   rz     s
   zHTTPHeaderDict.itermergedrU   c                 C  s   t | S r   )rU   r   r   r   r   r     s   zHTTPHeaderDict.itemsheader_namepotential_valuec                 C  s&   || v r|| j |  dd  v S dS )Nrl   Fro   )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.   NotImplementedrd   )r   rt   r{   r   r   r   __ior__  s
   
zHTTPHeaderDict.__ior__c                 C  s*   t |}|d u r
tS |  }|| |S r   )r.   r   r   rd   r   rt   r{   resultr   r   r   __or__  s   
zHTTPHeaderDict.__or__c                 C  s.   t |}|d u r
tS t| |}||  |S r   )r.   r   ry   rd   r   r   r   r   __ror__  s   
zHTTPHeaderDict.__ror__r   )rW   r&   rb   r   )r   r   re   r   r
   r7   r   )r   r   r
   r7   )r   r%   r
   r[   )rp   )r   r   rq   r   r
   r   )rt   r%   r
   r[   rQ   r   )r   r   re   r   r   r[   r
   r7   )r   r   rb   r   r
   r7   )r   r   r
   r   )r   r   rq   r!   r
   r   )r   r   rq   r   r
   r   )r
   r   )r
   r   )rt   r   r
   r7   ra   )r
   rU   )r   r   r   r   r
   r[   )rt   r%   r
   r   )rt   r%   r
   r   )'r   r   r   rR   rS   r9   rF   r   rG   r`   rr   r}   r~   rH   rK   r   r   rd   r(   overloadr   r"   r#   r   
getheadersgetallmatchingheadersigetget_allr   rc   r   rY   rz   r   r]   r   r   r   rT   r   r   r:   r   r      sJ   
 !









#!









	
)r$   r%   r
   r&   )"
__future__r   r(   collectionsr   enumr   r   	threadingr   TYPE_CHECKINGr   typing_extensionsr   r	   __all__TypeVarr   r    r!   Unionr)   r   r+   r,   r   r"   r.   GenericMutableMappingr   rP   rU   r   r   r   r   r   <module>   s2    



&]0