o
     JAfP  ã                   @   sZ  d Z ddlZddlZddlZg d¢ZdjZdjZdjZG dd„ de	ƒZ
ejej d	 Zed
 Zdd„ eedƒƒeeeeƒƒ D ƒZe edƒdedƒdi¡ e de e¡ ¡jZdd„ Ze d¡Ze d¡Zdd„ Zg d¢Zg d¢Zdeefdd„ZG dd„ de ƒZ!dZ"e"d  Z#e d!e" d" e# d# ej$ej%B ¡Z&G d$d%„ d%e ƒZ'G d&d'„ d'e'ƒZ(dS )(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 Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__© r
   r
   ú#/usr/lib/python3.10/http/cookies.pyr   ‘   s    r   z!#$%&'*+-.^_`|~:z ()/<=>?@[]{}c                 C   s   i | ]}|d | “qS )z\%03or
   )Ú.0Únr
   r
   r   Ú
<dictcomp>¥   s    ÿr   é   ú"ú\"ú\z\\z[%s]+c                 C   s&   | du st | ƒr
| S d|  t¡ d S )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   sn  | d u s
t | ƒdk r| S | d dks| d dkr| S | dd… } d}t | ƒ}g }d|  kr2|k r³n t|ƒS t | |¡}t | |¡}|sU|sU| | |d … ¡ 	 t|ƒS d }}|r`| d¡}|rg| d¡}|r†|ro||k r†| | ||… ¡ | | |d  ¡ |d }n| | ||… ¡ | tt| |d |d … dƒƒ¡ |d }d|  kr²|k s7t|ƒS  t|ƒS )Né   r   r   éÿÿÿÿé   é   é   )	ÚlenÚ
_OctalPattÚsearchÚ
_QuotePattÚappendÚstartÚchrÚintÚ	_nulljoin)r   Úir   ÚresZo_matchZq_matchÚjÚkr
   r
   r   Ú_unquote¾   s@   íó


$íìr+   )ZMonZTueZWedZThuZFriZSatZSun)NZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc              	   C   sR   ddl m}m } |ƒ }|||  ƒ\	}}}}	}
}}}}d|| ||| ||	|
|f S )Nr   )ÚgmtimeÚtimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r-   r,   )ÚfutureZweekdaynameZ	monthnamer,   r-   ZnowZyearZmonthZdayZhhZmmÚssZwdÚyÚzr
   r
   r   Ú_getdateö   s   ÿr2   c                
   @   sà   e Zd ZdZdddddddd	d
dœ	ZddhZdd„ Zedd„ ƒZedd„ ƒZ	edd„ ƒZ
dd„ Zd2dd„Zdd„ ZejZdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd3d*d+„ZeZd,d-„ Zd2d.d/„Zd2d0d1„ZeejƒZdS )4Ú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ÚCommentZDomainzMax-AgeZSecureZHttpOnlyZVersionZSameSite)	r4   ÚpathÚcommentÚdomainúmax-ageÚsecureÚhttponlyÚversionZsamesiter;   r<   c                 C   s0   d  | _  | _| _| jD ]	}t | |d¡ qd S )Nr   )Ú_keyÚ_valueÚ_coded_valueÚ	_reservedÚdictÚ__setitem__)ÚselfÚkeyr
   r
   r   Ú__init__!  s   
ÿzMorsel.__init__c                 C   ó   | j S ©N)r>   ©rD   r
   r
   r   rE   )  ó   z
Morsel.keyc                 C   rG   rH   )r?   rI   r
   r
   r   Úvalue-  rJ   zMorsel.valuec                 C   rG   rH   )r@   rI   r
   r
   r   Úcoded_value1  rJ   zMorsel.coded_valuec                 C   s2   |  ¡ }|| jvrtd|f ƒ‚t | ||¡ d S ©NzInvalid attribute %r)ÚlowerrA   r   rB   rC   )rD   ÚKÚVr
   r
   r   rC   5  s   
zMorsel.__setitem__Nc                 C   s.   |  ¡ }|| jvrtd|f ƒ‚t | ||¡S rM   )rN   rA   r   rB   Ú
setdefault)rD   rE   Úvalr
   r
   r   rQ   ;  s   
zMorsel.setdefaultc                 C   s>   t |tƒstS t | |¡o| j|jko| j|jko| j|jkS rH   )Ú
isinstancer3   ÚNotImplementedrB   Ú__eq__r?   r>   r@   ©rD   Zmorselr
   r
   r   rU   A  s   

ÿ
þ
ýzMorsel.__eq__c                 C   s$   t ƒ }t || ¡ |j | j¡ |S rH   )r3   rB   ÚupdateÚ__dict__rV   r
   r
   r   ÚcopyK  s   zMorsel.copyc                 C   sR   i }t |ƒ ¡ D ]\}}| ¡ }|| jvrtd|f ƒ‚|||< qt  | |¡ d S rM   )rB   ÚitemsrN   rA   r   rW   )rD   ÚvaluesÚdatarE   rR   r
   r
   r   rW   Q  s   

zMorsel.updatec                 C   s   |  ¡ | jv S rH   )rN   rA   )rD   rO   r
   r
   r   ÚisReservedKeyZ  s   zMorsel.isReservedKeyc                 C   sH   |  ¡ | jv rtd|f ƒ‚t|ƒstd|f ƒ‚|| _|| _|| _d S )Nz Attempt to set a reserved key %rzIllegal key %r)rN   rA   r   r   r>   r?   r@   )rD   rE   rR   Z	coded_valr
   r
   r   Úset]  s   
z
Morsel.setc                 C   s   | j | j| jdœS )N)rE   rK   rL   ©r>   r?   r@   rI   r
   r
   r   Ú__getstate__h  s   ýzMorsel.__getstate__c                 C   s"   |d | _ |d | _|d | _d S )NrE   rK   rL   r_   )rD   Ústater
   r
   r   Ú__setstate__o  s   

zMorsel.__setstate__úSet-Cookie:c                 C   s   d||   |¡f S )Nz%s %s)ÚOutputString)rD   ÚattrsÚheaderr
   r
   r   Úoutputt  s   zMorsel.outputc                 C   s   d| j j|  ¡ f S )Nú<%s: %s>)Ú	__class__r   rd   rI   r
   r
   r   Ú__repr__y  s   zMorsel.__repr__c                 C   s   d|   |¡ dd¡ S )Nz—
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        r   r   )rd   Úreplace)rD   re   r
   r
   r   Ú	js_output|  s   úzMorsel.js_outputc                 C   s   g }|j }|d| j| jf ƒ |d u r| j}t|  ¡ ƒ}|D ]m\}}|dkr'q||vr,q|dkrCt|tƒrC|d| j| t|ƒf ƒ q|dkrXt|tƒrX|d| j| |f ƒ q|dkrot|t	ƒro|d| j| t
|ƒf ƒ q|| jv r€|r|t	| j| ƒƒ q|d| j| |f ƒ qt|ƒS )Nú%s=%sr   r4   r:   z%s=%dr8   )r"   rE   rL   rA   ÚsortedrZ   rS   r%   r2   r   r   Ú_flagsÚ_semispacejoin)rD   re   Úresultr"   rZ   rE   rK   r
   r
   r   rd   †  s.   
€zMorsel.OutputStringrH   )Nrc   )r   r   r	   Ú__doc__rA   ro   rF   ÚpropertyrE   rK   rL   rC   rQ   rU   ÚobjectÚ__ne__rY   rW   r]   r^   r`   rb   rg   Ú__str__rj   rl   rd   ÚclassmethodÚtypesÚGenericAliasÚ__class_getitem__r
   r
   r
   r   r3   þ   sH    ÷



	



!r3   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 Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zdd„ Zddd„Z	e	Z
dd„ Zddd„Zdd„ Zefdd„ZdS )r   z'A container class for a set of Morsels.c                 C   s   ||fS )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
   ©rD   rR   r
   r
   r   Úvalue_decodeÏ  s   zBaseCookie.value_decodec                 C   s   t |ƒ}||fS )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   ©rD   rR   Zstrvalr
   r
   r   Úvalue_encodeØ  s   zBaseCookie.value_encodeNc                 C   s   |r	|   |¡ d S d S rH   )Úload)rD   Úinputr
   r
   r   rF   á  s   ÿzBaseCookie.__init__c                 C   s.   |   |tƒ ¡}| |||¡ t | ||¡ dS )z+Private method for setting a cookie's valueN)Úgetr3   r^   rB   rC   )rD   rE   Z
real_valuerL   ÚMr
   r
   r   Z__setå  s   zBaseCookie.__setc                 C   s<   t |tƒrt | ||¡ dS |  |¡\}}|  |||¡ dS )zDictionary style assignment.N)rS   r3   rB   rC   r~   Ú_BaseCookie__set)rD   rE   rK   ÚrvalÚcvalr
   r
   r   rC   ë  s   
zBaseCookie.__setitem__rc   ú
c                 C   s:   g }t |  ¡ ƒ}|D ]\}}| | ||¡¡ q
| |¡S )z"Return a string suitable for HTTP.)rn   rZ   r"   rg   Újoin)rD   re   rf   Úseprq   rZ   rE   rK   r
   r
   r   rg   ô  s
   
zBaseCookie.outputc                 C   sJ   g }t |  ¡ ƒ}|D ]\}}| d|t|jƒf ¡ q
d| jjt|ƒf S )Nrm   rh   )rn   rZ   r"   ÚreprrK   ri   r   Ú
_spacejoin)rD   ÚlrZ   rE   rK   r
   r
   r   rj   þ  s
   zBaseCookie.__repr__c                 C   s6   g }t |  ¡ ƒ}|D ]\}}| | |¡¡ q
t|ƒS )z(Return a string suitable for JavaScript.)rn   rZ   r"   rl   r&   )rD   re   rq   rZ   rE   rK   r
   r
   r   rl     s
   zBaseCookie.js_outputc                 C   s6   t |tƒr|  |¡ dS | ¡ D ]\}}|| |< qdS )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)rS   r   Ú_BaseCookie__parse_stringrZ   )rD   ZrawdatarE   rK   r
   r
   r   r     s   

þ
zBaseCookie.loadc                 C   sp  d}t |ƒ}g }d}d}d}d|  kr|k r”n nz| ||¡}	|	s#nq|	 d¡|	 d¡}
}|	 d¡}|
d dkrI|s<q| ||
dd … |f¡ n@|
 ¡ tjv ru|sTd S |d u rj|
 ¡ tjv rh| ||
df¡ n!d S | ||
t	|ƒf¡ n|d ur‡| ||
|  
|¡f¡ d}nd S d|  kr“|k sn d }|D ]\}}
}||kr¦|||
< q˜|\}}|  |
||¡ | |
 }q˜d S )	Nr   Fr   r   rE   rR   ú$T)r   ÚmatchÚgroupÚendr"   rN   r3   rA   ro   r+   r|   rƒ   )rD   r   Zpattr'   r   Zparsed_itemsZmorsel_seenZTYPE_ATTRIBUTEZTYPE_KEYVALUErŽ   rE   rK   r‚   Útpr„   r…   r
   r
   r   Z__parse_string  sJ   
Þ%

øzBaseCookie.__parse_stringrH   )Nrc   r†   )r   r   r	   rr   r|   r~   rF   rƒ   rC   rg   rv   rj   rl   r   Ú_CookiePatternrŒ   r
   r
   r
   r   r   Ì  s    	
	
	
r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )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 |ƒ|fS rH   )r+   r{   r
   r
   r   r|   _  s   zSimpleCookie.value_decodec                 C   s   t |ƒ}|t|ƒfS rH   )r   r   r}   r
   r
   r   r~   b  s   zSimpleCookie.value_encodeN)r   r   r	   rr   r|   r~   r
   r
   r
   r   r   X  s    r   ))rr   ÚreÚstringrx   Ú__all__r‡   r&   rp   rŠ   Ú	Exceptionr   Úascii_lettersÚdigitsZ_LegalCharsZ_UnescapedCharsr^   ÚrangeÚmapÚordr   rW   ÚcompileÚescapeÚ	fullmatchr   r   r   r!   r+   Z_weekdaynameZ
_monthnamer2   rB   r3   Z_LegalKeyCharsZ_LegalValueCharsÚASCIIÚVERBOSEr’   r   r   r
   r
   r
   r   Ú<module>   sX   &]ÿþ

2 6ýýôô
ï 