o ­=?h€Mã@sZdZddlZddlZddlZgd¢ZdjZdjZdjZGdd„de ƒZ ej ej d Z e d Zd d „eed ƒƒeeeeƒƒDƒZe edƒdedƒdi¡e de e ¡¡jZdd„Ze d¡jZdd„Zdd„Zgd¢Zgd¢Zdeefdd„Z Gdd„de!ƒZ"d Z#e#d!Z$e d"e#d#e$d$ej%ej&B¡Z'Gd%d&„d&e!ƒZ(Gd'd(„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=\\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 eZdZdS)rN)Ú__name__Ú __module__Ú __qualname__©r r ú3/opt/alt/python310/lib64/python3.10/http/cookies.pyr‘srz!#$%&'*+-.^_`|~:z ()/<=>?@[]{}cCsi|]}|d|“qS)z\%03or )Ú.0Únr r r Ú ¥sÿréú"ú\"ú\z\\z[%s]+cCs&|dust|ƒr |Sd| t¡dS)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®srz\\(?:([0-3][0-7][0-7])|(.))cCs"|dr tt|ddƒƒS|dS)Nééé)ÚchrÚint)Úmr r r Ú_unquote_replace½srcCsJ|dus t|ƒdkr |S|ddks|ddkr|S|dd…}tt|ƒS)Nrrréÿÿÿÿr)ÚlenÚ _unquote_subrrr r r Ú_unquoteÃs   r#)ZMonZTueZWedZThuZFriZSatZSun) NZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc CsRddlm}m}|ƒ}|||ƒ\ }}}} } } } } }d|| ||||| | | fS)Nr)ÚgmtimeÚtimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r%r$)ZfutureZ weekdaynameZ monthnamer$r%ZnowZyearZmonthZdayZhhZmmZssZwdÚyÚzr r r Ú_getdateäs ÿr(c @sàeZdZdZdddddddd d d œ Zd d hZdd„Zedd„ƒZedd„ƒZ edd„ƒZ dd„Z d2dd„Z dd„Z ejZdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd3d*d+„ZeZd,d-„Zd2d.d/„Zd2d0d1„ZeejƒZdS)4Ú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. ÚexpiresZPathÚCommentZDomainzMax-AgeZSecureZHttpOnlyZVersionZSameSite) r*ÚpathÚcommentZdomainúmax-ageÚsecureÚhttponlyÚversionZsamesiter/r0cCs0d|_|_|_|jD] }t ||d¡q dS)Nr)Ú_keyÚ_valueÚ _coded_valueÚ _reservedÚdictÚ __setitem__)ÚselfÚkeyr r r Ú__init__s ÿzMorsel.__init__cCó|jS©N)r2©r8r r r r9óz Morsel.keycCr;r<)r3r=r r r Úvaluer>z Morsel.valuecCr;r<)r4r=r r r Ú coded_valuer>zMorsel.coded_valuecCs2| ¡}||jvrtd|fƒ‚t |||¡dS©NzInvalid attribute %r)Úlowerr5rr6r7)r8ÚKÚVr r r r7#s zMorsel.__setitem__NcCs.| ¡}||jvrtd|fƒ‚t |||¡SrA)rBr5rr6Ú setdefault)r8r9Úvalr r r rE)s zMorsel.setdefaultcCs>t|tƒstSt ||¡o|j|jko|j|jko|j|jkSr<)Ú isinstancer)ÚNotImplementedr6Ú__eq__r3r2r4©r8Zmorselr r r rI/s   ÿ þ ýz Morsel.__eq__cCs$tƒ}t ||¡|j |j¡|Sr<)r)r6ÚupdateÚ__dict__rJr r r Úcopy9s z Morsel.copycCsRi}t|ƒ ¡D]\}}| ¡}||jvrtd|fƒ‚|||<qt ||¡dSrA)r6ÚitemsrBr5rrK)r8ÚvaluesÚdatar9rFr r r rK?s  z Morsel.updatecCs| ¡|jvSr<)rBr5)r8rCr r r Ú isReservedKeyHszMorsel.isReservedKeycCsH| ¡|jvrtd|fƒ‚t|ƒstd|fƒ‚||_||_||_dS)Nz Attempt to set a reserved key %rzIllegal key %r)rBr5rrr2r3r4)r8r9rFZ coded_valr r r ÚsetKs z Morsel.setcCs|j|j|jdœS)N)r9r?r@©r2r3r4r=r r r Ú __getstate__VsýzMorsel.__getstate__cCs"|d|_|d|_|d|_dS)Nr9r?r@rS)r8Ústater r r Ú __setstate__]s  zMorsel.__setstate__ú Set-Cookie:cCsd|| |¡fS)Nz%s %s)Ú OutputString)r8ÚattrsÚheaderr r r Úoutputbsz Morsel.outputcCsd|jj| ¡fS)Nú<%s: %s>)Ú __class__rrXr=r r r Ú__repr__gszMorsel.__repr__cCsd| |¡ dd¡S)Nz— rr)rXÚreplace)r8rYr r r Ú js_outputjsúzMorsel.js_outputcCs g}|j}|d|j|jfƒ|dur|j}t| ¡ƒ}|D]m\}}|dkr'q||vr,q|dkrCt|tƒrC|d|j|t|ƒfƒq|dkrXt|tƒrX|d|j||fƒq|dkrot|t ƒro|d|j|t |ƒfƒq||j vr€|r|t |j|ƒƒq|d|j||fƒqt |ƒS)Nú%s=%srr*r.z%s=%dr-) Úappendr9r@r5ÚsortedrNrGrr(rrÚ_flagsÚ_semispacejoin)r8rYÚresultrbrNr9r?r r r rXts.   €zMorsel.OutputStringr<)NrW)rrr Ú__doc__r5rdr:Úpropertyr9r?r@r7rErIÚobjectÚ__ne__rMrKrQrRrTrVr[Ú__str__r^r`rXÚ classmethodÚtypesÚ GenericAliasÚ__class_getitem__r r r r r)ìsH÷          !r)z,\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@sneZdZdZdd„Zdd„Zddd„Zd d „Zd d „Zddd„Z e Z dd„Z ddd„Z dd„Z efdd„ZdS)rz'A container class for a set of Morsels.cCs||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 ©r8rFr r r Ú value_decode½szBaseCookie.value_decodecCst|ƒ}||fS)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©r8rFZstrvalr r r Ú value_encodeÆszBaseCookie.value_encodeNcCs|r | |¡dSdSr<)Úload)r8Úinputr r r r:ÏsÿzBaseCookie.__init__cCs.| |tƒ¡}| |||¡t |||¡dS)z+Private method for setting a cookie's valueN)Úgetr)rRr6r7)r8r9Z real_valuer@ÚMr r r Z__setÓszBaseCookie.__setcCs<t|tƒrt |||¡dS| |¡\}}| |||¡dS)zDictionary style assignment.N)rGr)r6r7rsÚ_BaseCookie__set)r8r9r?ÚrvalÚcvalr r r r7Ùs zBaseCookie.__setitem__rWú cCs:g}t| ¡ƒ}|D] \}}| | ||¡¡q | |¡S)z"Return a string suitable for HTTP.)rcrNrbr[Újoin)r8rYrZÚseprfrNr9r?r r r r[âs    zBaseCookie.outputcCsJg}t| ¡ƒ}|D]\}}| d|t|jƒf¡q d|jjt|ƒfS)Nrar\)rcrNrbÚreprr?r]rÚ _spacejoin)r8ÚlrNr9r?r r r r^ìs   zBaseCookie.__repr__cCs6g}t| ¡ƒ}|D] \}}| | |¡¡q t|ƒS)z(Return a string suitable for JavaScript.)rcrNrbr`Ú _nulljoin)r8rYrfrNr9r?r r r r`ós   zBaseCookie.js_outputcCs6t|tƒr | |¡dS| ¡D]\}}|||<qdS)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)rGrÚ_BaseCookie__parse_stringrN)r8Zrawdatar9r?r r r rtûs  þ zBaseCookie.loadcCsˆd}t|ƒ}g}d}d}d}d|kr|kr”nnz| ||¡} | s#nq|  d¡|  d¡} } |  d¡}| ddkrI|ssX&]ÿþ 6ýý ô ô ï