AlkantarClanX12

Your IP : 18.224.31.90


Current Path : /opt/alt/python37/lib/python3.7/site-packages/requests/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/requests/__pycache__/cookies.cpython-37.pyc

B

0��_�G�@s�dZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZyddlZWne
k
rlddlZYnXGdd�de�ZGdd	�d	e�Zd
d�Zdd
�Zddd�ZGdd�de�ZGdd�deje�Zdd�Zdd�Zdd�Zd dd�Zdd�ZdS)!z�
requests.cookies
~~~~~~~~~~~~~~~~

Compatibility code to be able to use `cookielib.CookieJar` with requests.

requests.utils imports from here, so be careful with imports.
�N�)�to_native_string)�	cookielib�urlparse�
urlunparse�Morsel�MutableMappingc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�Zedd��Zedd��Zedd��ZdS) �MockRequesta�Wraps a `requests.Request` to mimic a `urllib2.Request`.

    The code in `cookielib.CookieJar` expects this interface in order to correctly
    manage cookie policies, i.e., determine whether a cookie can be set, given the
    domains of the request and the cookie.

    The original request object is read-only. The client is responsible for collecting
    the new headers via `get_new_headers()` and interpreting them appropriately. You
    probably want `get_cookie_header`, defined below.
    cCs ||_i|_t|jj�j|_dS)N)�_r�_new_headersr�url�scheme�type)�self�request�r�A/opt/alt/python37/lib/python3.7/site-packages/requests/cookies.py�__init__%szMockRequest.__init__cCs|jS)N)r)rrrr�get_type*szMockRequest.get_typecCst|jj�jS)N)rr
r�netloc)rrrr�get_host-szMockRequest.get_hostcCs|��S)N)r)rrrr�get_origin_req_host0szMockRequest.get_origin_req_hostcCsT|jj�d�s|jjSt|jjddd�}t|jj�}t|j||j|j	|j
|jg�S)NZHostzutf-8)�encoding)r
�headers�getrrrrr
�path�params�query�fragment)r�host�parsedrrr�get_full_url3szMockRequest.get_full_urlcCsdS)NTr)rrrr�is_unverifiableAszMockRequest.is_unverifiablecCs||jjkp||jkS)N)r
rr)r�namerrr�
has_headerDszMockRequest.has_headerNcCs|jj�||j�||��S)N)r
rrr)rr#�defaultrrr�
get_headerGszMockRequest.get_headercCstd��dS)zMcookielib has no legitimate use for this method; add it back if you find one.z=Cookie headers should be added with add_unredirected_header()N)�NotImplementedError)r�key�valrrr�
add_headerJszMockRequest.add_headercCs||j|<dS)N)r)rr#�valuerrr�add_unredirected_headerNsz#MockRequest.add_unredirected_headercCs|jS)N)r)rrrr�get_new_headersQszMockRequest.get_new_headerscCs|��S)N)r")rrrr�unverifiableTszMockRequest.unverifiablecCs|��S)N)r)rrrr�origin_req_hostXszMockRequest.origin_req_hostcCs|��S)N)r)rrrrr\szMockRequest.host)N)�__name__�
__module__�__qualname__�__doc__rrrrr!r"r$r&r*r,r-�propertyr.r/rrrrrr	s

r	c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�MockResponsez�Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.

    ...what? Basically, expose the parsed HTTP headers from the server response
    the way `cookielib` expects to see them.
    cCs
||_dS)z�Make a MockResponse for `cookielib` to read.

        :param headers: a httplib.HTTPMessage or analogous carrying the headers
        N)�_headers)rrrrrrhszMockResponse.__init__cCs|jS)N)r6)rrrr�infooszMockResponse.infocCs|j�|�dS)N)r6�
getheaders)rr#rrrr8rszMockResponse.getheadersN)r0r1r2r3rr7r8rrrrr5asr5cCs8t|d�r|jsdSt|�}t|jj�}|�||�dS)z�Extract the cookies from the response into a CookieJar.

    :param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
    :param request: our own requests.Request object
    :param response: urllib3.HTTPResponse object
    �_original_responseN)�hasattrr9r	r5�msgZextract_cookies)�jarr�response�req�resrrr�extract_cookies_to_jarvs
r@cCs t|�}|�|�|���d�S)zj
    Produce an appropriate Cookie header string to be sent with `request`, or None.

    :rtype: str
    �Cookie)r	Zadd_cookie_headerr-r)r<r�rrrr�get_cookie_header�s
rCcCs�g}xV|D]N}|j|krq
|dk	r.||jkr.q
|dk	rB||jkrBq
|�|j|j|jf�q
Wx |D]\}}}|�|||�qbWdS)zkUnsets a cookie by name, by default over all domains and paths.

    Wraps CookieJar.clear(), is O(n).
    N)r#�domainr�append�clear)�	cookiejarr#rDrZ
clearables�cookierrr�remove_cookie_by_name�s

rIc@seZdZdZdS)�CookieConflictErrorz�There are two cookies that meet the criteria specified in the cookie jar.
    Use .get and .set and include domain and path args in order to be more specific.
    N)r0r1r2r3rrrrrJ�srJcs�eZdZdZd3dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zd4dd�Z�fdd�Zdd�Zdd �Zd!d"�Z�fd#d$�Z�fd%d&�Zd5d'd(�Zd6d)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z�ZS)7�RequestsCookieJara�Compatibility class; is a cookielib.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).
    NcCs(y|�|||�Stk
r"|SXdS)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)rr#r%rDrrrrr�szRequestsCookieJar.getcKsX|dkr(t|||�d�|�d�d�dSt|t�r<t|�}nt||f|�}|�|�|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.
        NrDr)rDr)rIr�
isinstancer�morsel_to_cookie�
create_cookie�
set_cookie)rr#r+�kwargs�crrr�set�s


zRequestsCookieJar.setccsxt|�D]}|jVq
WdS)z�Dict-like iterkeys() that returns an iterator of names of cookies
        from the jar.

        .. seealso:: itervalues() and iteritems().
        N)�iterr#)rrHrrr�iterkeys�szRequestsCookieJar.iterkeyscCst|���S)z�Dict-like keys() that returns a list of names of cookies from the
        jar.

        .. seealso:: values() and items().
        )�listrV)rrrr�keys�szRequestsCookieJar.keysccsxt|�D]}|jVq
WdS)z�Dict-like itervalues() that returns an iterator of values of cookies
        from the jar.

        .. seealso:: iterkeys() and iteritems().
        N)rUr+)rrHrrr�
itervalues�szRequestsCookieJar.itervaluescCst|���S)z�Dict-like values() that returns a list of values of cookies from the
        jar.

        .. seealso:: keys() and items().
        )rWrY)rrrr�values�szRequestsCookieJar.valuesccs$xt|�D]}|j|jfVq
WdS)z�Dict-like iteritems() that returns an iterator of name-value tuples
        from the jar.

        .. seealso:: iterkeys() and itervalues().
        N)rUr#r+)rrHrrr�	iteritems�szRequestsCookieJar.iteritemscCs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().
        )rWr[)rrrr�itemsszRequestsCookieJar.itemscCs0g}x&t|�D]}|j|kr|�|j�qW|S)z2Utility method to list all the domains in the jar.)rUrDrE)r�domainsrHrrr�list_domainss

zRequestsCookieJar.list_domainscCs0g}x&t|�D]}|j|kr|�|j�qW|S)z0Utility method to list all the paths in the jar.)rUrrE)r�pathsrHrrr�
list_pathss

zRequestsCookieJar.list_pathscCs>g}x4t|�D](}|jdk	r*|j|kr*dS|�|j�qWdS)zvReturns True if there are multiple domains in the jar.
        Returns False otherwise.

        :rtype: bool
        NTF)rUrDrE)rr]rHrrr�multiple_domainssz"RequestsCookieJar.multiple_domainscCsJi}x@t|�D]4}|dks$|j|kr|dks6|j|kr|j||j<qW|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)rUrDrr+r#)rrDr�
dictionaryrHrrr�get_dict+szRequestsCookieJar.get_dictcs*ytt|��|�Stk
r$dSXdS)NT)�superrK�__contains__rJ)rr#)�	__class__rrre;szRequestsCookieJar.__contains__cCs
|�|�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).
        )rL)rr#rrr�__getitem__AszRequestsCookieJar.__getitem__cCs|�||�dS)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)rT)rr#r+rrr�__setitem__JszRequestsCookieJar.__setitem__cCst||�dS)zlDeletes a cookie given a name. Wraps ``cookielib.CookieJar``'s
        ``remove_cookie_by_name()``.
        N)rI)rr#rrr�__delitem__QszRequestsCookieJar.__delitem__csLt|jd�r4|j�d�r4|j�d�r4|j�dd�|_tt|�j|f|�|�S)N�
startswith�"z\"�)r:r+rj�endswith�replacerdrKrQ)rrH�argsrR)rfrrrQWs$zRequestsCookieJar.set_cookiecs@t|tj�r,x.|D]}|�t�|��qWntt|��|�dS)zAUpdates this jar with cookies from another CookieJar or dict-likeN)rNr�	CookieJarrQ�copyrdrK�update)r�otherrH)rfrrrr\s
zRequestsCookieJar.updatecCs\xDt|�D]8}|j|kr
|dks*|j|kr
|dks<|j|kr
|jSq
Wtd|||f��dS)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
        Nzname=%r, domain=%r, path=%r)rUr#rDrr+rM)rr#rDrrHrrr�_findds

zRequestsCookieJar._findcCs|d}xXt|�D]L}|j|kr|dks.|j|kr|dks@|j|kr|dk	rTtd|��|j}qW|rf|Std|||f��dS)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, %rzname=%r, domain=%r, path=%r)rUr#rDrrJr+rM)rr#rDrZtoReturnrHrrrrLxs

z%RequestsCookieJar._find_no_duplicatescCs|j��}|�d�|S)z4Unlike a normal CookieJar, this class is pickleable.�
_cookies_lock)�__dict__rq�pop)r�staterrr�__getstate__�s

zRequestsCookieJar.__getstate__cCs$|j�|�d|jkr t��|_dS)z4Unlike a normal CookieJar, this class is pickleable.ruN)rvrr�	threading�RLockru)rrxrrr�__setstate__�s
zRequestsCookieJar.__setstate__cCs"t�}|�|���|�|�|S)z(Return a copy of this RequestsCookieJar.)rKZ
set_policy�
get_policyrr)rZnew_cjrrrrq�s
zRequestsCookieJar.copycCs|jS)z&Return the CookiePolicy instance used.)Z_policy)rrrrr}�szRequestsCookieJar.get_policy)NNN)NN)NN)NN)r0r1r2r3rrTrVrXrYrZr[r\r^r`rarcrergrhrirQrrrtrLryr|rqr}�
__classcell__rr)rfrrK�s2
				
	

rKcCsR|dkrdSt|d�r|��St�|�}|��x|D]}|�t�|��q6W|S)Nrq)r:rqrFrQ)r<Znew_jarrHrrr�_copy_cookie_jar�s


rcKs�d||ddddddddddidd�
}t|�t|�}|rLd	}t|t|���|�|�t|d
�|d<t|d�|d
<|d�d�|d<t|d�|d<tjf|�S)z�Make a cookie from underspecified parameters.

    By default, the pair of `name` and `value` will be set for the domain ''
    and sent on every request (this is sometimes called a "supercookie").
    rNrl�/FT�HttpOnly)
�versionr#r+�portrDr�secure�expires�discard�comment�comment_url�rest�rfc2109z4create_cookie() got unexpected keyword arguments: %sr�Zport_specifiedrDZdomain_specified�.Zdomain_initial_dotrZpath_specified)rT�	TypeErrorrWrr�boolrjrrA)r#r+rR�resultZbadargs�errrrrrP�s.
rPcCs�d}|drPytt��t|d��}Wqrtk
rLtd|d��YqrXn"|drrd}t�t�|d|��}t|dt|d�d|d||j	|d	dd
|didt|d�|j
|d
p�dd�
S)zBConvert a Morsel object into a Cookie containing the one k/v pair.Nzmax-agezmax-age: %s must be integerr�z%a, %d-%b-%Y %H:%M:%S GMTr�FrDrr�Zhttponlyr�r�r)
r�r�r�rDr�r#rr�r�r�r�r+r�)�int�time�
ValueErrorr��calendar�timegm�strptimerPr�r(r+)Zmorselr�Z
time_templaterrrrO�s0


rOTcCsV|dkrt�}|dk	rRdd�|D�}x,|D]$}|s:||kr*|�t|||��q*W|S)aCReturns 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
    NcSsg|]
}|j�qSr)r#)�.0rHrrr�
<listcomp>	sz'cookiejar_from_dict.<locals>.<listcomp>)rKrQrP)Zcookie_dictrG�	overwriteZnames_from_jarr#rrr�cookiejar_from_dict�s	
r�cCszt|tj�std��t|t�r.t||dd�}nHt|tj�rvy|�|�Wn,tk
rtx|D]}|�|�q^WYnX|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)rGr�)	rNrrpr��dictr�rr�AttributeErrorrQ)rGZcookiesZ
cookie_in_jarrrr�
merge_cookiess

r�)NN)NT)r3rqr�r�Z_internal_utilsr�compatrrrrrrz�ImportErrorZdummy_threading�objectr	r5r@rCrI�RuntimeErrorrJrprKrrPrOr�r�rrrr�<module>
s.H
$