
    F\hM                        S r SSKrSSKrSSKr/ SQrSR
                  rSR
                  rSR
                  r " S S\	5      r
\R                  \R                  -   S	-   r\S
-   r\" \" S5      5      \" \" \\5      5      -
   V s0 s H	  n U SU -  _M     sn r\R)                  \" S5      S\" S5      S05        \R*                  " S\R,                  " \5      -  5      R.                  rS r\R*                  " S5      R4                  rS rS r/ SQr/ SQrS\\4S jr  " S S\!5      r"Sr#\#S-   r$\R*                  " S\#-   S-   \$-   S-   \RJ                  \RL                  -  5      r' " S  S!\!5      r( " S" S#\(5      r)gs  sn f )$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                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r
       #/usr/lib/python3.13/http/cookies.pyr   r      s    r   r   z!#$%&'*+-.^_`|~:z ()/<=>?@[]{}   z\%03o"\"\z\\z[%s]+c                 b    U b  [        U 5      (       a  U $ SU R                  [        5      -   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.
r   )_is_legal_key	translate_Translatorstrs    r   _quoter      s1     {mC((
S]];//#55r   z\\(?:([0-3][0-7][0-7])|(.))c                 P    U S   (       a  [        [        U S   S5      5      $ U S   $ )N         )chrint)ms    r   _unquote_replacer$      s'    t3qtQ<  tr   c                 |    U b  [        U 5      S:  a  U $ U S   S:w  d	  U S   S:w  a  U $ U SS n [        [        U 5      $ )Nr    r   r   r   )len_unquote_subr$   r   s    r   _unquoter)      sO     {c#hl

1v}B3
 a)C (#..r   )MonTueWedThuFriSatSun)NJanFebMarAprMayJunJulAugSepOctNovDecc           	      \    SSK JnJ n  U" 5       nU" XP-   5      u	  pgpppnSX   XU   XiX4-  $ )Nr   )gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r?   r>   )futureweekdayname	monthnamer>   r?   nowyearmonthdayhhmmsswdyzs                  r   _getdaterM      sE    !
&C-3CL-A*D""0OSE"2DbEF Fr   c            
          \ rS rSrSrSSSSSSS	S
SS.	rSS1rS r\S 5       r	\S 5       r
\S 5       rS rS"S jrS r\R                   rS rS rS rS rS rS rS#S jr\rS rS"S jrS"S  jr\" \R<                  5      rS!r g)$Morsel   a/  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)	rQ   pathcommentdomainmax-agesecurehttponlyversionsamesiter]   r^   c                     S =U l         =U l        U l        U R                   H  n[        R                  XS5        M     g )Nr   )_key_value_coded_value	_reserveddict__setitem__)selfkeys     r   __init__Morsel.__init__  s8    6::	:DK$"3 >>CT+ "r   c                     U R                   $ N)rb   rh   s    r   ri   
Morsel.key  s    yyr   c                     U R                   $ rm   )rc   rn   s    r   valueMorsel.value  s    {{r   c                     U R                   $ rm   )rd   rn   s    r   coded_valueMorsel.coded_value  s       r   c                     UR                  5       nXR                  ;  a  [        SU< 35      e[        R	                  XU5        g NzInvalid attribute )lowerre   r   rf   rg   )rh   KVs      r   rg   Morsel.__setitem__#  s5    GGINN";<<!$r   Nc                     UR                  5       nXR                  ;  a  [        SU< 35      e[        R	                  XU5      $ rw   )rx   re   r   rf   
setdefault)rh   ri   vals      r   r}   Morsel.setdefault)  s6    iiknn$=>>t#..r   c                 "   [        U[        5      (       d  [        $ [        R	                  X5      =(       aY    U R
                  UR
                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ rm   )
isinstancerO   NotImplementedrf   __eq__rc   rb   rd   rh   morsels     r   r   Morsel.__eq__/  sk    &&))!!D) 9v}},9		V[[(9 !!V%8%88	:r   c                     [        5       n[        R                  X5        UR                  R                  U R                  5        U$ rm   )rO   rf   update__dict__r   s     r   copyMorsel.copy9  s0    F!t}}-r   c                     0 n[        U5      R                  5        H7  u  p4UR                  5       nX0R                  ;  a  [	        SU< 35      eXBU'   M9     [         R                  X5        g rw   )rf   itemsrx   re   r   r   )rh   valuesdatari   r~   s        r   r   Morsel.update?  sX    V**,HC))+C..(!C"ABBI	 -
 	Dr   c                 <    UR                  5       U R                  ;   $ rm   )rx   re   )rh   ry   s     r   isReservedKeyMorsel.isReservedKeyH  s    wwyDNN**r   c                     UR                  5       U R                  ;   a  [        SU< 35      e[        U5      (       d  [        SU< 35      eXl        X l        X0l        g )NzAttempt to set a reserved key zIllegal key )rx   re   r   r   rb   rc   rd   )rh   ri   r~   	coded_vals       r   set
Morsel.setK  sM    99;$..(CIJJS!!#788 	%r   c                 J    U R                   U R                  U R                  S.$ )N)ri   rq   rt   rb   rc   rd   rn   s    r   __getstate__Morsel.__getstate__V  s#    99[[,,
 	
r   c                 @    US   U l         US   U l        US   U l        g )Nri   rq   rt   r   )rh   states     r   __setstate__Morsel.__setstate__]  s%    %L	Gn!-0r   c                 2    U< SU R                  U5      < 3$ )Nr   )OutputString)rh   attrsheaders      r   outputMorsel.outputb  s     $"3"3E":;;r   c                 \    SU R                   R                  < SU R                  5       < S3$ )N<: >)	__class__r   r   rn   s    r   __repr__Morsel.__repr__g  s     !^^44d6G6G6IJJr   c                 J    SU R                  U5      R                  SS5      -  $ )Nz
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        r   r   )r   replace)rh   r   s     r   	js_outputMorsel.js_outputj  s.       '//U;= 	=r   c                 $   / nUR                   nU" U R                  < SU R                  < 35        Uc  U R                  n[	        U R                  5       5      nU GH&  u  pVUS:X  a  M  XQ;  a  M  US:X  a<  [        U[        5      (       a'  U" U R                  U   < S[        U5      < 35        MW  US:X  a1  [        U[        5      (       a  U" SU R                  U   U4-  5        M  US:X  a<  [        U[        5      (       a'  U" U R                  U   < S[        U5      < 35        M  XPR                  ;   a+  U(       a!  U" [        U R                  U   5      5        GM  GM
  U" U R                  U   < SU< 35        GM)     [        U5      $ )N=r   rQ   r\   z%s=%drZ   )appendri   rt   re   sortedr   r   r"   rM   r   r   _flags_semispacejoin)rh   r   resultr   r   ri   rq   s          r   r   Morsel.OutputStringt  sB     	$((D$4$456 =NNEtzz|$JC{iJuc$:$:$.."5xGH	!j&<&<w$.."5u!==>	!j&<&<$.."5ve}EF#3t~~c234  $.."5u=>  $ f%%r   )rd   rb   rc   rm   )NSet-Cookie:)!r   r   r   r   __doc__re   r   rj   propertyri   rq   rt   rg   r}   r   object__ne__r   r   r   r   r   r   r   __str__r   r   r   classmethodtypesGenericAlias__class_getitem__r   r
   r   r   rO   rO      s    * 
I 
#F,     ! !%/: ]]F +	&
1
< GK=&B $E$6$67r   rO   z,\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=z\[\]z
    \s*                            # Optional whitespace at start of cookie
    (?P<key>                       # Start of group 'key'
    [ax  ]+?   # 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 double-quoted string
    |                                  # or
    # Special case for "expires" attr
    (\w{3,6}day|\w{3}),\s              # Day of the week or abbreviated day
    [\w\d\s-]{9,11}\s[\d:]{8}\sGMT     # Date and time in specific format
    |                                  # 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                   j    \ rS rSrSrS rS rSS jrS rS r	SS	 jr
\
rS
 rSS jrS r\4S jrSrg)r   i  z'A container class for a set of Morsels.c                     X4$ )zreal_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
   rh   r~   s     r   value_decodeBaseCookie.value_decode  s     xr   c                     [        U5      nX"4$ )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   rh   r~   strvals      r   value_encodeBaseCookie.value_encode  s     S~r   Nc                 6    U(       a  U R                  U5        g g rm   )load)rh   inputs     r   rj   BaseCookie.__init__  s    IIe r   c                     U R                  U[        5       5      nUR                  XU5        [        R	                  XU5        g)z+Private method for setting a cookie's valueN)getrO   r   rf   rg   )rh   ri   
real_valuert   Ms        r   __setBaseCookie.__set  s2    HHS&(#	c{+A&r   c                     [        U[        5      (       a  [        R                  XU5        gU R	                  U5      u  p4U R                  XU5        g)zDictionary style assignment.N)r   rO   rf   rg   r   _BaseCookie__set)rh   ri   rq   rvalcvals        r   rg   BaseCookie.__setitem__  s?    eV$$T.**51JDJJs$'r   c                     / n[        U R                  5       5      nU H%  u  pgUR                  UR                  X5      5        M'     UR	                  U5      $ )z"Return a string suitable for HTTP.)r   r   r   r   join)rh   r   r   sepr   r   ri   rq   s           r   r   BaseCookie.output  sG    tzz|$JCMM%,,u56  xxr   c                     / n[        U R                  5       5      nU H0  u  p4UR                  U< S[        UR                  5      < 35        M2     SU R
                  R                  < S[        U5      < S3$ )Nr   r   r   r   )r   r   r   reprrq   r   r   
_spacejoin)rh   lr   ri   rq   s        r   r   BaseCookie.__repr__  sV    tzz|$JCHHT%++%678  !^^44jmDDr   c                     / n[        U R                  5       5      nU H%  u  pEUR                  UR                  U5      5        M'     [	        U5      $ )z(Return a string suitable for JavaScript.)r   r   r   r   	_nulljoin)rh   r   r   r   ri   rq   s         r   r   BaseCookie.js_output  sC    tzz|$JCMM%//%01    r   c                     [        U[        5      (       a  U R                  U5        gUR                  5        H	  u  p#X0U'   M     g)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   )rh   rawdatari   rq   s       r   r   BaseCookie.load  sB     gs##(
 	 &mmo
!S	 .r   c                 2   Sn[        U5      n/ nSnSnSnSUs=::  a  U:  Ga5  O  GO1UR                  X5      n	U	(       d  GOU	R                  S5      U	R                  S5      pU	R                  S5      nU
S   S:X  a   U(       d  Mp  UR	                  XzSS  U45        OU
R                  5       [        R                  ;   a_  U(       d  g Uc7  U
R                  5       [        R                  ;   a  UR	                  XzS45        OGg UR	                  Xz[        U5      45        O)Ub%  UR	                  XU R                  U5      45        SnOg SUs=::  a	  U:  a  GM/  O  S nU H7  u  pnX:X  a  Uc   eXU
'   M  X:X  d   eUu  pU R                  XU5        X
   nM9     g )	Nr   Fr   r    ri   r~   $T)r'   matchgroupendr   rx   rO   re   r   r)   r   r   )rh   r   pattinparsed_itemsmorsel_seenTYPE_ATTRIBUTETYPE_KEYVALUEr   ri   rq   r   tpr   r   s                   r   __parse_stringBaseCookie.__parse_string  s   H
 1jqjjJJs&EU+U[[-?		!A1v}" ##^We$DE 0 00"=yy{fmm3$++^$,GH  ''huo(NO"##]9J9J59Q$RS" E 1jqjjJ *NBU#}$}#***"


3d+I +r   r
   rm   )Nr   z
)r   r   r   r   r   r   r   rj   r   rg   r   r   r   r   r   _CookiePatternr   r   r
   r   r   r   r     sD    1'(  GE! (6 :r   r   c                   $    \ rS rSrSrS rS rSrg)r   iH  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                     [        U5      U4$ rm   )r)   r   s     r   r   SimpleCookie.value_decodeO  s    }c!!r   c                 2    [        U5      nU[        U5      4$ rm   )r   r   r   s      r   r   SimpleCookie.value_encodeR  s    Svf~%%r   r
   N)r   r   r   r   r   r   r   r   r
   r   r   r   r   H  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   subr(   r$   r)   _weekdayname
_monthnamerM   rf   rO   _LegalKeyChars_LegalValueCharsASCIIVERBOSEr   r   r   )r   s   0r   <module>r     s  NXz 
  
7GG	XX

	) 	" ""V]]25GG/ E#J#c#.G*HHJH1 (Q,HJ   HeIv 
 

7RYY{%;;<FF
6 zz89==/6 A8
 <: Fi8T i8j B!G+  	 		 & 
BJJ	' 2I IX&: &GJs   E: