
    0iQ                        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e	          Z
ej        ej        z   d	z   Zed
z   Zd  e ed                     e eee                    z
  D             Ze                     ed          d ed          di            ej        d ej        e          z            j        Z ej        d          Zd Zd Z ej        d          j        Zd Zd Zg dZ g dZ!de e!fdZ" G d de#          Z$dZ%e%dz   Z& ej        de%z   d z   e&z   d!z   ej'        ej(        z            Z) G d" d#e#          Z* G 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=;";')
   >>> print(C)
   Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=;"

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                       e Zd ZdS )r   N)__name__
__module____qualname__     %/usr/lib64/python3.11/http/cookies.pyr   r      s        Dr   r   z!#$%&'*+-.^_`|~:z ()/<=>?@[]{}c                     i | ]}|d |z  	S )z\%03or   ).0ns     r   
<dictcomp>r      s4     J J J (Q, J J Jr      "\"\z\\z[%s]+z[\x00-\x1F\x7F]c                  4    t          d | D                       S )zhDetects control characters within a value.
    Supports any type, as header values can be any type.
    c              3   d   K   | ]+}t                               t          |                    V  ,d S N)_control_character_researchstr)r   vs     r   	<genexpr>z)_has_control_character.<locals>.<genexpr>   s7      AA$++CFF33AAAAAAr   )any)vals    r   _has_control_characterr!      s!     AASAAAAAAr   c                 h    | t          |           r| S d|                     t                    z   dz   S )zQuote 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r   s    r   _quoter'      s6     {mC(({
S]];///#55r   z\\(?:([0-3][0-7][0-7])|(.))c                 h    | d         r#t          t          | d         d                    S | d         S )N         )chrint)ms    r   _unquote_replacer/      s1    t 3qtQ<<   tr   c                     | t          |           dk     r| S | d         dk    s| d         dk    r| S | dd         } t          t          |           S )Nr+   r   r   r)   )len_unquote_subr/   r&   s    r   _unquoter4      s\     {c#hhll

1v}}B3
 ad)C (#...r   )MonTueWedThuFriSatSun)NJanFebMarAprMayJunJulAugSepOctNovDecc           	          ddl m}m }  |            } ||| z             \	  }}}}	}
}}}}d||         |||         ||	|
|fz  S )Nr   )gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)rJ   rI   )futureweekdayname	monthnamerI   rJ   nowyearmonthdayhhmmsswdyzs                  r   _getdaterX      su    !!!!!!!!
$&&C-3VC&L-A-A*D%b"b"a0OS)E"2D"b"EF Fr   c            
          e Zd ZdZdddddddd	d
d	ZddhZd Zed             Zed             Z	ed             Z
d Zd!dZd Zej        Zd Zd Zd Zd Zd Zd Zd"dZeZd Zd!dZd!d Z eej                  ZdS )#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CommentDomainzMax-AgeSecureHttpOnlyVersionSameSite)	r[   pathcommentdomainmax-agesecurehttponlyversionsamesiterg   rh   c                 |    d x| _         x| _        | _        | j        D ]}t                              | |d           d S )Nr   )_key_value_coded_value	_reserveddict__setitem__)selfkeys     r   __init__zMorsel.__init__  sP    6::	:DK$"3 > 	, 	,CT3++++	, 	,r   c                     | j         S r   )rl   rr   s    r   rs   z
Morsel.key   s
    yr   c                     | j         S r   )rm   rv   s    r   valuezMorsel.value$  s
    {r   c                     | j         S r   )rn   rv   s    r   coded_valuezMorsel.coded_value(  s      r   c                     |                                 }|| j        vrt          d|          t          ||          rt          d|d|          t                              | ||           d S NInvalid attribute .Control characters are not allowed in cookies r   )lowerro   r   r!   rp   rq   )rr   KVs      r   rq   zMorsel.__setitem__,  s    GGIIDN""+;<<<!!Q'' 	\ZqZZUVZZ[[[q!$$$$$r   Nc                     |                                 }|| j        vrt          d|          t          ||          rt          d|d|          t                              | ||          S r|   )r   ro   r   r!   rp   
setdefault)rr   rs   r    s      r   r   zMorsel.setdefault4  sz    iikkdn$$+=>>>!#s++ 	c+WZWZWZ\_\_abbbtS#...r   c                     t          |t                    st          S t                              | |          o/| j        |j        k    o| j        |j        k    o| j        |j        k    S r   )
isinstancerZ   NotImplementedrp   __eq__rm   rl   rn   rr   morsels     r   r   zMorsel.__eq__<  sg    &&)) 	"!!D&)) 9v},9	V[(9 !V%88	:r   c                     t                      }t                              ||            |j                            | j                   |S r   )rZ   rp   update__dict__r   s     r   copyzMorsel.copyF  s<    FD!!!t}---r   c                     i }t          |                                          D ]9\  }}|                                }|| j        vrt	          d|          |||<   :t                               | |           d S )Nr}   )rp   itemsr   ro   r   r   )rr   valuesdatars   r    s        r   r   zMorsel.updateL  s    V**,, 	 	HC))++C$.((!kCC"ABBBDIID$r   c                 8    |                                 | j        v S r   )r   ro   )rr   r   s     r   isReservedKeyzMorsel.isReservedKeyU  s    wwyyDN**r   c                    |                                 | j        v rt          d|          t          |          st          d|          t	          |||          rt          d|d|d|          || _        || _        || _        d S )NzAttempt to set a reserved key zIllegal key r~   r   )r   ro   r   r#   r!   rl   rm   rn   )rr   rs   r    	coded_vals       r   setz
Morsel.setX  s    99;;$.((+CCIJJJS!! 	9+##7888!#sI66 	c+LOCCQTQTQTV_V_ac c c 	%r   c                 ,    | j         | j        | j        dS )N)rs   rx   rz   rl   rm   rn   rv   s    r   __getstate__zMorsel.__getstate__f  s!    9[,
 
 	
r   c                 T    |d         | _         |d         | _        |d         | _        d S )Nrs   rx   rz   r   )rr   states     r   __setstate__zMorsel.__setstate__m  s+    %L	Gn!-0r   Set-Cookie:c                 6    |d|                      |          S )Nr   )OutputString)rr   attrsheaders      r   outputzMorsel.outputr  s"     &&$"3"3E":":":;;r   c                 L    d| j         j        d|                                 dS )N<: >)	__class__r	   r   rv   s    r   __repr__zMorsel.__repr__w  s,     !^444d6G6G6I6I6I6IJJr   c                 Z    d|                      |                              dd          z  S )Nz
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        r   r   )r   replace)rr   r   s     r   	js_outputzMorsel.js_outputz  s4       ''//U;;= 	=r   c                    g }|j         } || j        d| j                   || j        }t	          |                                           }|D ]\  }}|dk    r||vr|dk    r>t          |t                    r) || j        |         dt          |                     V|dk    r1t          |t                    r |d| j        |         |fz             |dk    r>t          |t                    r) || j        |         dt          |                     || j        v r'|r# |t          | j        |                               || j        |         d|           t          |          S )N=r   r[   rf   z%s=%drd   )appendrs   rz   ro   sortedr   r   r-   rX   r   r'   _flags_semispacejoin)rr   r   resultr   r   rs   rx   s          r   r   zMorsel.OutputString  s     	$(((D$4$45666 =NEtzz||$$ 	? 	?JC{{%iJuc$:$:$."5"5"5xGHHHH	!!j&<&<!w$."5u!==>>>>	!!j&<&<!$."5"5"5ve}}}EFFFF## 5F3t~c233444$."5"5"5uu=>>>> f%%%r   r   )Nr   )r	   r
   r   __doc__ro   r   rt   propertyrs   rx   rz   rq   r   r   object__ne__r   r   r   r   r   r   r   __str__r   r   r   classmethodtypesGenericAlias__class_getitem__r   r   r   rZ   rZ      s        * 
 
I 
#F, , ,   X   X ! ! X!% % %/ / / /: : : ]F       + + +& & &
 
 
1 1 1
< < < < GK K K= = = =& & & &B $E$677r   rZ   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                   \    e Zd ZdZd Zd ZddZd Zd Zdd
Z	e	Z
d ZddZd ZefdZdS )r   z'A container class for a set of Morsels.c                 
    ||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   rr   r    s     r   value_decodezBaseCookie.value_decode  s     Cxr   c                 (    t          |          }||fS )zreal_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&   rr   r    strvals      r   value_encodezBaseCookie.value_encode  s     Sv~r   Nc                 8    |r|                      |           d S d S r   )load)rr   inputs     r   rt   zBaseCookie.__init__  s,     	IIe	 	r   c                     |                      |t                                }|                    |||           t                              | ||           dS )z+Private method for setting a cookie's valueN)getrZ   r   rp   rq   )rr   rs   
real_valuerz   Ms        r   __setzBaseCookie.__set  sM    HHS&((##	c:{+++sA&&&&&r   c                     t          |t                    rt                              | ||           dS |                     |          \  }}|                     |||           dS )zDictionary style assignment.N)r   rZ   rp   rq   r   _BaseCookie__set)rr   rs   rx   rvalcvals        r   rq   zBaseCookie.__setitem__  se    eV$$ 	(T3.....**511JD$JJsD$'''''r   r   
c                    g }t          |                                           }|D ]N\  }}|                    ||          }t          |          rt	          d          |                    |           O|                    |          S )z"Return a string suitable for HTTP.z-Control characters are not allowed in cookies)r   r   r   r!   r   r   join)	rr   r   r   sepr   r   rs   rx   value_outputs	            r   r   zBaseCookie.output  s    tzz||$$ 	( 	(JC <<v66L%l33 S!"QRRRMM,''''xxr   c                     g }t          |                                           }|D ]1\  }}|                    |dt          |j                             2d| j        j        dt          |          dS )Nr   r   r   r   )r   r   r   reprrx   r   r	   
_spacejoin)rr   lr   rs   rx   s        r   r   zBaseCookie.__repr__  s    tzz||$$ 	9 	9JCHHT%+%6%6%678888	9!^444jmmmmDDr   c                     g }t          |                                           }|D ]-\  }}|                    |                    |                     .t	          |          S )z(Return a string suitable for JavaScript.)r   r   r   r   	_nulljoin)rr   r   r   r   rs   rx   s         r   r   zBaseCookie.js_output  s^    tzz||$$ 	2 	2JCMM%//%001111   r   c                     t          |t                    r|                     |           n|                                D ]
\  }}|| |<   dS )zLoad 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)r   r   _BaseCookie__parse_stringr   )rr   rawdatars   rx   s       r   r   zBaseCookie.load  sZ     gs## 	"(((( &mmoo " "
U!S		r   c                 v   d}t          |          }g }d}d}d}d|cxk    r|k     rVn nR|                    ||          }	|	sn8|	                    d          |	                    d          }}
|	                    d          }|
d         dk    r$|sz|                    ||
dd          |f           n|
                                t          j        v rg|sd S |;|
                                t          j        v r|                    ||
df           nZd S |                    ||
t          |          f           n2|.|                    ||
| 
                    |          f           d}nd S d|cxk    r|k     Pn d }|D ]6\  }}
}||k    r|||
<   |\  }}|                     |
||           | |
         }7d S )	Nr   Fr)   r+   rs   r    $T)r2   matchgroupendr   r   rZ   ro   r   r4   r   r   )rr   r   pattir   parsed_itemsmorsel_seenTYPE_ATTRIBUTETYPE_KEYVALUEr   rs   rx   r   tpr   r   s                   r   __parse_stringzBaseCookie.__parse_string  s   HH
 1jjjjqjjjjjJJsA&&E U++U[[-?-?C		!A1v}}"  ##^SWe$DEEEE 000" F=yy{{fm33$++^S$,GHHHH  ''huoo(NOOOO"##]C9J9J59Q9Q$RSSS" E 1jjjjqjjjjJ * 	 	NBU^### #
d

3d+++I	 	r   r   )Nr   r   )r	   r
   r   r   r   r   rt   r   rq   r   r   r   r   r   _CookiePatternr   r   r   r   r   r     s        11       ' ' '( ( (	  	  	  	  GE E E! ! ! !   (6 : : : : : :r   r   c                       e Zd ZdZd Z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                 $    t          |          |fS r   )r4   r   s     r   r   zSimpleCookie.value_decode`  s    }}c!!r   c                 B    t          |          }|t          |          fS r   )r   r'   r   s      r   r   zSimpleCookie.value_encodec  s    Svf~~%%r   N)r	   r
   r   r   r   r   r   r   r   r   r   Y  s<         " " "& & & & &r   r   ),r   restringr   __all__r   r   r   r   	Exceptionr   ascii_lettersdigits_LegalChars_UnescapedCharsr   rangemapordr%   r   compileescape	fullmatchr#   r   r!   r'   subr3   r/   r4   _weekdayname
_monthnamerX   rp   rZ   _LegalKeyChars_LegalValueCharsASCIIVERBOSEr   r   r   r   r   r   <module>r     s  NX Xz 
			  
7
7
7G	X

	 	 	 	 	) 	 	 	" "V]25GG/J JEE#JJ##cc#.G.G*H*HHJ J J   CHHeCIIv   
 
7YRY{%;%;;<<F"
#566 B B B
6 
6 
6 rz899=  / / /6 A@@8 8 8
 <: F F F Fp8 p8 p8 p8 p8T p8 p8 p8x B!G+  	 			 " 
BJ	#   .L L L L L L L L^& & & & &: & & & & &r   