Edit File: cookies.cpython-36.pyc
3 � \�S��������������� ���@���s|��d�Z�ddlZddlZdddgZdjZdjZdjZd d ��ZG�dd��de �Z ejej�d�Z e d �Zdd��eed��eeee���D��Zejed�ded�di��ejdeje ���jZdd��Zejd�Zejd�Zdd��Zddddd d!d"gZdd#d$d%d&d'd(d)d*d+d,d-d.g Zdeefd/d0�ZG�d1d2��d2e �Z!d3Z"e"d4�Z#ejd5e"�d6�e#�d7�ej$ej%B��Z&G�d8d��de �Z'G�d9d��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; � c�������������C���s$���dd�l�}d|��}|j|tdd��d�S�)Nr���zvThe .%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/http/cookies.py�_warn_deprecated_setter����s����r���c���������������@���s���e�Zd�ZdS�)r���N)�__name__� __module__�__qualname__r���r���r���r���r�������s���z!#$%&'*+-.^_`|~:z ()/<=>?@[]{}c�������������C���s���i�|�]}d�|�|�qS�)z\%03or���)�.0�nr���r���r���� <dictcomp>����s���r��������"z\"�\z\\z[%s]+c�������������C���s*���|�dkst�|��r|�S�d|�jt��d�S�dS�)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����s����r���z\\[0-3][0-7][0-7]z[\\].c�������������C���sT��|�d�kst�|��dk�r|�S�|�d�dks0|�d�dkr4|�S�|�dd��}�d}t�|��}g�}x�d|��kod|k�n���rJtj|�|�}tj|�|�}|�r�|�r�|j|�|d�����P�d �}}|r�|jd�}|r�|jd�}|o�|�s�||k��r |j|�||����|j|�|d����|d�}qR|j|�||����|jtt|�|d�|d���d����|d�}qRW�t|�S�) N����r���r������������������r#���r#���) �len� _OctalPatt�search� _QuotePatt�append�start�chr�int� _nulljoin)r����ir����resZo_matchZq_match�j�kr���r���r����_unquote����s6���� $r1���ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc���������� ���C���sR���ddl�m}m�}�|��}|||���\ }}}} } }}} }d||�|||�|| | |f�S�)Nr���)�gmtime�timez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r3���r2���)ZfutureZweekdaynameZ monthnamer2���r3���ZnowZyearZmonthZdayZhhZmmZssZwd�y�zr���r���r����_getdate����s ����r6���c������������ ���@���s��e�Zd�ZdZdddddddd 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)r8����path�commentZdomainzmax-age�secure�httponly�versionr<���r=���c�������������C���s4���d��|�_��|�_|�_x|�jD�]}tj|�|d��qW�d�S�)Nr���)�_key�_value�_coded_value� _reserved�dict�__setitem__)�self�keyr���r���r����__init__&��s����zMorsel.__init__c�������������C���s���|�j�S�)N)r?���)rE���r���r���r���rF���.��s����z Morsel.keyc�������������C���s���t�d��||�_d�S�)NrF���)r���r?���)rE���rF���r���r���r���rF���2��s����c�������������C���s���|�j�S�)N)r@���)rE���r���r���r����value7��s����zMorsel.valuec�������������C���s���t�d��||�_d�S�)NrH���)r���r@���)rE���rH���r���r���r���rH���;��s����c�������������C���s���|�j�S�)N)rA���)rE���r���r���r����coded_value@��s����zMorsel.coded_valuec�������������C���s���t�d��||�_d�S�)NrI���)r���rA���)rE���rI���r���r���r���rI���D��s����c�������������C���s2���|j���}||�jkr td|f���tj|�||��d�S�)NzInvalid attribute %r)�lowerrB���r���rC���rD���)rE����K�Vr���r���r���rD���I��s���� zMorsel.__setitem__Nc�������������C���s.���|j���}||�jkr td|f���tj|�||�S�)NzInvalid attribute %r)rJ���rB���r���rC���� setdefault)rE���rF����valr���r���r���rM���O��s���� zMorsel.setdefaultc�������������C���s>���t�|t�stS�tj|�|�o<|�j|jko<|�j|jko<|�j|jkS�)N)� isinstancer7����NotImplementedrC����__eq__r@���r?���rA���)rE����morselr���r���r���rQ���U��s���� z Morsel.__eq__c�������������C���s$���t���}tj||���|jj|�j��|S�)N)r7���rC����update�__dict__)rE���rR���r���r���r����copy_��s����zMorsel.copyc�������������C���sV���i�}x@t�|�j��D�]0\}}|j��}||�jkr:td|f���|||<�qW�t�j|�|��d�S�)NzInvalid attribute %r)rC����itemsrJ���rB���r���rS���)rE����values�datarF���rN���r���r���r���rS���e��s���� z Morsel.updatec�������������C���s���|j���|�jkS�)N)rJ���rB���)rE���rK���r���r���r���� isReservedKeyn��s����zMorsel.isReservedKeyc�������������C���sh���|t�kr dd�l}|jdtdd��|j��|�jkr<td|f���t|�sRtd|f���||�_||�_ ||�_ d�S�)Nr���zSLegalChars parameter is deprecated, ignored and will be removed in future versions.r���)r���z Attempt to set a reserved key %rzIllegal key %r)�_LegalCharsr ���r ���r���rJ���rB���r���r���r?���r@���rA���)rE���rF���rN���Z coded_valZ LegalCharsr ���r���r���r����setq��s����z Morsel.setc�������������C���s���|�j�|�j|�jd�S�)N)rF���rH���rI���)r?���r@���rA���)rE���r���r���r����__getstate__���s����zMorsel.__getstate__c�������������C���s"���|d�|�_�|d�|�_|d�|�_d�S�)NrF���rH���rI���)r?���r@���rA���)rE����stater���r���r����__setstate__���s���� zMorsel.__setstate__�Set-Cookie:c�������������C���s���d||�j�|�f�S�)Nz%s %s)�OutputString)rE����attrs�headerr���r���r����output���s����z Morsel.outputc�������������C���s���d|�j�j|�j��f�S�)Nz<%s: %s>)� __class__r���r`���)rE���r���r���r����__repr__���s����zMorsel.__repr__c�������������C���s���d|�j�|�jdd��S�)Nz� <script type="text/javascript"> <!-- begin hiding document.cookie = "%s"; // end hiding --> </script> r���z\")r`����replace)rE���ra���r���r���r���� js_output���s����zMorsel.js_outputc�������������C���s(��g�}|j�}|d|�j|�jf���|d�kr,|�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>W�t|�S�)Nz%s=%sr���r8���zmax-agez%s=%dr;���) r(���rF���rI���rB����sortedrV���rO���r+���r6���r���r����_flags�_semispacejoin)rE���ra����resultr(���rV���rF���rH���r���r���r���r`������s,����zMorsel.OutputString)N)Nr_���)N)N)r���r���r����__doc__rB���ri���rG����propertyrF���r���rH���rI���rD���rM���rQ����object�__ne__rU���rS���rY���rZ���r[���r\���r^���rc����__str__re���rg���r`���r���r���r���r���r7�����s@��� r7���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���������������@���sn���e�Zd�ZdZdd��Zdd��Zddd�Zd d ��Zdd��Zddd�Z e Z dd��Zddd�Zdd��Z efdd�ZdS�)r���z'A container class for a set of Morsels.c�������������C���s���||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���)rE���rN���r���r���r����value_decode���s����zBaseCookie.value_decodec�������������C���s���t�|�}||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���)rE���rN����strvalr���r���r����value_encode���s����zBaseCookie.value_encodeNc�������������C���s���|r|�j�|��d�S�)N)�load)rE����inputr���r���r���rG������s����zBaseCookie.__init__c�������������C���s.���|�j�|t���}|j|||��tj|�||��dS�)z+Private method for setting a cookie's valueN)�getr7���r[���rC���rD���)rE���rF���Z real_valuerI����Mr���r���r���Z__set���s����zBaseCookie.__setc�������������C���s:���t�|t�rtj|�||��n|�j|�\}}|�j|||��dS�)zDictionary style assignment.N)rO���r7���rC���rD���rs����_BaseCookie__set)rE���rF���rH����rval�cvalr���r���r���rD�����s���� zBaseCookie.__setitem__�Set-Cookie:� c�������������C���s>���g�}t�|�j���}x"|D�]\}}|j|j||���qW�|j|�S�)z"Return a string suitable for HTTP.)rh���rV���r(���rc����join)rE���ra���rb����seprk���rV���rF���rH���r���r���r���rc��� ��s ����zBaseCookie.outputc�������������C���sN���g�}t�|�j���}x(|D�] \}}|jd|t|j�f���qW�d|�jjt|�f�S�)Nz%s=%sz<%s: %s>)rh���rV���r(����reprrH���rd���r���� _spacejoin)rE����lrV���rF���rH���r���r���r���re�����s ����zBaseCookie.__repr__c�������������C���s:���g�}t�|�j���}x |D�]\}}|j|j|���qW�t|�S�)z(Return a string suitable for JavaScript.)rh���rV���r(���rg���r,���)rE���ra���rk���rV���rF���rH���r���r���r���rg�����s ����zBaseCookie.js_outputc�������������C���s8���t�|t�r|�j|��nx|j��D�]\}}||�|<�q W�dS�)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)rO���r����_BaseCookie__parse_stringrV���)rE���ZrawdatarF���rH���r���r���r���rt���&��s ���� zBaseCookie.loadc�������������C���s���d}t�|�}g�}d}d}d}�x�d|��ko2|k�n���r|j||�} | sLP�| jd�| jd��} }| jd�}| d�dkr�|s~q |j|| dd���|f��q | j��tjkr�|s�d�S�|d�kr�| j��tjkr�|j|| df��q�d�S�n|j|| t |�f��q |d�k �r|j|| |�j |�f��d}q d�S�q W�d�}xb|D�]Z\} } }| |k�rV|d�k �sLt�||| <�n,| |k�sdt�|\}}|�j| ||��|�| �}�q*W�d�S�) Nr���Fr ���r���rF���rN����$T) r$����match�group�endr(���rJ���r7���rB���ri���r1���rq����AssertionErrorrx���)rE���r���Zpattr-���r���Zparsed_itemsZmorsel_seenZTYPE_ATTRIBUTEZ TYPE_KEYVALUEr����rF���rH���rw����tpry���rz���r���r���r���Z__parse_string4��sJ���� zBaseCookie.__parse_string)N)Nr{���r|���)N)r���r���r���rl���rq���rs���rG���rx���rD���rc���rp���re���rg���rt����_CookiePatternr����r���r���r���r���r������s��� c���������������@���s ���e�Zd�ZdZdd��Zdd��ZdS�)r���z� 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. c�������������C���s���t�|�|fS�)N)r1���)rE���rN���r���r���r���rq���x��s����zSimpleCookie.value_decodec�������������C���s���t�|�}|t|�fS�)N)r���r���)rE���rN���rr���r���r���r���rs���{��s����zSimpleCookie.value_encodeN)r���r���r���rl���rq���rs���r���r���r���r���r���q��s���))rl����re�string�__all__r}���r,���rj���r����r���� Exceptionr���Z ascii_lettersZdigitsrZ���Z_UnescapedCharsr[����range�map�ordr���rS����compile�escape� fullmatchr���r���r%���r'���r1���Z_weekdaynameZ _monthnamer6���rC���r7���Z_LegalKeyCharsZ_LegalValueChars�ASCII�VERBOSEr����r���r���r���r���r���r����<module>���sF��� 2�J�