
    ѝivQ                     (   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\R*                  " S5      rS rS r\R*                  " S5      R8                  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!-   \RN                  \RP                  -  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=;";')
   >>> 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                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r
       lib/python3.13/http/cookies.pyr   r      s    r   r   z!#$%&'*+-.^_`|~:z ()/<=>?@[]{}   z\%03o"\"\z\\z[%s]+z[\x00-\x1F\x7F]c                  &    [        S U  5       5      $ )z`Detects control characters within a value.
Supports any type, as header values can be any type.
c              3   ^   #    U  H#  n[         R                  [        U5      5      v   M%     g 7fN)_control_character_researchstr).0vs     r   	<genexpr>)_has_control_character.<locals>.<genexpr>   s#     AS$++CF33Ss   +-)any)vals    r   _has_control_characterr"      s     ASAAAr   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r   s    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_replacer0      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_subr0   r'   s    r   _unquoter5      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)rK   rJ   )futureweekdayname	monthnamerJ   rK   nowyearmonthdayhhmmsswdyzs                  r   _getdaterY      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)	r]   pathcommentdomainmax-agesecurehttponlyversionsamesiteri   rj   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                   $ r   )rn   rt   s    r   ru   
Morsel.key   s    yyr   c                     U R                   $ r   )ro   ry   s    r   valueMorsel.value$  s    {{r   c                     U R                   $ r   )rp   ry   s    r   coded_valueMorsel.coded_value(  s       r   c                     UR                  5       nXR                  ;  a  [        SU< 35      e[        X5      (       a  [        SU< SU< 35      e[        R                  XU5        g NInvalid attribute .Control characters are not allowed in cookies r   )lowerrq   r   r"   rr   rs   )rt   KVs      r   rs   Morsel.__setitem__,  s\    GGINN";<<!!'' NqeSTUVTYZ[[!$r   Nc                     UR                  5       nXR                  ;  a  [        SU< 35      e[        X5      (       a  [        SU< SU< 35      e[        R                  XU5      $ r   )r   rq   r   r"   rr   
setdefault)rt   ru   r!   s      r   r   Morsel.setdefault4  sS    iiknn$=>>!#++WZ\_abb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  $ r   )
isinstancer[   NotImplementedrr   __eq__ro   rn   rp   rt   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$ r   )r[   rr   update__dict__r   s     r   copyMorsel.copyF  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 )Nr   )rr   itemsr   rq   r   r   )rt   valuesdataru   r!   s        r   r   Morsel.updateL  sX    V**,HC))+C..(!C"ABBI	 -
 	Dr   c                 <    UR                  5       U R                  ;   $ r   )r   rq   )rt   r   s     r   isReservedKeyMorsel.isReservedKeyU  s    wwyDNN**r   c                    UR                  5       U R                  ;   a  [        SU< 35      e[        U5      (       d  [        SU< 35      e[	        XU5      (       a  [        SU< SU< SU< 35      eXl        X l        X0l        g )NzAttempt to set a reserved key zIllegal key r   r   )r   rq   r   r$   r"   rn   ro   rp   )rt   ru   r!   	coded_vals       r   set
Morsel.setX  su    99;$..(CIJJS!!#788!#I66LOQTV_ac c 	%r   c                 J    U R                   U R                  U R                  S.$ )N)ru   r|   r   rn   ro   rp   ry   s    r   __getstate__Morsel.__getstate__f  s#    99[[,,
 	
r   c                 @    US   U l         US   U l        US   U l        g )Nru   r|   r   r   )rt   states     r   __setstate__Morsel.__setstate__m  s%    %L	Gn!-0r   c                 2    U< SU R                  U5      < 3$ )Nr   )OutputString)rt   attrsheaders      r   outputMorsel.outputr  s     $"3"3E":;;r   c                 \    SU R                   R                  < SU R                  5       < S3$ )N<: >)	__class__r   r   ry   s    r   __repr__Morsel.__repr__w  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)rt   r   s     r   	js_outputMorsel.js_outputz  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   r]   rh   z%s=%drf   )appendru   r   rq   sortedr   r   r.   rY   r   r(   _flags_semispacejoin)rt   r   resultr   r   ru   r|   s          r   r   Morsel.OutputString  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   )rp   rn   ro   r   )NSet-Cookie:)!r   r   r   r   __doc__rq   r   rv   propertyru   r|   r   rs   r   r   object__ne__r   r   r   r   r   r   r   __str__r   r   r   classmethodtypesGenericAlias__class_getitem__r   r
   r   r   r[   r[      s    * 
I 
#F,     ! !%/: ]]F +&
1
< GK=&B $E$6$67r   r[   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
   rt   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'   rt   r!   strvals      r   value_encodeBaseCookie.value_encode  s     S~r   Nc                 6    U(       a  U R                  U5        g g r   )load)rt   inputs     r   rv   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)getr[   r   rr   rs   )rt   ru   
real_valuer   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   r[   rr   rs   r   _BaseCookie__set)rt   ru   r|   rvalcvals        r   rs   BaseCookie.__setitem__  s?    eV$$T.**51JDJJs$'r   c                     / n[        U R                  5       5      nU HB  u  pgUR                  X5      n[        U5      (       a  [	        S5      eUR                  U5        MD     UR                  U5      $ )z"Return a string suitable for HTTP.z-Control characters are not allowed in cookies)r   r   r   r"   r   r   join)	rt   r   r   sepr   r   ru   r|   value_outputs	            r   r   BaseCookie.output  se    tzz|$JC <<6L%l33!"QRRMM,'	  
 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   reprr|   r   r   
_spacejoin)rt   lr   ru   r|   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)rt   r   r   r   ru   r|   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   )rt   rawdataru   r|   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,   ru   r!   $T)r3   matchgroupendr   r   r[   rq   r   r5   r   r   )rt   r   pattinparsed_itemsmorsel_seenTYPE_ATTRIBUTETYPE_KEYVALUEr   ru   r|   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
   r   )Nr   z
)r   r   r   r   r   r   r   rv   r   rs   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   i[  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$ r   )r5   r   s     r   r   SimpleCookie.value_decodeb  s    }c!!r   c                 2    [        U5      nU[        U5      4$ r   )r   r(   r   s      r   r   SimpleCookie.value_encodee  s    Svf~%%r   r
   N)r   r   r   r   r   r   r   r   r
   r   r   r   r   [  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(   subr4   r0   r5   _weekdayname
_monthnamerY   rr   r[   _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

#56 B
6 zz89==/6 A8
 <: Fp8T p8x B!G+  	 		 & 
BJJ	' 2L L^&: &mJs   F