a
    &ñ»jÁP  ã                   @  sP  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ	 d dl
mZ d dlmZ d dlmZmZmZmZmZmZ d dlmZmZ d	d
lmZmZ d	dlmZ er¼ddlmZ ddlm Z  dZ!G dd„ dƒZ"G dd„ dƒZ#G dd„ de	j$eƒZ%dd„ Z&dd„ Z'd)dd„Z(dd„ Z)dd„ Z*d d!„ Z+d*d#d$„Z,d%d&„ Z-G d'd(„ d(ee.e.f ƒZ/dS )+é    )ÚannotationsN)ÚMessage©Ú	cookiejar)ÚCookie)ÚMorsel)ÚTYPE_CHECKINGÚAnyÚDictÚIteratorÚMutableMappingÚOptional)ÚurlparseÚ
urlunparseé   )ÚCookieConflictErrorÚCookieError)ÚCookieTypesé   )ÚRequest)ÚResponse)ÚCookiesc                   @  s"   e Zd Zddœdd„Zdd„ ZdS )ÚMockResponser   )Úresponsec                 C  s
   || _ d S ©N)Ú_original_response)Úselfr   © r   úAE:\soccer\ml_env\Lib\site-packages\tls_requests/models/cookies.pyÚ__init__   s    zMockResponse.__init__c                 C  s(   t ƒ }| jj ¡ D ]\}}|||< q|S r   )r   r   ÚheadersÚitems)r   ÚinfoÚkÚvr   r   r   r"      s    
zMockResponse.infoN)Ú__name__Ú
__module__Ú__qualname__r   r"   r   r   r   r   r      s   r   c                   @  sˆ   e Zd Zddœdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Z	ddd„Z
dd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZdS )ÚMockRequestr   )Úrequestc                 C  s*   i | _ || _|j| _tt|jƒƒj| _d S r   )	Ú_new_headersÚ_requestr    Ú_headersr   ÚstrÚurlÚschemeÚtype©r   r)   r   r   r   r   &   s    zMockRequest.__init__c                 C  s   | j S r   )r0   ©r   r   r   r   Úget_type,   s    zMockRequest.get_typec                 C  s   t t| jjƒƒjS r   )r   r-   r+   r.   Únetlocr2   r   r   r   Úget_host/   s    zMockRequest.get_hostc                 C  s   |   ¡ S r   ©r5   r2   r   r   r   Úget_origin_req_host2   s    zMockRequest.get_origin_req_hostc                 C  sP   | j  d¡st| jjƒS | j d }tt| jjƒƒ}t|j||j|j	|j
|jgƒS )NÚHost)r,   Úgetr-   r+   r.   r   r   r/   ÚpathÚparamsÚqueryÚfragment)r   ÚhostÚparsedr   r   r   Úget_full_url5   s    
úÿzMockRequest.get_full_urlc                 C  s   dS ©NTr   r2   r   r   r   Úis_unverifiableJ   s    zMockRequest.is_unverifiablec                 C  s   || j v p|| jv S r   )r,   r*   ©r   Únamer   r   r   Ú
has_headerM   s    zMockRequest.has_headerNc                 C  s   | j  || j ||¡¡S r   )r,   r9   r*   )r   rD   Údefaultr   r   r   Ú
get_headerP   s    zMockRequest.get_headerc                 C  s   || j |< d S r   ©r*   ©r   rD   Úvaluer   r   r   Úadd_unredirected_headerS   s    z#MockRequest.add_unredirected_headerc                 C  s   | j S r   rH   r2   r   r   r   Úget_new_headersV   s    zMockRequest.get_new_headersc                 C  s   |   ¡ S r   )rB   r2   r   r   r   ÚunverifiableY   s    zMockRequest.unverifiablec                 C  s   |   ¡ S r   )r7   r2   r   r   r   Úorigin_req_host]   s    zMockRequest.origin_req_hostc                 C  s   |   ¡ S r   r6   r2   r   r   r   r>   a   s    zMockRequest.host)N)r%   r&   r'   r   r3   r5   r7   r@   rB   rE   rG   rK   rL   ÚpropertyrM   rN   r>   r   r   r   r   r(   %   s    


r(   c                      sô   e Zd ZdZd6dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zd7dd„Z‡ fdd„Zdd„ Zdd „ Zd!d"„ Z‡ fd#d$„Zd8d%d%d&d'œ‡ fd(d)„Zd9d*d+„Zd:d,d-„Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Z‡  ZS );ÚRequestsCookieJara¶  Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict
    interface.

    This is the CookieJar we create by default for requests and sessions that
    don't specify one, since some clients may expect response.cookies and
    session.cookies to support dict operations.

    Requests does not use the dict interface internally; it's just for
    compatibility with external client code. All requests code should work
    out of the box with externally provided instances of ``CookieJar``, e.g.
    ``LWPCookieJar`` and ``FileCookieJar``.

    Unlike a regular CookieJar, this class is pickleable.

    .. warning:: dictionary operations that are normally O(1) may be O(n).
    Nc                 C  s0   z|   |||¡}|W S  ty*   | Y S 0 dS )zãDict-like get() that also supports optional domain and path args in
        order to resolve naming collisions from using one cookie jar over
        multiple domains.

        .. warning:: operation is O(n), not O(1).
        N)Ú_find_no_duplicatesÚKeyError)r   rD   rF   Údomainr:   rJ   r   r   r   r9   x   s
    zRequestsCookieJar.getc                 K  s\   |du r(t | || d¡| d¡d� dS t|tƒr<t|ƒ}nt||fi |¤Ž}|  |¡ |S )z°Dict-like set() that also supports optional domain and path args in
        order to resolve naming collisions from using one cookie jar over
        multiple domains.
        NrS   r:   ©rS   r:   )Úremove_cookie_by_namer9   Ú
isinstancer   Úmorsel_to_cookieÚcreate_cookieÚ
set_cookie)r   rD   rJ   ÚkwargsÚcr   r   r   Úset…   s    


zRequestsCookieJar.setc                 c  s   t | ƒD ]}|jV  qdS )z”Dict-like iterkeys() that returns an iterator of names of cookies
        from the jar.

        .. seealso:: itervalues() and iteritems().
        N)ÚiterrD   ©r   Úcookier   r   r   Úiterkeys–   s    zRequestsCookieJar.iterkeysc                 C  s   t |  ¡ ƒS )zƒDict-like keys() that returns a list of names of cookies from the
        jar.

        .. seealso:: values() and items().
        )Úlistr`   r2   r   r   r   ÚkeysŸ   s    zRequestsCookieJar.keysc                 c  s   t | ƒD ]}|jV  qdS )z•Dict-like itervalues() that returns an iterator of values of cookies
        from the jar.

        .. seealso:: iterkeys() and iteritems().
        N)r]   rJ   r^   r   r   r   Ú
itervalues§   s    zRequestsCookieJar.itervaluesc                 C  s   t |  ¡ ƒS )z„Dict-like values() that returns a list of values of cookies from the
        jar.

        .. seealso:: keys() and items().
        )ra   rc   r2   r   r   r   Úvalues°   s    zRequestsCookieJar.valuesc                 c  s    t | ƒD ]}|j|jfV  qdS )z•Dict-like iteritems() that returns an iterator of name-value tuples
        from the jar.

        .. seealso:: iterkeys() and itervalues().
        N)r]   rD   rJ   r^   r   r   r   Ú	iteritems¸   s    zRequestsCookieJar.iteritemsc                 C  s   t |  ¡ ƒS )zõDict-like items() that returns a list of name-value tuples from the
        jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a
        vanilla python dict of key value pairs.

        .. seealso:: keys() and values().
        )ra   re   r2   r   r   r   r!   Á   s    zRequestsCookieJar.itemsc                 C  s,   g }t | ƒD ]}|j|vr| |j¡ q|S )z2Utility method to list all the domains in the jar.©r]   rS   Úappend©r   Údomainsr_   r   r   r   Úlist_domainsÊ   s
    
zRequestsCookieJar.list_domainsc                 C  s,   g }t | ƒD ]}|j|vr| |j¡ q|S )z0Utility method to list all the paths in the jar.)r]   r:   rg   )r   Úpathsr_   r   r   r   Ú
list_pathsÒ   s
    
zRequestsCookieJar.list_pathsc                 C  s<   g }t | ƒD ]*}|jdur*|j|v r* dS | |j¡ qdS )zvReturns True if there are multiple domains in the jar.
        Returns False otherwise.

        :rtype: bool
        NTFrf   rh   r   r   r   Úmultiple_domainsÚ   s    z"RequestsCookieJar.multiple_domainsc                 C  sF   i }t | ƒD ]4}|du s"|j|kr|du s4|j|kr|j||j< q|S )z¾Takes as an argument an optional domain and path and returns a plain
        old Python dict of name-value pairs of cookies that meet the
        requirements.

        :rtype: dict
        N)r]   rS   r:   rJ   rD   )r   rS   r:   Ú
dictionaryr_   r   r   r   Úget_dictç   s
    $zRequestsCookieJar.get_dictc                   s(   zt ƒ  |¡W S  ty"   Y dS 0 d S rA   )ÚsuperÚ__contains__r   rC   ©Ú	__class__r   r   rq   ô   s    zRequestsCookieJar.__contains__c                 C  s
   |   |¡S )zÿDict-like __getitem__() for compatibility with client code. Throws
        exception if there are more than one cookie with name. In that case,
        use the more explicit get() method instead.

        .. warning:: operation is O(n), not O(1).
        )rQ   rC   r   r   r   Ú__getitem__ú   s    zRequestsCookieJar.__getitem__c                 C  s   |   ||¡ dS )zÓDict-like __setitem__ for compatibility with client code. Throws
        exception if there is already a cookie of that name in the jar. In that
        case, use the more explicit set() method instead.
        N©r\   rI   r   r   r   Ú__setitem__  s    zRequestsCookieJar.__setitem__c                 C  s   t | |ƒ dS )zqDeletes a cookie given a name. Wraps ``http.cookiejar.CookieJar``'s
        ``remove_cookie_by_name()``.
        N)rU   rC   r   r   r   Ú__delitem__
  s    zRequestsCookieJar.__delitem__c                   sN   t |jdƒr4|j d¡r4|j d¡r4|j dd¡|_tƒ j|g|¢R i |¤ŽS )NÚ
startswithú"z\"Ú )ÚhasattrrJ   rx   ÚendswithÚreplacerp   rY   )r   r_   ÚargsrZ   rr   r   r   rY     s    $zRequestsCookieJar.set_cookier	   ÚNone)ÚotherrZ   Úreturnc                   sV   |dur<t |tjƒr0|D ]}|  t |¡¡ qntƒ  |¡ |rRtƒ jf i |¤Ž dS )zAUpdates this jar with cookies from another CookieJar or dict-likeN)rV   Ú	cookielibÚ	CookieJarrY   Úcopyrp   Úupdate)r   r€   rZ   r_   rr   r   r   r…     s    zRequestsCookieJar.updatec                 C  sd   t | ƒD ]<}|j|kr|du s(|j|kr|du s:|j|kr|j  S qtd|›d|›d|›�ƒ‚dS )aÔ  Requests uses this method internally to get cookie values.

        If there are conflicting cookies, _find arbitrarily chooses one.
        See _find_no_duplicates if you want an exception thrown if there are
        conflicting cookies.

        :param name: a string containing name of cookie
        :param domain: (optional) string containing domain of cookie
        :param path: (optional) string containing path of cookie
        :return: cookie.value
        Núname=ú	, domain=ú, path=)r]   rD   rS   r:   rJ   rR   )r   rD   rS   r:   r_   r   r   r   Ú_find   s    
zRequestsCookieJar._findc                 C  s†   d}t | ƒD ]N}|j|kr|du s,|j|kr|du s>|j|kr|durTtd|›�ƒ‚|j}q|durh|S td|›d|›d|›�ƒ‚dS )aù  Both ``__get_item__`` and ``get`` call this function: it's never
        used elsewhere in Requests.

        :param name: a string containing name of cookie
        :param domain: (optional) string containing domain of cookie
        :param path: (optional) string containing path of cookie
        :raises KeyError: if cookie is not found
        :raises CookieConflictError: if there are multiple cookies
            that match name and optionally domain and path
        :return: cookie.value
        Nz&There are multiple cookies with name, r†   r‡   rˆ   )r]   rD   rS   r:   r   rJ   rR   )r   rD   rS   r:   ÚtoReturnr_   r   r   r   rQ   4  s    
z%RequestsCookieJar._find_no_duplicatesc                 C  s   | j  ¡ }| d¡ |S )ú4Unlike a normal CookieJar, this class is pickleable.Ú_cookies_lock)Ú__dict__r„   Úpop)r   Ústater   r   r   Ú__getstate__O  s    

zRequestsCookieJar.__getstate__c                 C  s,   | j  |¡ d| j vr(ddl}| ¡ | _dS )r‹   rŒ   r   N)r�   r…   Ú	threadingÚRLockrŒ   )r   r�   r‘   r   r   r   Ú__setstate__V  s    
zRequestsCookieJar.__setstate__c                 C  s"   t ƒ }| |  ¡ ¡ | | ¡ |S )z(Return a copy of this RequestsCookieJar.)rP   Ú
set_policyÚ
get_policyr…   )r   Únew_cjr   r   r   r„   ^  s    
zRequestsCookieJar.copyc                 C  s   t | ddƒS )z&Return the CookiePolicy instance used.Ú_policyN)Úgetattrr2   r   r   r   r•   e  s    zRequestsCookieJar.get_policy)NNN)NN)N)NN)NN)r%   r&   r'   Ú__doc__r9   r\   r`   rb   rc   rd   re   r!   rj   rl   rm   ro   rq   rt   rv   rw   rY   r…   r‰   rQ   r�   r“   r„   r•   Ú__classcell__r   r   rr   r   rP   f   s2   
				
	

rP   c                 C  s    t |ƒ}t|ƒ}|  ||¡ dS )zøExtract the cookies from the response into a CookieJar.

    :param cookiejar: http.cookiejar.CookieJar (not necessarily a RequestsCookieJar)
    :param request: our own requests.Request object
    :param response: tls_requests.Response object
    N)r(   r   Úextract_cookies)r   r   r)   r   r   r   Úextract_cookies_to_jarj  s    rœ   c                 C  s    t |ƒ}|  |¡ | ¡  d¡S )zj
    Produce an appropriate Cookie header string to be sent with `request`, or None.

    :rtype: str
    r   )r(   Úadd_cookie_headerrL   r9   )Újarr)   Úrr   r   r   Úget_cookie_headerv  s    
r    c                 C  sz   g }| D ]N}|j |krq|dur,||jkr,q|dur@||jkr@q| |j|j|j f¡ q|D ]\}}}|  |||¡ q\dS )zjUnsets a cookie by key, by default over all domains and paths.

    Wraps CookieJar.clear(), is O(n).
    N)rD   rS   r:   rg   Úclear)r   rD   rS   r:   Ú
clearablesr_   r   r   r   rU   �  s    
rU   c                 C  sN   | d u rd S t | dƒr|  ¡ S t | ¡}| ¡  | D ]}| t |¡¡ q4|S )Nr„   )r{   r„   r¡   rY   )rž   Únew_jarr_   r   r   r   Ú_copy_cookie_jar”  s    

r¤   c                 K  s¦   d| |ddddddddddiddœ}t |ƒt |ƒ }|rJtd	t|ƒ› �ƒ‚| |¡ t|d
 ƒ|d< t|d ƒ|d< |d  d¡|d< t|d ƒ|d< tjf i |¤ŽS )zÉMake a cookie from underspecified parameters.

    By default, the pair of `key` and `value` will be set for the domain ''
    and sent on every request (this is sometimes called a "supercookie").
    r   Nrz   ú/FTÚHttpOnly)ÚversionrD   rJ   ÚportrS   r:   ÚsecureÚexpiresÚdiscardÚcommentÚcomment_urlÚrestÚrfc2109z2create_cookie() got unexpected keyword arguments: r¨   Úport_specifiedrS   Údomain_specifiedÚ.Údomain_initial_dotr:   Úpath_specified)r\   r   ra   r…   Úboolrx   r‚   r   )rD   rJ   rZ   ÚresultÚbadargsr   r   r   rX   £  s.    ò
rX   c                 C  sÆ   d}| d rRzt t ¡ t | d ƒ ƒ}W qt tyN   td| d › d�ƒ‚Y qt0 n"| d rtd}t t | d |¡¡}t| d t| d ƒd| d	 || j	| d
 dd| d idt| d ƒ| j
| d pÀdd�S )zBConvert a Morsel object into a Cookie containing the one k/v pair.Nzmax-agez	max-age: z must be integerrª   z%a, %d-%b-%Y %H:%M:%S GMTr¬   FrS   r:   r¦   Úhttponlyr©   r§   r   )r¬   r­   r«   rS   rª   rD   r:   r¨   r®   r¯   r©   rJ   r§   )ÚintÚtimeÚ
ValueErrorr   ÚcalendarÚtimegmÚstrptimerX   rµ   ÚkeyrJ   )Úmorselrª   Útime_templater   r   r   rW   Ç  s0    



órW   Tc                 C  sR   |du rt ƒ }| durNdd„ |D ƒ}| D ]$}|s8||vr(| t|| | ƒ¡ q(|S )aC  Returns a CookieJar from a key/value dictionary.

    :param cookie_dict: Dict of key/values to insert into CookieJar.
    :param cookiejar: (optional) A cookiejar to add the cookies to.
    :param overwrite: (optional) If False, will not replace cookies
        already in the jar with new ones.
    :rtype: CookieJar
    Nc                 S  s   g | ]
}|j ‘qS r   ©rD   ©Ú.0r_   r   r   r   Ú
<listcomp>ñ  ó    z'cookiejar_from_dict.<locals>.<listcomp>)rP   rY   rX   )Úcookie_dictr   Ú	overwriteÚnames_from_jarrD   r   r   r   Úcookiejar_from_dictä  s    	rÊ   c                 C  st   t | tjƒstdƒ‚t |tƒr.t|| dd�} nBt |tjƒrpz|  |¡ W n& tyn   |D ]}|  |¡ qZY n0 | S )zÒAdd cookies to cookiejar and returns a merged CookieJar.

    :param cookiejar: CookieJar object to add the cookies to.
    :param cookies: Dictionary or CookieJar object to be added.
    :rtype: CookieJar
    z!You can only merge into CookieJarF)r   rÈ   )	rV   r‚   rƒ   r»   ÚdictrÊ   r…   ÚAttributeErrorrY   )r   ÚcookiesÚcookie_in_jarr   r   r   Úmerge_cookiesù  s    
rÏ   c                   @  s"  e Zd Zd9dddœdd„Zd: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d„Zd<dddddœdd„Z	d=dddœdd „Z
d>dddœd!d"„Zd#dœ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/d0„Zd1dœd2d3„Zd4dœd5d6„Zddœd7d8„ZdS )?r   NzOptional[CookieTypes]r   )rÍ   r�   c                 C  s   |   |¡| _d S r   )Ú_prepare_cookiejarr   ©r   rÍ   r   r   r   r     s    zCookies.__init__rP   c                 C  sª   t || jƒr|jS t |ttttfƒr¤tƒ }t |tƒr<| ¡ n|}|D ]Z}t |ttfƒrDt	|ƒdkrD|d |d  }}t |t
tfƒrŠt|ƒ}| t|ƒt|ƒ¡ qD|S tƒ S )Nr   r   r   )rV   rs   r   rË   Útuplera   r\   rP   r!   ÚlenÚfloatr¹   r-   )r   rÍ   r   Zcookie_itemsÚitemr#   r$   r   r   r   rÐ     s    zCookies._prepare_cookiejarr   r   )r   r)   r�   c                 C  s   t | j||ƒ d S r   )rœ   r   )r   r   r)   r   r   r   r›   %  s    zCookies.extract_cookiesr-   )r)   r�   c                 C  s   t | j|ƒS r   )r    r   r1   r   r   r   r    (  s    zCookies.get_cookie_headerzOptional[Cookie])r�   c                 K  s`   |d u r*t | j|| d¡| d¡d� d S t|tƒr>t|ƒ}nt||fi |¤Ž}| j |¡ |S )NrS   r:   rT   )rU   r   r9   rV   r   rW   rX   rY   )r   rD   rJ   rZ   r_   r   r   r   r\   +  s    

zCookies.setr	   c                 C  s   | j  ||||¡S r   ©r   r9   )r   rD   rF   rS   r:   r   r   r   r9   8  s    zCookies.getzOptional[str])rD   rS   r:   r�   c                 C  s   t | j|||d�S )NrT   )rU   r   )r   rD   rS   r:   r   r   r   Údelete;  s    zCookies.deleterT   c                 C  s4   g }|r|  |¡ |r$|r$|  |¡ | jj|Ž  d S r   )rg   r   r¡   )r   rS   r:   r~   r   r   r   r¡   >  s    

zCookies.clearc                 C  s   | j  |  |¡¡ d S r   )r   r…   rÐ   rÑ   r   r   r   r…   G  s    zCookies.updatez	'Cookies'c                 C  s   |   ¡ }t| jƒ|_|S r   )rs   r¤   r   )r   Úretr   r   r   r„   J  s    zCookies.copy)rD   rJ   r�   c                 C  s   |   ||¡ d S r   ru   rI   r   r   r   rv   O  s    zCookies.__setitem__)rD   r�   c                 C  s   | j  |¡pdS )Nrz   rÖ   rC   r   r   r   rt   R  s    zCookies.__getitem__c                 C  s   |   |¡ d S r   )r×   rC   r   r   r   rw   U  s    zCookies.__delitem__r¹   c                 C  s
   t | jƒS r   )rÓ   r   r2   r   r   r   Ú__len__X  s    zCookies.__len__zIterator[str]c                 C  s   dd„ | j D ƒS )Nc                 s  s   | ]}|j V  qd S r   rÂ   rÃ   r   r   r   Ú	<genexpr>\  rÆ   z#Cookies.__iter__.<locals>.<genexpr>r   r2   r   r   r   Ú__iter__[  s    zCookies.__iter__rµ   c                 C  s   | j D ]} dS dS )NTFr   )r   Ú_r   r   r   Ú__bool__^  s    
zCookies.__bool__c                 C  s&   d  dd„ | jD ƒ¡}d| jj|f S )Nz, c                 S  s   g | ]}t |ƒ‘qS r   )ÚreprrÃ   r   r   r   rÅ   d  rÆ   z$Cookies.__repr__.<locals>.<listcomp>z<%s[%s]>)Újoinr   rs   r%   )r   Zcookiejar_reprr   r   r   Ú__repr__c  s    zCookies.__repr__)N)N)NNN)NN)NN)N)r%   r&   r'   r   rÐ   r›   r    r\   r9   r×   r¡   r…   r„   rv   rt   rw   rÙ   rÛ   rÝ   rà   r   r   r   r   r     s"   	r   )NN)NT)0Ú
__future__r   r¼   r„   rº   Úemail.messager   Úhttpr   r‚   Úhttp.cookiejarr   Úhttp.cookiesr   Útypingr   r	   r
   r   r   r   Úurllib.parser   r   Ú
exceptionsr   r   Útypesr   r)   r   r   r   Ú__all__r   r(   rƒ   rP   rœ   r    rU   r¤   rX   rW   rÊ   rÏ   r-   r   r   r   r   r   Ú<module>   s:    A  
$
