AlkantarClanX12

Your IP : 18.116.85.204


Current Path : /opt/alt/python37/lib64/python3.7/http/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/http/__pycache__/cookies.cpython-37.pyc

B

� f�O�
@stdZddlZddlZdddgZdjZdjZdjZGd	d�de�Z	ej
ejd
ZedZ
dd
�eed��eeee
��D�Ze�ed�ded�di�e�de�e��jZdd�Ze�d�Ze�d�Zdd�Zddddddd gZdd!d"d#d$d%d&d'd(d)d*d+d,g
Zdeefd-d.�ZGd/d0�d0e�Z d1Z!e!d2Z"e�d3e!d4e"d5ej#ej$B�Z%Gd6d�de�Z&Gd7d�de&�Z'dS)8a.

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=\\012;";')
   >>> print(C)
   Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"

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; � c@seZdZdS)rN)�__name__�
__module__�__qualname__�r
r
�1/opt/alt/python37/lib64/python3.7/http/cookies.pyr�sz!#$%&'*+-.^_`|~:z
 ()/<=>?@[]{}cCsi|]}d||�qS)z\%03or
)�.0�nr
r
r�
<dictcomp>�sr��"z\"�\z\\z[%s]+cCs*|dkst|�r|Sd|�t�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)�strr
r
r�_quote�srz\\[0-3][0-7][0-7]z[\\].cCsP|dkst|�dkr|S|ddks0|ddkr4|S|dd�}d}t|�}g}x�d|krh|k�rFnn�t�||�}t�||�}|s�|s�|�||d��Pd}}|r�|�d�}|r�|�d�}|�r|r�||k�r|�|||��|�||d�|d}qR|�|||��|�tt||d|d�d���|d}qRWt|�S)N�rr������)	�len�
_OctalPatt�search�
_QuotePatt�append�start�chr�int�	_nulljoin)r�ir
ZresZo_matchZq_match�j�kr
r
r�_unquote�s6


$r(ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc	CsRddlm}m}|�}|||�\	}}}}	}
}}}
}d|||||||	|
|fS)Nr)�gmtime�timez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r*r))ZfutureZweekdaynameZ	monthnamer)r*ZnowZyearZmonthZdayZhhZmmZssZwd�y�zr
r
r�_getdate�s
r-c	@s�eZdZdZdddddddd	d
�ZddhZd
d�Zedd��Zedd��Z	edd��Z
dd�Zd1dd�Zdd�Z
ejZdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd2d)d*�ZeZd+d,�Zd3d-d.�Zd4d/d0�ZdS)5�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.
    �expiresZPath�CommentZDomainzMax-AgeZSecureZHttpOnlyZVersion)r/�path�commentZdomainzmax-age�secure�httponly�versionr3r4cCs4d|_|_|_x|jD]}t�||d�qWdS)Nr)�_key�_value�_coded_value�	_reserved�dict�__setitem__)�self�keyr
r
r�__init__ szMorsel.__init__cCs|jS)N)r6)r<r
r
rr=(sz
Morsel.keycCs|jS)N)r7)r<r
r
r�value,szMorsel.valuecCs|jS)N)r8)r<r
r
r�coded_value0szMorsel.coded_valuecCs2|��}||jkr td|f��t�|||�dS)NzInvalid attribute %r)�lowerr9rr:r;)r<�K�Vr
r
rr;4s
zMorsel.__setitem__NcCs.|��}||jkr td|f��t�|||�S)NzInvalid attribute %r)rAr9rr:�
setdefault)r<r=�valr
r
rrD:s
zMorsel.setdefaultcCs>t|t�stSt�||�o<|j|jko<|j|jko<|j|jkS)N)�
isinstancer.�NotImplementedr:�__eq__r7r6r8)r<�morselr
r
rrH@s
z
Morsel.__eq__cCs$t�}t�||�|j�|j�|S)N)r.r:�update�__dict__)r<rIr
r
r�copyJszMorsel.copycCsVi}x@t|���D]0\}}|��}||jkr:td|f��|||<qWt�||�dS)NzInvalid attribute %r)r:�itemsrAr9rrJ)r<�values�datar=rEr
r
rrJPs
z
Morsel.updatecCs|��|jkS)N)rAr9)r<rBr
r
r�
isReservedKeyYszMorsel.isReservedKeycCsH|��|jkrtd|f��t|�s2td|f��||_||_||_dS)Nz Attempt to set a reserved key %rzIllegal key %r)rAr9rrr6r7r8)r<r=rEZ	coded_valr
r
r�set\sz
Morsel.setcCs|j|j|jd�S)N)r=r?r@)r6r7r8)r<r
r
r�__getstate__gszMorsel.__getstate__cCs"|d|_|d|_|d|_dS)Nr=r?r@)r6r7r8)r<�stater
r
r�__setstate__ns

zMorsel.__setstate__�Set-Cookie:cCsd||�|�fS)Nz%s %s)�OutputString)r<�attrs�headerr
r
r�outputssz
Morsel.outputcCsd|jj|��fS)Nz<%s: %s>)�	__class__rrV)r<r
r
r�__repr__xszMorsel.__repr__cCsd|�|��dd�S)Nz�
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        rz\")rV�replace)r<rWr
r
r�	js_output{szMorsel.js_outputcCs(g}|j}|d|j|jf�|dkr,|j}t|���}x�|D]�\}}|dkrPq>||krZq>|dkr�t|t�r�|d|j|t|�f�q>|dkr�t|t�r�|d|j||f�q>|dkr�t|t	�r�|d|j|t
|�f�q>||jk�r|�r|t	|j|��q>|d|j||f�q>Wt|�S)Nz%s=%srr/zmax-agez%s=%dr2)
r r=r@r9�sortedrMrFr#r-rr�_flags�_semispacejoin)r<rW�resultr rMr=r?r
r
rrV�s,zMorsel.OutputString)N)NrU)N)N)rrr	�__doc__r9r_r>�propertyr=r?r@r;rDrH�object�__ne__rLrJrPrQrRrTrY�__str__r[r]rVr
r
r
rr.�s:
	


r.z,\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=z\[\]z�
    \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@sneZdZdZdd�Zdd�Zddd�Zd	d
�Zdd�Zddd�Z	e	Z
dd�Zddd�Zdd�Z
efdd�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
)r<rEr
r
r�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)r<rE�strvalr
r
r�value_encode�szBaseCookie.value_encodeNcCs|r|�|�dS)N)�load)r<�inputr
r
rr>�szBaseCookie.__init__cCs.|�|t��}|�|||�t�|||�dS)z+Private method for setting a cookie's valueN)�getr.rQr:r;)r<r=Z
real_valuer@�Mr
r
rZ__set�szBaseCookie.__setcCs:t|t�rt�|||�n|�|�\}}|�|||�dS)zDictionary style assignment.N)rFr.r:r;ri�_BaseCookie__set)r<r=r?�rval�cvalr
r
rr;�s
zBaseCookie.__setitem__�Set-Cookie:�
cCs>g}t|���}x"|D]\}}|�|�||��qW|�|�S)z"Return a string suitable for HTTP.)r^rMr rY�join)r<rWrX�seprarMr=r?r
r
rrY�s
zBaseCookie.outputcCsNg}t|���}x(|D] \}}|�d|t|j�f�qWd|jjt|�fS)Nz%s=%sz<%s: %s>)r^rMr �reprr?rZr�
_spacejoin)r<�lrMr=r?r
r
rr[�s
zBaseCookie.__repr__cCs:g}t|���}x |D]\}}|�|�|��qWt|�S)z(Return a string suitable for JavaScript.)r^rMr r]r$)r<rWrarMr=r?r
r
rr]s
zBaseCookie.js_outputcCs8t|t�r|�|�nx|��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)rFr�_BaseCookie__parse_stringrM)r<Zrawdatar=r?r
r
rrj
s

zBaseCookie.loadcCs�d}t|�}g}d}d}d}�xd|kr6|k�rnn�|�||�}	|	sLP|	�d�|	�d�}
}|	�d�}|
ddkr�|s~q |�||
dd�|f�q |
��tjkr�|s�dS|dkr�|
��tjkr�|�||
df�q�dSn|�||
t	|�f�q |dk	�r|�||
|�
|�f�d}q dSq Wd}xb|D]Z\}
}
}|
|k�rV|dk	�sLt�|||
<n,|
|k�sdt�|\}}|�|
||�||
}�q*WdS)	NrFrrr=rE�$T)
r�match�group�endr rAr.r9r_r(rg�AssertionErrorrn)r<rZpattr%r
Zparsed_itemsZmorsel_seenZTYPE_ATTRIBUTEZ
TYPE_KEYVALUErzr=r?rm�tprorpr
r
rZ__parse_stringsJ



zBaseCookie.__parse_string)N)Nrqrr)N)rrr	rbrgrir>rnr;rYrfr[r]rj�_CookiePatternrxr
r
r
rr�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.
    cCst|�|fS)N)r()r<rEr
r
rrg\szSimpleCookie.value_decodecCst|�}|t|�fS)N)rr)r<rErhr
r
rri_szSimpleCookie.value_encodeN)rrr	rbrgrir
r
r
rrUs)(rb�re�string�__all__rsr$r`rv�	ExceptionrZ
ascii_lettersZdigitsZ_LegalCharsZ_UnescapedCharsrQ�range�map�ordrrJ�compile�escape�	fullmatchrrrrr(Z_weekdaynameZ
_monthnamer-r:r.Z_LegalKeyCharsZ_LegalValueChars�ASCII�VERBOSErrrr
r
r
r�<module>sD


24