관리-도구
편집 파일: cookies.cpython-39.pyc
a �����DOg�M����������������������@���sZ��d�Z�ddlZddlZddlZg�d�ZdjZdjZdjZG�dd��de �Z ejej�d �Z e d �Zdd��eed ��eeee���D��Ze�ed�ded�di��e�de�e ���jZdd��Ze�d�jZdd��Zdd��Zg�d�Zg�d�Zdeefdd�Z G�dd��de!�Z"d Z#e#d!�Z$e�d"e#�d#�e$�d$�ej%ej&B��Z'G�d%d&��d&e!�Z(G�d'd(��d(e(�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�������������������@���s���e�Zd�ZdS�)r���N)�__name__� __module__�__qualname__��r ���r ����$/usr/lib64/python3.9/http/cookies.pyr�������s���r���z!#$%&'*+-.^_`|~:z ()/<=>?@[]{}c�����������������C���s���i�|�]}|d�|��qS�)z\%03or ���)�.0�nr ���r ���r���� <dictcomp>����s����r��������"�\"�\z\\z[%s]+c�����������������C���s*���|�du�st�|��r|�S�d|��t��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])|(.))c�����������������C���s&���|�d�rt�t|�d�d��S�|�d�S�d�S�)N������������)�chr�int)�mr ���r ���r����_unquote_replace����s����r���c�����������������C���sJ���|�d�u�st�|��dk�r|�S�|�d�dks0|�d�dkr4|�S�|�dd��}�tt|��S�)Nr���r���r������r���)�len�_unquote_subr���r���r ���r ���r����_unquote����s����r#���)ZMonZTueZWedZThuZFriZSatZSun) NZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc�������������� ���C���sR���ddl�m}m�}�|��}|||���\ }}}} } }}} }d||�|||�|| | |f�S�)Nr���)�gmtime�timez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r%���r$���)�futureZweekdaynameZ monthnamer$���r%���ZnowZyearZmonthZdayZhhZmm�ssZwd�y�zr ���r ���r����_getdate����s�����r*���c���������������� ���@���s����e�Zd�ZdZdddddddd d d� Zdd hZdd��Zedd���Zedd���Z edd���Z dd��Zd2dd�Zdd��Z ejZdd��Zdd ��Zd!d"��Zd#d$��Zd%d&��Zd'd(��Zd3d*d+�ZeZd,d-��Zd4d.d/�Zd5d0d1�Zeej�ZdS�)6�MorselaC��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. �expires�Path�CommentZDomainzMax-AgeZSecureZHttpOnlyZVersionZSameSite) r,����path�comment�domain�max-age�secure�httponly�versionZsamesiter3���r4���c�����������������C���s0���d��|�_��|�_|�_|�jD�]}t�|�|d��qd�S�)Nr���)�_key�_value�_coded_value� _reserved�dict�__setitem__)�self�keyr ���r ���r����__init__��s���� zMorsel.__init__c�����������������C���s���|�j�S��N)r6����r<���r ���r ���r���r=�����s����z Morsel.keyc�����������������C���s���|�j�S�r?���)r7���r@���r ���r ���r����value��s����zMorsel.valuec�����������������C���s���|�j�S�r?���)r8���r@���r ���r ���r����coded_value��s����zMorsel.coded_valuec�����������������C���s2���|����}||�jvr td|f���t�|�||��d�S��NzInvalid attribute %r)�lowerr9���r���r:���r;���)r<����K�Vr ���r ���r���r;���#��s���� zMorsel.__setitem__Nc�����������������C���s.���|����}||�jvr td|f���t�|�||�S�rC���)rD���r9���r���r:���� setdefault)r<���r=����valr ���r ���r���rG���)��s���� zMorsel.setdefaultc�����������������C���s>���t�|t�stS�t�|�|�o<|�j|jko<|�j|jko<|�j|jkS�r?���)� isinstancer+����NotImplementedr:����__eq__r7���r6���r8����r<���Zmorselr ���r ���r���rK���/��s���� � � �z Morsel.__eq__c�����������������C���s$���t���}t�||���|j�|�j��|S�r?���)r+���r:����update�__dict__rL���r ���r ���r����copy9��s����zMorsel.copyc�����������������C���sR���i�}t�|����D�]0\}}|���}||�jvr8td|f���|||<�qt��|�|��d�S�rC���)r:����itemsrD���r9���r���rM���)r<����values�datar=���rH���r ���r ���r���rM���?��s���� z Morsel.updatec�����������������C���s���|����|�jv�S�r?���)rD���r9���)r<���rE���r ���r ���r���� isReservedKeyH��s����zMorsel.isReservedKeyc�����������������C���sH���|����|�jv�rtd|f���t|�s2td|f���||�_||�_||�_d�S�)Nz Attempt to set a reserved key %rzIllegal key %r)rD���r9���r���r���r6���r7���r8���)r<���r=���rH���Z coded_valr ���r ���r����setK��s����z Morsel.setc�����������������C���s���|�j�|�j|�jd�S�)N)r=���rA���rB����r6���r7���r8���r@���r ���r ���r����__getstate__V��s�����zMorsel.__getstate__c�����������������C���s"���|d�|�_�|d�|�_|d�|�_d�S�)Nr=���rA���rB���rU���)r<����stater ���r ���r����__setstate__]��s���� zMorsel.__setstate__�Set-Cookie:c�����������������C���s���d||���|�f�S�)Nz%s %s)�OutputString)r<����attrs�headerr ���r ���r����outputb��s����z Morsel.outputc�����������������C���s���d|�j�j|����f�S�)N�<%s: %s>)� __class__r���rZ���r@���r ���r ���r����__repr__g��s����zMorsel.__repr__c�����������������C���s���d|���|��dd��S�)Nz� <script type="text/javascript"> <!-- begin hiding document.cookie = "%s"; // end hiding --> </script> r���r���)rZ����replace)r<���r[���r ���r ���r���� js_outputj��s�����zMorsel.js_outputc�����������������C���s$��g�}|j�}|d|�j|�jf���|d�u�r,|�j}t|�����}|D�]�\}}|dkrNq<||vrXq<|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<||�jv��r|�r|t |�j|����q<|d|�j|�|f���q<t|�S�)N�%s=%sr���r,���r2���z%s=%dr0���) �appendr=���rB���r9����sortedrP���rI���r���r*���r���r����_flags�_semispacejoin)r<���r[����resultrd���rP���r=���rA���r ���r ���r���rZ���t��s,����zMorsel.OutputString)N)NrY���)N)N)r���r���r ����__doc__r9���rf���r>����propertyr=���rA���rB���r;���rG���rK����object�__ne__rO���rM���rS���rT���rV���rX���r]����__str__r`���rb���rZ����classmethod�types�GenericAlias�__class_getitem__r ���r ���r ���r���r+�������sF���� !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�������������������@���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 ����r<���rH���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����r<���rH���Zstrvalr ���r ���r����value_encode���s����zBaseCookie.value_encodeNc�����������������C���s���|r|���|��d�S�r?���)�load)r<����inputr ���r ���r���r>������s����zBaseCookie.__init__c�����������������C���s.���|���|t���}|�|||��t�|�||��dS�)z+Private method for setting a cookie's valueN)�getr+���rT���r:���r;���)r<���r=���Z real_valuerB����Mr ���r ���r���Z__set���s����zBaseCookie.__setc�����������������C���s:���t�|t�rt�|�||��n|��|�\}}|��|||��dS�)zDictionary style assignment.N)rI���r+���r:���r;���ru����_BaseCookie__set)r<���r=���rA����rval�cvalr ���r ���r���r;������s���� zBaseCookie.__setitem__rY���� c�����������������C���s:���g�}t�|�����}|D�]\}}|�|�||���q|�|�S�)z"Return a string suitable for HTTP.)re���rP���rd���r]����join)r<���r[���r\����seprh���rP���r=���rA���r ���r ���r���r]������s ����zBaseCookie.outputc�����������������C���sJ���g�}t�|�����}|D�] \}}|�d|t|j�f���qd|�jjt|�f�S�)Nrc���r^���)re���rP���rd����reprrA���r_���r���� _spacejoin)r<����lrP���r=���rA���r ���r ���r���r`������s ����zBaseCookie.__repr__c�����������������C���s6���g�}t�|�����}|D�]\}}|�|�|���qt|�S�)z(Return a string suitable for JavaScript.)re���rP���rd���rb���� _nulljoin)r<���r[���rh���rP���r=���rA���r ���r ���r���rb������s ����zBaseCookie.js_outputc�����������������C���s4���t�|t�r|��|��n|���D�]\}}||�|<�qdS�)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)rI���r����_BaseCookie__parse_stringrP���)r<���Zrawdatar=���rA���r ���r ���r���rv������s ���� zBaseCookie.loadc�����������������C���s���d}t�|�}g�}d}d}d}d|��kr2|k��rn�n�|�||�} | sJ�q| �d�| �d��} }| �d�}| d�dkr�|s|q|�|| dd���|f��q| ���tjv�r�|s�d�S�|d�u�r�| ���tjv�r�|�|| df��q�d�S�n|�|| t |�f��q|d�u�r|�|| |�� |�f��d}qd�S�qd�}|D�]Z\} } }| |k�rP|d�u�sFJ��||| <�n,| |k�s^J��|\}}|��| ||��|�| �}�q$d�S�) Nr���Fr���r���r=���rH����$T)r!����match�group�endrd���rD���r+���r9���rf���r#���rs���rz���)r<���r���Zpatt�ir ���Zparsed_itemsZmorsel_seenZTYPE_ATTRIBUTEZ TYPE_KEYVALUEr����r=���rA���ry����tpr{���r|���r ���r ���r���Z__parse_string ��sJ���� zBaseCookie.__parse_string)N)NrY���r}���)N)r���r���r ���ri���rs���ru���r>���rz���r;���r]���rm���r`���rb���rv����_CookiePatternr����r ���r ���r ���r���r������s��� r���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�r?���)r#���rr���r ���r ���r���rs���M��s����zSimpleCookie.value_decodec�����������������C���s���t�|�}|t|�fS�r?���)r���r���rt���r ���r ���r���ru���P��s����zSimpleCookie.value_encodeN)r���r���r ���ri���rs���ru���r ���r ���r ���r���r���F��s���r���)*ri����re�stringro����__all__r~���r����rg���r����� Exceptionr���� ascii_letters�digitsZ_LegalCharsZ_UnescapedCharsrT����range�map�ordr���rM����compile�escape� fullmatchr���r����subr"���r���r#���Z_weekdaynameZ _monthnamer*���r:���r+���Z_LegalKeyCharsZ_LegalValueChars�ASCII�VERBOSEr����r���r���r ���r ���r ���r����<module>'���sV���]�� �6���� ��