v"SdZddlZddlZddlZgdZdjZdjZdjZGdde Z ej ej zd zZ e d zZd eed eeeez DZeed deddiejdeje zjZejdZdZdZejdjZdZdZgdZ gdZ!de e!fdZ"Gdde#Z$dZ%e%dzZ&ejde%zd ze&zd!zej'ej(zZ)Gd"d#e#Z*Gd$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=;";') >>> 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 SimpleCookiez;  ceZdZdS)rN)__name__ __module__ __qualname__3/opt/alt/python311/lib64/python3.11/http/cookies.pyrrsDr rz!#$%&'*+-.^_`|~:z ()/<=>?@[]{}ci|]}|d|z S)z\%03or ).0ns r rs4JJJ(Q,JJJr "\"\z\\z[%s]+z[\x00-\x1F\x7F]c4td|DS)zhDetects control characters within a value. Supports any type, as header values can be any type. c3dK|]+}tt|V,dSN)_control_character_researchstr)rvs r z)_has_control_character..s7AA$++CFF33AAAAAAr )any)vals r_has_control_characterr!s! AASAAA A AAr ch|t|r|Sd|tzdzS)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 _Translatorrs r_quoter's6 {mC(({ S]];///#55r z\\(?:([0-3][0-7][0-7])|(.))ch|dr#tt|ddS|dS)N)chrint)ms r_unquote_replacer/s1t3qtQ<<   t r c|t|dkr|S|ddks |ddkr|S|dd}tt|S)Nr+rrr))len _unquote_subr/r&s r_unquoter4s\ {c#hhll  1v}}B3 ad)C (# . ..r )MonTueWedThuFriSatSun) NJanFebMarAprMayJunJulAugSepOctNovDecc ddlm}m}|}|||z\ }}}} } } } } }d|| ||||| | | fzS)Nr)gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)rJrI)future weekdayname monthnamerIrJnowyearmonthdayhhmmsswdyzs r_getdaterXsu!!!!!!!! $&&C-3VC&L-A-A*D%b"b"a 0 OS)E"2D"b" E FFr c eZdZdZdddddddd d d Zd d hZdZedZedZ edZ dZ d!dZ dZ ejZdZdZdZdZdZdZd"dZeZdZd!dZd!d ZeejZdS)#MorselaCA 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. expiresPathCommentDomainzMax-AgeSecureHttpOnlyVersionSameSite) r[pathcommentdomainmax-agesecurehttponlyversionsamesitergrhc|dx|_x|_|_|jD]}t||ddS)Nr)_key_value _coded_value _reserveddict __setitem__)selfkeys r__init__zMorsel.__init__sP6:: :DK$"3> , ,C   T3 + + + + , ,r c|jSr)rlrrs rrsz Morsel.key s yr c|jSr)rmrvs rvaluez Morsel.value$s {r c|jSr)rnrvs r coded_valuezMorsel.coded_value(s   r c|}||jvrtd|t||rtd|d|t|||dSNInvalid attribute .Control characters are not allowed in cookies r)lowerrorr!rprq)rrKVs rrqzMorsel.__setitem__,s GGIIDN""+;<< < !!Q ' ' \ZqZZUVZZ[[ [ q!$$$$$r Nc|}||jvrtd|t||rtd|d|t|||Sr|)rrorr!rp setdefault)rrrsr s rrzMorsel.setdefault4sziikk dn $ $+=>> > !#s + + c+WZWZWZ\_\_abb btS#...r ct|tstSt||o/|j|jko|j|jko|j|jkSr) isinstancerZNotImplementedrp__eq__rmrlrnrrmorsels rrz Morsel.__eq__<sg&&)) "! ! D&))9 v},9 V[(9!V%88 :r ct}t|||j|j|Sr)rZrpupdate__dict__rs rcopyz Morsel.copyFs< FD!!!t}--- r ci}t|D]9\}}|}||jvrt d||||<:t||dS)Nr})rpitemsrrorr)rrvaluesdatarsr s rrz Morsel.updateLsV **,,  HC))++C$.((!kCC"ABBBDII D$r c8||jvSr)rro)rrrs r isReservedKeyzMorsel.isReservedKeyUswwyyDN**r c||jvrtd|t|std|t |||rtd|d|d|||_||_||_dS)NzAttempt to set a reserved key z Illegal key r~r)rrorr#r!rlrmrn)rrrsr coded_vals rsetz Morsel.setXs 99;;$. ( (+CCIJJ JS!! 9+##788 8 !#sI 6 6 c+LOCCQTQTQTV_V_acc c  %r c,|j|j|jdS)N)rsrxrzrlrmrnrvs r __getstate__zMorsel.__getstate__fs!9[,   r cT|d|_|d|_|d|_dS)Nrsrxrzr)rrstates r __setstate__zMorsel.__setstate__ms+%L Gn !-0r Set-Cookie:c6|d||S)Nr) OutputString)rrattrsheaders routputz Morsel.outputrs" &&$"3"3E":":":;;r cLd|jjd|dS)N<: >) __class__r rrvs r__repr__zMorsel.__repr__ws,!^444d6G6G6I6I6I6IJJr cZd||ddzS)Nz rr)rreplace)rrrs r js_outputzMorsel.js_outputzs4   ''//U;; = =r cg}|j}||jd|j||j}t |}|D]\}}|dkr ||vr|dkr>t |tr)||j|dt|V|dkr1t |tr|d|j||fz|dkr>t |tr)||j|dt|||j vr'|r#|t|j|||j|d|t|S)N=rr[rfz%s=%drd) appendrsrzrosortedrrr-rXrr'_flags_semispacejoin)rrrresultrrrsrxs rrzMorsel.OutputStrings $(((D$4$45666 =NEtzz||$$ ? ?JC{{%iJuc$:$:$."5"5"5xGHHHH !!j&<&<!w$."5u!==>>>> !!j&<&<!$."5"5"5ve}}}EFFFF ##5F3t~c233444$."5"5"5uu=>>>>f%%%r r)Nr)r r r __doc__rorrtpropertyrsrxrzrqrrobject__ne__rrrrrrr__str__rrr classmethodtypes GenericAlias__class_getitem__r r rrZrZs*  I #F,,,XX!!X!%%%////:::]F    +++ & & &   111 <<<<GKKK====&&&&B$ E$677r rZz,\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=z\[\]z \s* # Optional whitespace at start of cookie (?P # 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 # 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\eZdZdZdZdZddZdZdZdd Z e Z d Z dd Z d Z efdZdS)rz'A container class for a set of Morsels.c ||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 rrr s r value_decodezBaseCookie.value_decodes Cxr c(t|}||fS)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&rrr strvals r value_encodezBaseCookie.value_encodes Sv~r Nc8|r||dSdSr)load)rrinputs rrtzBaseCookie.__init__s,   IIe       r c||t}||||t|||dS)z+Private method for setting a cookie's valueN)getrZrrprq)rrrs real_valuerzMs r__setzBaseCookie.__setsM HHS&(( # # c:{+++ sA&&&&&r ct|trt|||dS||\}}||||dS)zDictionary style assignment.N)rrZrprqr_BaseCookie__set)rrrsrxrvalcvals rrqzBaseCookie.__setitem__se eV $ $ (   T3 . . . . .**511JD$ JJsD$ ' ' ' ' 'r r cg}t|}|D]N\}}|||}t|rt d||O||S)z"Return a string suitable for HTTP.z-Control characters are not allowed in cookies)rrrr!rrjoin) rrrrseprrrsrx value_outputs rrzBaseCookie.outputstzz||$$ ( (JC <<v66L%l33 S!"QRRR MM, ' ' ' 'xxr cg}t|}|D]1\}}||dt|j2d|jjdt|dS)Nrrrr)rrrreprrxrr _spacejoin)rrlrrsrxs rrzBaseCookie.__repr__s tzz||$$ 9 9JC HHT%+%6%6%67 8 8 8 8 9!^444jmmmmDDr cg}t|}|D]-\}}|||.t |S)z(Return a string suitable for JavaScript.)rrrr _nulljoin)rrrrrrsrxs rrzBaseCookie.js_outputs^tzz||$$ 2 2JC MM%//%00 1 1 1 1   r ct|tr||n|D] \}}|||< dS)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)rr_BaseCookie__parse_stringr)rrrawdatarsrxs rrzBaseCookie.loadsZ gs # # "    ( ( ( (&mmoo " " U!S r cvd}t|}g}d}d}d}d|cxkr|krVnnR|||} | sn8| d| d} } | d}| ddkr$|sz||| dd| fn| t jvrg|sdS| ;| t jvr||| dfnZdS||| t| fn2| .||| | | fd}ndSd|cxkr|kPnd} |D]6\} } } | |kr| | | <| \}}| | |||| } 7dS) NrFr)r+rsr $T) r2matchgroupendrrrZrorr4rr)rrrpattir parsed_items morsel_seenTYPE_ATTRIBUTE TYPE_KEYVALUErrsrxrtprrs r__parse_stringzBaseCookie.__parse_strings  HH   1jjjjqjjjjjJJsA&&E U++U[[-?-?C ! A1v}}"##^SWe$DEEEE 000"F=yy{{fm33$++^S$,GHHHH ''huoo(NOOOO"##]C9J9J59Q9Q$RSSS" E1jjjjqjjjjJ *  NBU^#### d 3d+++I  r r)Nrr)r r r rrrrtrrqrrrrr_CookiePatternrr r rrrs11''' (((     GEEE!!!!   (6::::::r rceZdZdZdZdZdS)rz 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||fSr)r4rs rrzSimpleCookie.value_decode`s}}c!!r cBt|}|t|fSr)rr'rs rrzSimpleCookie.value_encodecsSvf~~%%r N)r r r rrrr r rrrYs< """&&&&&r r),rrestringr__all__rrrr Exceptionr ascii_lettersdigits _LegalChars_UnescapedCharsrrangemapordr%rcompileescape fullmatchr#rr!r'subr3r/r4 _weekdayname _monthnamerXrprZ_LegalKeyChars_LegalValueCharsASCIIVERBOSErrrr r rrsNXXz 7 7 7 G  X      )   ""V]25GG /JJEE#JJ##cc#.G.G*H*HHJJJ CHHeCIIv  7YRY{%;%;;<<F " #566BBB 6 6 6rz899=  ///6A@@ 888 <:FFFFp8p8p8p8p8Tp8p8p8xB!G+        " BJ #  .LLLLLLLL^ & & & & &: & & & & &r