Spade
Mini Shell
| Directory:~$ /lib64/python3.6/http/__pycache__/ |
| [Home] [System Details] [Kill Me] |
3
k��hQ�
@s|dZddlZddlZdddgZdjZdjZdjZd d
�ZGdd�de �Z
ejejdZ
e
d
Zdd�eed��eeee��D�Zejed�ded�di�ejdeje
��jZdd�Zejd�jZdd�Zdd�Zdddd
d!d"d#gZdd$d%d&d'd(d)d*d+d,d-d.d/g
Zdeefd0d1�Z
Gd2d3�d3e!�Z"d4Z#e#d5Z$ejd6e#d7e$d8ej%ej&B�Z'Gd9d�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=\\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; �
cCs$ddl}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/lib64/python3.6/cookies.py�_warn_deprecated_setter�src@seZdZdS)rN)�__name__�
__module__�__qualname__rrrrr�sz!#$%&'*+-.^_`|~:z
()/<=>?@[]{}cCsi|]}d||�qS)z\%03or)�.0�nrrr�
<dictcomp>�sr��"z\"�\z\\z[%s]+cCs*|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)�strrrr�_quote�srz\\(?:([0-3][0-7][0-7])|(.))cCs&|drtt|dd��S|dSdS)N���)�chr�int)�mrrr�_unquote_replace�sr%cCsJ|dkst|�dkr|S|ddks0|ddkr4|S|dd�}tt|�S)Nr!rrr���r&)�len�_unquote_subr%)rrrr�_unquote�sr)ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc CsRddlm}m}|�}|||�\ }}}} }
}}}
}d||||||| |
|fS)Nr)�gmtime�timez#%s, %02d %3s %4d %02d:%02d:%02d
GMT)r+r*)ZfutureZweekdaynameZ monthnamer*r+ZnowZyearZmonthZdayZhhZmmZssZwd�y�zrrr�_getdate�s
r.c @seZdZdZdddddddd d
�ZddhZd
d�Zedd��Zej dd��Zedd��Z
e
j dd��Z
edd��Zej dd��Zdd�Zd4dd�Z
dd�ZejZdd
�Zd!d"�Zd#d$�Zefd%d&�Zd'd(�Zd)d*�Zd5d,d-�ZeZd.d/�Zd6d0d1�Zd7d2d3�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.
�expiresZPath�CommentZDomainzMax-AgeZSecureZHttpOnlyZVersion)r0�path�commentZdomainzmax-age�secure�httponly�versionr4r5cCs4d|_|_|_x|jD]}tj||d�qWdS)Nr)�_key�_value�_coded_value� _reserved�dict�__setitem__)�self�keyrrr�__init__szMorsel.__init__cCs|jS)N)r7)r=rrrr>sz
Morsel.keycCstd�||_dS)Nr>)rr7)r=r>rrrr>
scCs|jS)N)r8)r=rrr�value%szMorsel.valuecCstd�||_dS)Nr@)rr8)r=r@rrrr@)scCs|jS)N)r9)r=rrr�coded_value.szMorsel.coded_valuecCstd�||_dS)NrA)rr9)r=rArrrrA2scCs2|j�}||jkr
td|f��tj|||�dS)NzInvalid attribute
%r)�lowerr:rr;r<)r=�K�Vrrrr<7s
zMorsel.__setitem__NcCs.|j�}||jkr
td|f��tj|||�S)NzInvalid attribute %r)rBr:rr;�
setdefault)r=r>�valrrrrE=s
zMorsel.setdefaultcCs>t|t�stStj||�o<|j|jko<|j|jko<|j|jkS)N)�
isinstancer/�NotImplementedr;�__eq__r8r7r9)r=�morselrrrrICs
z
Morsel.__eq__cCs$t�}tj||�|jj|j�|S)N)r/r;�update�__dict__)r=rJrrr�copyMszMorsel.copycCsVi}x@t|�j�D]0\}}|j�}||jkr:td|f��|||<qWtj||�dS)NzInvalid
attribute
%r)r;�itemsrBr:rrK)r=�values�datar>rFrrrrKSs
z
Morsel.updatecCs|j�|jkS)N)rBr:)r=rCrrr�
isReservedKey\szMorsel.isReservedKeycCsh|tkr
ddl}|jdtdd�|j�|jkr<td|f��t|�sRtd|f��||_||_ ||_
dS)NrzSLegalChars parameter is deprecated, ignored and will be removed in
future versions.r!)rz Attempt to set a reserved key %rzIllegal key
%r)�_LegalCharsr r
rrBr:rrr7r8r9)r=r>rFZ coded_valZ
LegalCharsr rrr�set_sz
Morsel.setcCs|j|j|jd�S)N)r>r@rA)r7r8r9)r=rrr�__getstate__qszMorsel.__getstate__cCs"|d|_|d|_|d|_dS)Nr>r@rA)r7r8r9)r=�staterrr�__setstate__xs
zMorsel.__setstate__�Set-Cookie:cCsd||j|�fS)Nz%s
%s)�OutputString)r=�attrs�headerrrr�output}sz
Morsel.outputcCsd|jj|j�fS)Nz<%s:
%s>)� __class__rrX)r=rrr�__repr__�szMorsel.__repr__cCsd|j|�jdd�S)Nz�
<script type="text/javascript">
<!-- begin hiding
document.cookie = "%s";
// end hiding -->
</script>
rz\")rX�replace)r=rYrrr� js_output�szMorsel.js_outputcCs(g}|j}|d|j|jf�|dkr,|j}t|j��}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=%srr0zmax-agez%s=%dr3)
�appendr>rAr:�sortedrNrGr#r.rr�_flags�_semispacejoin)r=rY�resultr`rNr>r@rrrrX�s,zMorsel.OutputString)N)NrW)N)N)rrr�__doc__r:rbr?�propertyr>rr@rAr<rErI�object�__ne__rMrKrQrRrSrTrVr[�__str__r]r_rXrrrrr/�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�Zdd�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=rFrrr�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=rF�strvalrrr�value_encode�szBaseCookie.value_encodeNcCs|r|j|�dS)N)�load)r=�inputrrrr?�szBaseCookie.__init__cCs.|j|t��}|j|||�tj|||�dS)z+Private
method for setting a cookie's valueN)�getr/rSr;r<)r=r>Z
real_valuerA�MrrrZ__set�szBaseCookie.__setcCs:t|t�rtj|||�n|j|�\}}|j|||�dS)zDictionary
style
assignment.N)rGr/r;r<rl�_BaseCookie__set)r=r>r@�rval�cvalrrrr<�s
zBaseCookie.__setitem__�Set-Cookie:�
cCs>g}t|j��}x"|D]\}}|j|j||��qW|j|�S)z"Return
a string suitable for
HTTP.)rarNr`r[�join)r=rYrZ�seprdrNr>r@rrrr[�s
zBaseCookie.outputcCsNg}t|j��}x(|D]
\}}|jd|t|j�f�qWd|jjt|�fS)Nz%s=%sz<%s:
%s>)rarNr`�reprr@r\r�
_spacejoin)r=�lrNr>r@rrrr]s
zBaseCookie.__repr__cCs:g}t|j��}x
|D]\}}|j|j|��qWt|�S)z(Return a string suitable for
JavaScript.)rarNr`r_� _nulljoin)r=rYrdrNr>r@rrrr_s
zBaseCookie.js_outputcCs8t|t�r|j|�nx|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)rGr�_BaseCookie__parse_stringrN)r=Zrawdatar>r@rrrrms
zBaseCookie.loadcCspd}t|�}g}d}d}d}�xd|ko2|kn�r|j||�} | sLP| jd�| jd�}
}| jd�}|
ddkr�|s~q |j||
dd�|f�q |
j�tjkr�|s�dS|dkr�|
j�tjkr�|j||
df�q�dSn|j||
t |�f�q |dk �r|j||
|j
|�f�d}q dSq Wd}xF|D]>\}
}
}|
|k�rH|||
<n|\}}|j|
||�||
}�q*WdS) NrFrr!r>rF�$T)r'�match�group�endr`rBr/r:rbr)rjrq)r=rZpatt�irZparsed_itemsZmorsel_seenZTYPE_ATTRIBUTEZ
TYPE_KEYVALUEr~r>r@rp�tprrrsrrrZ__parse_string"sF
zBaseCookie.__parse_string)N)Nrtru)N)rrrrerjrlr?rqr<r[rir]r_rm�_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)r))r=rFrrrrjfszSimpleCookie.value_decodecCst|�}|t|�fS)N)rr)r=rFrkrrrrliszSimpleCookie.value_encodeN)rrrrerjrlrrrrr_s)*re�re�string�__all__rvr{rcryr� ExceptionrZ
ascii_lettersZdigitsrRZ_UnescapedCharsrS�range�map�ordrrK�compile�escape� fullmatchrr�subr(r%r)Z_weekdaynameZ
_monthnamer.r;r/Z_LegalKeyCharsZ_LegalValueChars�ASCII�VERBOSEr�rrrrrr�<module>sF
J