ok

Mini Shell

Direktori : /lib/python2.7/site-packages/pip/_vendor/requests/
Upload File :
Current File : //lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyo

�
��abc@sQdZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZyddlZWne
k
r�ddlZnXdefd��YZdefd	��YZd
�Zd�Zddd�Zd
efd��YZdejejfd��YZd�Zd�Zd�Zded�Zd�Z dS(s�
requests.cookies
~~~~~~~~~~~~~~~~

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

requests.utils imports from here, so be careful with imports.
i����Ni(tto_native_string(t	cookielibturlparset
urlunparsetMorseltMockRequestcBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	dd�Zd	�Zd
�Z
d�Zed��Zed
��Zed��ZRS(s�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(t_rt_new_headersRturltschemettype(tselftrequest((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__init__&s		cCs|jS(N(R
(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_type+scCst|jj�jS(N(RRRtnetloc(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_host.scCs
|j�S(N(R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_origin_req_host1scCsx|jjjd�s|jjSt|jjddd�}t|jj�}t|j||j|j	|j
|jg�S(NtHosttencodingsutf-8(RtheaderstgetRRRRR	tpathtparamstquerytfragment(Rthosttparsed((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_full_url4s
cCstS(N(tTrue(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytis_unverifiableBscCs||jjkp||jkS(N(RRR(Rtname((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt
has_headerEscCs%|jjj||jj||��S(N(RRRR(RRtdefault((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt
get_headerHscCstd��dS(sMcookielib has no legitimate use for this method; add it back if you find one.s=Cookie headers should be added with add_unredirected_header()N(tNotImplementedError(Rtkeytval((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt
add_headerKscCs||j|<dS(N(R(RRtvalue((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytadd_unredirected_headerOscCs|jS(N(R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_new_headersRscCs
|j�S(N(R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytunverifiableUscCs
|j�S(N(R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytorigin_req_hostYscCs
|j�S(N(R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyR]sN(t__name__t
__module__t__doc__R
RRRRRR tNoneR"R&R(R)tpropertyR*R+R(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRs
										tMockResponsecBs)eZdZd�Zd�Zd�ZRS(s�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(s�Make a MockResponse for `cookielib` to read.

        :param headers: a httplib.HTTPMessage or analogous carrying the headers
        N(t_headers(RR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyR
iscCs|jS(N(R2(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytinfopscCs|jj|�dS(N(R2t
getheaders(RR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyR4ss(R,R-R.R
R3R4(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyR1bs		cCsNt|d�o|jsdSt|�}t|jj�}|j||�dS(s�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
    t_original_responseN(thasattrR5RR1tmsgtextract_cookies(tjarRtresponsetreqtres((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytextract_cookies_to_jarws	cCs,t|�}|j|�|j�jd�S(sj
    Produce an appropriate Cookie header string to be sent with `request`, or None.

    :rtype: str
    tCookie(Rtadd_cookie_headerR)R(R9Rtr((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_cookie_header�s
cCs�g}x�|D]|}|j|kr(q
n|dk	rI||jkrIq
n|dk	rj||jkrjq
n|j|j|j|jf�q
Wx*|D]"\}}}|j|||�q�WdS(skUnsets a cookie by name, by default over all domains and paths.

    Wraps CookieJar.clear(), is O(n).
    N(RR/tdomainRtappendtclear(t	cookiejarRRBRt
clearablestcookie((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytremove_cookie_by_name�s
#tCookieConflictErrorcBseZdZRS(s�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.
    (R,R-R.(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRI�stRequestsCookieJarcBs�eZdZdddd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zddd�Zd
�Zd�Zd�Zd�Zd�Zd�Zddd�Zddd�Zd�Zd�Zd�ZRS(s�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).
    cCs0y|j|||�SWntk
r+|SXdS(s�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(t_find_no_duplicatestKeyError(RRR!RBR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyR�s
cKs||dkr;t||d|jd�d|jd��dSt|t�rYt|�}nt|||�}|j|�|S(s�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.
        RBRN(R/RHRt
isinstanceRtmorsel_to_cookiet
create_cookiet
set_cookie(RRR'tkwargstc((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytset�s+
ccs#xt|�D]}|jVq
WdS(s�Dict-like iterkeys() that returns an iterator of names of cookies
        from the jar.

        .. seealso:: itervalues() and iteritems().
        N(titerR(RRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytiterkeys�scCst|j��S(s�Dict-like keys() that returns a list of names of cookies from the
        jar.

        .. seealso:: values() and items().
        (tlistRU(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytkeys�sccs#xt|�D]}|jVq
WdS(s�Dict-like itervalues() that returns an iterator of values of cookies
        from the jar.

        .. seealso:: iterkeys() and iteritems().
        N(RTR'(RRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt
itervalues�scCst|j��S(s�Dict-like values() that returns a list of values of cookies from the
        jar.

        .. seealso:: keys() and items().
        (RVRX(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytvalues�sccs,x%t|�D]}|j|jfVq
WdS(s�Dict-like iteritems() that returns an iterator of name-value tuples
        from the jar.

        .. seealso:: iterkeys() and itervalues().
        N(RTRR'(RRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt	iteritems�scCst|j��S(s�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().
        (RVRZ(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytitemsscCsCg}x6t|�D](}|j|kr|j|j�qqW|S(s2Utility method to list all the domains in the jar.(RTRBRC(RtdomainsRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytlist_domainss
cCsCg}x6t|�D](}|j|kr|j|j�qqW|S(s0Utility method to list all the paths in the jar.(RTRRC(RtpathsRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt
list_pathss
cCsSg}xFt|�D]8}|jdk	r;|j|kr;tS|j|j�qWtS(svReturns True if there are multiple domains in the jar.
        Returns False otherwise.

        :rtype: bool
        N(RTRBR/RRCtFalse(RR\RG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytmultiple_domainsscCsji}x]t|�D]O}|dks4|j|kr|dksO|j|kr|j||j<qqW|S(s�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(RTR/RBRR'R(RRBRt
dictionaryRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_dict,scCs3ytt|�j|�SWntk
r.tSXdS(N(tsuperRJt__contains__RIR(RR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRe<s
cCs
|j|�S(s�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).
        (RK(RR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__getitem__BscCs|j||�dS(s�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(RS(RRR'((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__setitem__KscCst||�dS(slDeletes a cookie given a name. Wraps ``cookielib.CookieJar``'s
        ``remove_cookie_by_name()``.
        N(RH(RR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__delitem__RscOsmt|jd�rQ|jjd�rQ|jjd�rQ|jjdd�|_ntt|�j|||�S(Nt
startswitht"s\"t(R6R'RitendswithtreplaceRdRJRP(RRGtargsRQ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRPXs6cCsVt|tj�r<x=|D]}|jtj|��qWntt|�j|�dS(sAUpdates this jar with cookies from another CookieJar or dict-likeN(RMRt	CookieJarRPtcopyRdRJtupdate(RtotherRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRq]s
cCs�xft|�D]X}|j|kr
|dks=|j|kre|dksX|j|krb|jSqeq
q
Wtd|||f��dS(s�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
        sname=%r, domain=%r, path=%rN(RTRR/RBRR'RL(RRRBRRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt_findescCs�d}x�t|�D]|}|j|kr|dksC|j|kr�|dks^|j|kr�|dk	r}td|��n|j}q�q�qqW|r�|Std|||f��dS(s�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
        s(There are multiple cookies with name, %rsname=%r, domain=%r, path=%rN(R/RTRRBRRIR'RL(RRRBRttoReturnRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRKyscCs |jj�}|jd�|S(s4Unlike a normal CookieJar, this class is pickleable.t
_cookies_lock(t__dict__Rptpop(Rtstate((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__getstate__�s
cCs5|jj|�d|jkr1tj�|_ndS(s4Unlike a normal CookieJar, this class is pickleable.RuN(RvRqt	threadingtRLockRu(RRx((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__setstate__�scCst�}|j|�|S(s(Return a copy of this RequestsCookieJar.(RJRq(Rtnew_cj((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRp�s	
N(R,R-R.R/RRSRURWRXRYRZR[R]R_RaRcReRfRgRhRPRqRsRKRyR|Rp(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRJ�s0														
									cCsm|dkrdSt|d�r)|j�Stj|�}|j�x$|D]}|jtj|��qIW|S(NRp(R/R6RpRDRP(R9tnew_jarRG((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt_copy_cookie_jar�s


cKstddd|d|dddddd	d
tdddtd
ddddidd6dt�
}t|�t|�}|r�d}t|t|���n|j|�t|d�|d<t|d�|d<|dj	d�|d<t|d�|d<t
j|�S(s�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").
    tversioniRR'tportRBRkRt/tsecuretexpirestdiscardtcommenttcomment_urltresttHttpOnlytrfc2109s4create_cookie() got unexpected keyword arguments: %stport_specifiedtdomain_specifiedt.tdomain_initial_dottpath_specifiedN(tdictR/R`RRSt	TypeErrorRVRqtboolRiRR>(RR'RQtresulttbadargsterr((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRO�s0
	
cCs!d}|dr_y$ttj�t|d��}Wq�tk
r[td|d��q�Xn2|dr�d}tjtj|d|��}ntd|ddt	|d�dt
d|dd|d	|jd
|d
dddi|d
d6dt
dt	|d�d|jd|dpd�
S(sBConvert a Morsel object into a Cookie containing the one k/v pair.smax-agesmax-age: %s must be integerR�s%a, %d-%b-%Y %H:%M:%S GMTR�R�R�RBRRR�R�thttponlyR�R�R�R'R�iN(
R/tintttimet
ValueErrorR�tcalendarttimegmtstrptimeROR�R`R$R'(tmorselR�t
time_template((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRN�s0
$



	
	cCs�|dkrt�}n|dk	r�g|D]}|j^q+}x@|D]5}|s_||krG|jt|||��qGqGWn|S(s-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.
    N(R/RJRRPRO(tcookie_dictREt	overwriteRGtnames_from_jarR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytcookiejar_from_dict�s
$cCs�t|tj�s!td��nt|t�rKt|d|dt�}nXt|tj�r�y|j|�Wq�tk
r�x|D]}|j	|�q�Wq�Xn|S(s�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.
    s!You can only merge into CookieJarRER�(
RMRRoR�R�R�R`RqtAttributeErrorRP(REtcookiest
cookie_in_jar((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt
merge_cookiess

(!R.RpR�R�tcollectionst_internal_utilsRtcompatRRRRRztImportErrortdummy_threadingtobjectRR1R=RAR/RHtRuntimeErrorRIRotMutableMappingRJRRORNRR�R�(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt<module>
s,"
H		�		#	

Zerion Mini Shell 1.0