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   SC:\Users\User\Downloads\Proyecto_IoT\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  s    | j |  }d|dd  S )N,    r/   rf   joinrg   r   r   r   r     s   zHTTPHeaderDict.__getitem__c                 C  s   | j | = d S r   r/   rf   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   rf   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   )rf   ).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')]
        rc   r[   rh   N)r'   rd   re   rf   r/   ro   rA   append)r   r   rb   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__
        ri   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   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   rp   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.ri   N)r/   rf   r@   r"   r#   )r   r   rn   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-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())rv   r   dictrw   r   r   r   r   __repr__  s   zHTTPHeaderDict.__repr__c                 C  s,   |D ]}| |}|g|| j| < qd S r   )r   r/   rf   )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.ri   Nr   rl   )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   rh   ri   Nrj   rg   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 )Nri   Frl   )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