/snap/core22/2437/usr/lib/python3.10/http/__pycache__
NameSizeModeActions
client.cpython-310.pyc354560644editdlrm
cookiejar.cpython-310.pyc534400644editdlrm
cookies.cpython-310.pyc159050644editdlrm
server.cpython-310.pyc351920644editdlrm
__init__.cpython-310.pyc64160644editdlrm
Edit: /snap/core22/2437/usr/lib/python3.10/http/__pycache__/cookies.cpython-310.pyc (15905B)
o p̦iQ@sldZddlZddlZddlZgdZdjZdjZdjZGddde Z ej ej d Z e d Zd d eed eeeeDZeeddeddiedee jZedZddZddZedjZddZddZgdZ gdZ!de e!fdd Z"Gd!d"d"e#Z$d#Z%e%d$Z&ed%e%d&e&d'ej'ej(BZ)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=;";') >>> 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;  c@s eZdZdS)rN)__name__ __module__ __qualname__r r #/usr/lib/python3.10/http/cookies.pyrsrz!#$%&'*+-.^_`|~:z ()/<=>?@[]{}cCsi|]}|d|qS)z\%03or ).0nr r r sr"\"\z\\z[%s]+z[\x00-\x1F\x7F]cGstdd|DS)zhDetects control characters within a value. Supports any type, as header values can be any type. css|] }tt|VqdSN)_control_character_researchstr)r vr r r sz)_has_control_character..)any)valr r r _has_control_charactersrcCs&|dust|r |Sd|tdS)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 _Translatorrr r r _quotesr z\\(?:([0-3][0-7][0-7])|(.))cCs"|dr tt|ddS|dS)N)chrint)mr r r _unquote_replacesr'cCsJ|dus t|dkr |S|ddks|ddkr|S|dd}tt|S)Nr#rrr!)len _unquote_subr'rr r r _unquotes   r+)MonTueWedThuFriSatSun) NJanFebMarAprMayJunJulAugSepOctNovDecc CsRddlm}m}|}|||\ }}}} } } } } }d|| ||||| | | fS)Nr)gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r@r?)future weekdayname monthnamer?r@nowyearmonthdayhhmmsswdyzr r r _getdates rNc @seZdZdZdddddddd d d Zd d hZddZeddZeddZ eddZ ddZ d2ddZ ddZ ejZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd3d*d+ZeZd,d-Zd2d.d/Zd2d0d1ZeejZdS)4MorselaCA 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) rPpathcommentdomainmax-agesecurehttponlyversionsamesiter\r]cCs0d|_|_|_|jD] }t||dq dS)Nr)_key_value _coded_value _reserveddict __setitem__)selfkeyr r r __init__s zMorsel.__init__cC|jSr)r`rfr r r rg z Morsel.keycCrir)rarjr r r value$rkz Morsel.valuecCrir)rbrjr r r coded_value(rkzMorsel.coded_valuecCsP|}||jvrtd|ft||rtd|d|t|||dS)NInvalid attribute %rz.Control characters are not allowed in cookies r)lowerrcrrrdre)rfKVr r r re,s   zMorsel.__setitem__NcCsH|}||jvrtd|ft||rtd||ft|||S)Nrnz3Control characters are not allowed in cookies %r %r)rorcrrrd setdefault)rfrgrr r r rr4s   zMorsel.setdefaultcCs>t|tstSt||o|j|jko|j|jko|j|jkSr) isinstancerONotImplementedrd__eq__rar`rbrfmorselr r r ru<s     z Morsel.__eq__cCs$t}t|||j|j|Sr)rOrdupdate__dict__rvr r r copyFs z Morsel.copycCsRi}t|D]\}}|}||jvrtd|f|||<qt||dS)Nrn)rditemsrorcrrx)rfvaluesdatargrr r r rxLs  z Morsel.updatecCs||jvSr)rorc)rfrpr r r isReservedKeyUszMorsel.isReservedKeycCsf||jvrtd|ft|std|ft|||r(td|||f||_||_||_dS)Nz Attempt to set a reserved key %rzIllegal key %rz6Control characters are not allowed in cookies %r %r %r)rorcrrrr`rarb)rfrgr coded_valr r r setXs   z Morsel.setcCs|j|j|jdS)N)rgrlrmr`rarbrjr r r __getstate__fszMorsel.__getstate__cCs"|d|_|d|_|d|_dS)Nrgrlrmr)rfstater r r __setstate__ms  zMorsel.__setstate__ Set-Cookie:cCsd|||fS)Nz%s %s) OutputString)rfattrsheaderr r r outputrsz Morsel.outputcCsd|jj|fS)N<%s: %s>) __class__rrrjr r r __repr__wszMorsel.__repr__cCsd||ddS)Nz rr)rreplace)rfrr r r js_outputzszMorsel.js_outputcCs g}|j}|d|j|jf|dur|j}t|}|D]m\}}|dkr'q||vr,q|dkrCt|trC|d|j|t|fq|dkrXt|trX|d|j||fq|dkrot|t ro|d|j|t |fq||j vr|r|t |j|q|d|j||fqt |S)N%s=%srrPr[z%s=%drY) appendrgrmrcsortedr{rsr%rNrr _flags_semispacejoin)rfrresultrr{rgrlr r r rs.   zMorsel.OutputStringr)Nr)rrr __doc__rcrrhpropertyrgrlrmrerrruobject__ne__rzrxr~rrrr__str__rrr classmethodtypes GenericAlias__class_getitem__r r r r rOsH         !rOz,\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@sneZdZdZddZddZdddZd d Zd d ZdddZ e Z ddZ dddZ ddZ efddZdS)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 rfrr r r value_decodeszBaseCookie.value_decodecCst|}||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. rrfrstrvalr r r value_encodeszBaseCookie.value_encodeNcCs|r ||dSdSr)load)rfinputr r r rhszBaseCookie.__init__cCs.||t}||||t|||dS)z+Private method for setting a cookie's valueN)getrOrrdre)rfrg real_valuermMr r r __setszBaseCookie.__setcCs<t|trt|||dS||\}}||||dS)zDictionary style assignment.N)rsrOrdrer_BaseCookie__set)rfrgrlrvalcvalr r r res zBaseCookie.__setitem__r c CsNg}t|}|D]\}}|||}t|rtd||q ||S)z"Return a string suitable for HTTP.z-Control characters are not allowed in cookies)rr{rrrrjoin) rfrrseprr{rgrl value_outputr r r rs     zBaseCookie.outputcCsJg}t|}|D]\}}|d|t|jfq d|jjt|fS)Nrr)rr{rreprrlrr _spacejoin)rflr{rgrlr r r rs   zBaseCookie.__repr__cCs6g}t|}|D] \}}|||q t|S)z(Return a string suitable for JavaScript.)rr{rr _nulljoin)rfrrr{rgrlr r r rs   zBaseCookie.js_outputcCs6t|tr ||dS|D]\}}|||<qdS)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)rsr_BaseCookie__parse_stringr{)rfrawdatargrlr r r rs   zBaseCookie.loadcCsd}t|}g}d}d}d}d|kr|krnnz|||} | s#nq| d| d} } | d}| ddkrI|ss\&]  =