Your IP : 216.73.217.13


Current Path : /snap/core/current/usr/lib/python3.5/http/__pycache__/
Upload File :
Current File : //snap/core/current/usr/lib/python3.5/http/__pycache__/cookies.cpython-35.pyc



H�iWT�
@s'dZddlZddlZdddgZdjZdjZdjZd	d
�ZGdd�de	�Z
ejejdZ
e
d
Zdd�eed��eeee��D�Zejed�ded�di�ejdeje
��jZejd�Zdd�Zdd�Zejd�jZdd�Zdd�Zd d!d"d#d$d%d&gZ dd'd(d)d*d+d,d-d.d/d0d1d2g
Z!de e!d3d4�Z"Gd5d6�d6e#�Z$d7Z%e%d8Z&ejd9e%d:e&d;ej'�Z(Gd<d�de#�Z)Gd=d�de)�Z*dS)>a%

Here's a sample session to show how to use this module.
At the moment, this is the only documentation.

The Basics
----------

Importing is easy...

   >>> from http import cookies

Most of the time you start by creating a cookie.

   >>> C = cookies.SimpleCookie()

Once you've created your Cookie, you can add values just as if it were
a dictionary.

   >>> C = cookies.SimpleCookie()
   >>> C["fig"] = "newton"
   >>> C["sugar"] = "wafer"
   >>> C.output()
   'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer'

Notice that the printable representation of a Cookie is the
appropriate format for a Set-Cookie: header.  This is the
default behavior.  You can change the header and printed
attributes by using the .output() function

   >>> C = cookies.SimpleCookie()
   >>> C["rocky"] = "road"
   >>> C["rocky"]["path"] = "/cookie"
   >>> print(C.output(header="Cookie:"))
   Cookie: rocky=road; Path=/cookie
   >>> print(C.output(attrs=[], header="Cookie:"))
   Cookie: rocky=road

The load() method of a Cookie extracts cookies from a string.  In a
CGI script, you would use this method to extract the cookies from the
HTTP_COOKIE environment variable.

   >>> C = cookies.SimpleCookie()
   >>> C.load("chips=ahoy; vienna=finger")
   >>> C.output()
   'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger'

The load() method is darn-tootin smart about identifying cookies
within a string.  Escaped quotation marks, nested semicolons, and other
such trickeries do not confuse it.

   >>> C = cookies.SimpleCookie()
   >>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=;";')
   >>> print(C)
   Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=;"

Each element of the Cookie also supports all of the RFC 2109
Cookie attributes.  Here's an example which sets the Path
attribute.

   >>> C = cookies.SimpleCookie()
   >>> C["oreo"] = "doublestuff"
   >>> C["oreo"]["path"] = "/"
   >>> print(C)
   Set-Cookie: oreo=doublestuff; Path=/

Each dictionary element has a 'value' attribute, which gives you
back the value associated with the key.

   >>> C = cookies.SimpleCookie()
   >>> C["twix"] = "none for you"
   >>> C["twix"].value
   'none for you'

The SimpleCookie expects that all values should be standard strings.
Just to be sure, SimpleCookie invokes the str() builtin to convert
the value to a string, when the values are set dictionary-style.

   >>> C = cookies.SimpleCookie()
   >>> C["number"] = 7
   >>> C["string"] = "seven"
   >>> C["number"].value
   '7'
   >>> C["string"].value
   'seven'
   >>> C.output()
   'Set-Cookie: number=7\r\nSet-Cookie: string=seven'

Finis.
�N�CookieError�
BaseCookie�SimpleCookie�z; � cCs0ddl}d|}|j|tdd�dS)NrzvThe .%s setter is deprecated. The attribute will be read-only in future releases. Please use the set() method instead.�
stacklevel�)�warnings�warn�DeprecationWarning)�setterr	�msg�r�"/usr/lib/python3.5/http/cookies.py�_warn_deprecated_setter�src@seZdZdS)rN)�__name__�
__module__�__qualname__rrrrr�sz!#$%&'*+-.^_`|~:z
 ()/<=>?@[]{}cCsi|]}d||�qS)z\%03or)�.0�nrrr�
<dictcomp>�s	r��"z\"�\z\\z[%s]+z[\x00-\x1F\x7F]cGstdd�|D��S)zhDetects control characters within a value.
    Supports any type, as header values can be any type.
    css$|]}tjt|��VqdS)N)�_control_character_re�search�str)r�vrrr�	<genexpr>�sz)_has_control_character.<locals>.<genexpr>)�any)�valrrr�_has_control_character�sr!cCs5|dkst|�r|Sd|jt�dSdS)z�Quote a string for use in a cookie header.

    If the string does not need to be double-quoted, then just return the
    string.  Otherwise, surround the string in doublequotes and quote
    (with a \) special characters.
    Nr)�
_is_legal_key�	translate�_Translator)rrrr�_quote�sr%z\\(?:([0-3][0-7][0-7])|(.))cCs<|jd�r+tt|jd�d��S|jd�SdS)N���)�group�chr�int)�mrrr�_unquote_replace�sr-cCsc|dkst|�dkr"|S|ddksB|ddkrF|S|dd�}tt|�S)Nr(rrr&���r.)�len�_unquote_subr-)rrrr�_unquote�s r1ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc	Csoddlm}m}|�}|||�\	}}}}	}
}}}
}d|||||||	|
|fS)Nr)�gmtime�timez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r3r2)ZfutureZweekdaynameZ	monthnamer2r3ZnowZyearZmonthZdayZhhZmmZssZwd�y�zrrr�_getdate�s
	+r6c@s�eZdZdZddddddddd	d
ddd
dddiZdd
hZdd�Zedd��Zej	dd��Zedd��Z
e
j	dd��Z
edd��Zej	dd��Zdd�Zddd �Z
d!d"�ZejZd#d$�Zd%d&�Zd'd(�Zed)d*�Zd+d,�Zd-d.�Zdd/d0d1�ZeZd2d3�Zdd4d5�Zdd6d7�ZdS)8�Morsela�A class to hold ONE (key, value) pair.

    In a cookie, each such pair may have several attributes, so this class is
    used to keep the attributes associated with the appropriate key,value pair.
    This class also includes a coded_value attribute, which is used to hold
    the network representation of the value.  This is most useful when Python
    objects are pickled for network transit.
    �expires�pathZPathZcomment�CommentZdomainZDomainzmax-agezMax-AgeZsecureZSecureZhttponlyZHttpOnly�versionZVersioncCsBd|_|_|_x$|jD]}tj||d�q!WdS)Nr)�_key�_value�_coded_value�	_reserved�dict�__setitem__)�self�keyrrr�__init__szMorsel.__init__cCs|jS)N)r<)rBrrrrC$sz
Morsel.keycCstd�||_dS)NrC)rr<)rBrCrrrrC(s
cCs|jS)N)r=)rBrrr�value-szMorsel.valuecCstd�||_dS)NrE)rr=)rBrErrrrE1s
cCs|jS)N)r>)rBrrr�coded_value6szMorsel.coded_valuecCstd�||_dS)NrF)rr>)rBrFrrrrF:s
cCsj|j�}||jkr.td|f��t||�rStd||f��tj|||�dS)NzInvalid attribute %rz3Control characters are not allowed in cookies %r %r)�lowerr?rr!r@rA)rB�K�VrrrrA?szMorsel.__setitem__NcCsf|j�}||jkr.td|f��t||�rStd||f��tj|||�S)NzInvalid attribute %rz3Control characters are not allowed in cookies %r %r)rGr?rr!r@�
setdefault)rBrCr rrrrJGszMorsel.setdefaultcCsYt|t�stStj||�oX|j|jkoX|j|jkoX|j|jkS)N)�
isinstancer7�NotImplementedr@�__eq__r=r<r>)rB�morselrrrrMOsz
Morsel.__eq__cCs0t�}tj||�|jj|j�|S)N)r7r@�update�__dict__)rBrNrrr�copyYs	zMorsel.copycCsui}xXt|�j�D]D\}}|j�}||jkrStd|f��|||<qWtj||�dS)NzInvalid attribute %r)r@�itemsrGr?rrO)rB�values�datarCr rrrrO_sz
Morsel.updatecCs|j�|jkS)N)rGr?)rBrHrrr�
isReservedKeyhszMorsel.isReservedKeycCs�|tkr.ddl}|jdtdd�|j�|jkrVtd|f��t|�sutd|f��t|||�r�td|||f��||_	||_
||_dS)NrzSLegalChars parameter is deprecated, ignored and will be removed in future versions.rr(z Attempt to set a reserved key %rzIllegal key %rz6Control characters are not allowed in cookies %r %r %r)�_LegalCharsr	r
rrGr?rr"r!r<r=r>)rBrCr Z	coded_valZ
LegalCharsr	rrr�setks 		z
Morsel.setcCsd|jd|jd|jiS)NrCrErF)r<r=r>)rBrrr�__getstate__�s		zMorsel.__getstate__cCs+|d|_|d|_|d|_dS)NrCrErF)r<r=r>)rB�staterrr�__setstate__�s

zMorsel.__setstate__zSet-Cookie:cCsd||j|�fS)Nz%s %s)�OutputString)rB�attrs�headerrrr�output�sz
Morsel.outputcCsd|jj|j�fS)Nz<%s: %s>)�	__class__rr[)rBrrr�__repr__�szMorsel.__repr__cCsd|j|�jdd�S)Nz�
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        rz\")r[�replace)rBr\rrr�	js_output�szMorsel.js_outputcCsQg}|j}|d|j|jf�|dkr>|j}t|j��}x�|D]�\}}|dkrrqW||kr�qW|dkr�t|t�r�|d|j|t|�f�qW|dkr�t|t�r�|d|j||f�qW||j	kr(|rC|t
|j|��qW|d|j||f�qWWt|�S)Nz%s=%srr8zmax-agez%s=%d)�appendrCrFr?�sortedrRrKr+r6�_flagsr�_semispacejoin)rBr\�resultrcrRrCrErrrr[�s(		$zMorsel.OutputString)rrr�__doc__r?rerD�propertyrCrrErFrArJrM�object�__ne__rQrOrUrVrWrXrZr^�__str__r`rbr[rrrrr7�s@		
r7z,\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=z\[\]z�
    (?x)                           # This is a verbose pattern
    \s*                            # Optional whitespace at start of cookie
    (?P<key>                       # Start of group 'key'
    [a	]+?   # Any word of at least one letter
    )                              # End of group 'key'
    (                              # Optional group: there may not be a value.
    \s*=\s*                          # Equal Sign
    (?P<val>                         # Start of group 'val'
    "(?:[^\\"]|\\.)*"                  # Any doublequoted string
    |                                  # or
    \w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT  # Special case for "expires" attr
    |                                  # or
    [a-]*      # Any word or empty string
    )                                # End of group 'val'
    )?                             # End of optional value group
    \s*                            # Any number of spaces.
    (\s+|;|$)                      # Ending either at space, semicolon, or EOS.
    c@s�eZdZdZdd�Zdd�Zddd�Zd	d
�Zdd�Zdd
ddd�Z	e	Z
dd�Zddd�Zdd�Z
edd�ZdS)rz'A container class for a set of Morsels.cCs
||fS)a
real_value, coded_value = value_decode(STRING)
        Called prior to setting a cookie's value from the network
        representation.  The VALUE is the value read from HTTP
        header.
        Override this function to modify the behavior of cookies.
        r)rBr rrr�value_decode�szBaseCookie.value_decodecCst|�}||fS)z�real_value, coded_value = value_encode(VALUE)
        Called prior to setting a cookie's value from the dictionary
        representation.  The VALUE is the value being assigned.
        Override this function to modify the behavior of cookies.
        )r)rBr �strvalrrr�value_encode�szBaseCookie.value_encodeNcCs|r|j|�dS)N)�load)rB�inputrrrrD�szBaseCookie.__init__cCs?|j|t��}|j|||�tj|||�dS)z+Private method for setting a cookie's valueN)�getr7rWr@rA)rBrCZ
real_valuerF�MrrrZ__set�szBaseCookie.__setcCsQt|t�r%tj|||�n(|j|�\}}|j|||�dS)zDictionary style assignment.N)rKr7r@rAro�_BaseCookie__set)rBrCrE�rval�cvalrrrrAszBaseCookie.__setitem__zSet-Cookie:z
c	Cssg}t|j��}xK|D]C\}}|j||�}t|�rUtd��|j|�qW|j|�S)z"Return a string suitable for HTTP.z-Control characters are not allowed in cookies)rdrRr^r!rrc�join)	rBr\r]�seprgrRrCrEZvalue_outputrrrr^	szBaseCookie.outputcCsig}t|j��}x4|D],\}}|jd|t|j�f�qWd|jjt|�fS)Nz%s=%sz<%s: %s>)rdrRrc�reprrEr_r�
_spacejoin)rB�lrRrCrErrrr`s
$zBaseCookie.__repr__cCsOg}t|j��}x*|D]"\}}|j|j|��qWt|�S)z(Return a string suitable for JavaScript.)rdrRrcrb�	_nulljoin)rBr\rgrRrCrErrrrbs
zBaseCookie.js_outputcCsJt|t�r|j|�n'x$|j�D]\}}|||<q,WdS)z�Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        N)rKr�_BaseCookie__parse_stringrR)rBZrawdatarCrErrrrp%s
zBaseCookie.loadcCsd}t|�}g}d}d}d}xZd|koD|knr�|j||�}	|	sbP|	jd�|	jd�}
}|	jd�}|
ddkr�|s�q-|j||
dd�|f�q-|
j�tjkrK|s�dS|dkr,|
j�tjkr%|j||
df�qHdSq�|j||
t	|�f�q-|dk	r|j||
|j
|�f�d}q-dSq-Wd}x}|D]u\}
}
}|
|kr�|dk	s�t�|||
<q�|
|ks�t�|\}}|j|
||�||
}q�WdS)	NrFr&r(rCr �$T)
r/�matchr)�endrcrGr7r?rer1rm�AssertionErrorrt)rBrZpatt�irZparsed_itemsZmorsel_seenZTYPE_ATTRIBUTEZ
TYPE_KEYVALUErrCrErs�tprurvrrrZ__parse_string3sJ#	
zBaseCookie.__parse_string)rrrrhrmrorDrtrAr^rlr`rbrp�_CookiePatternr}rrrrr�s			c@s.eZdZdZdd�Zdd�ZdS)rz�
    SimpleCookie supports strings as cookie values.  When setting
    the value using the dictionary assignment notation, SimpleCookie
    calls the builtin str() to convert the value to a string.  Values
    received from HTTP are kept as strings.
    cCst|�|fS)N)r1)rBr rrrrmwszSimpleCookie.value_decodecCst|�}|t|�fS)N)rr%)rBr rnrrrrozszSimpleCookie.value_encodeN)rrrrhrmrorrrrrps)+rh�re�string�__all__rwr|rfrzr�	ExceptionrZ
ascii_lettersZdigitsrVZ_UnescapedCharsrW�range�map�ordr$rO�compile�escape�	fullmatchr"rr!r%�subr0r-r1Z_weekdaynameZ
_monthnamer6r@r7Z_LegalKeyCharsZ_LegalValueChars�ASCIIr�rrrrrr�<module>sF				
	)�

�