• File: cookies.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python37/lib64/python3.7/http/__pycache__/cookies.cpython-37.pyc
  • Date Modified: 10/26/2026 8:08 PM
  • File size: 15.99 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

LjqT
@sdZddlZddlZdddgZdjZdjZdjZGd	ddeZ	ej
ejd
ZedZ
dd
eedeeee
DZeeddeddiedeejZedZddZddZedjZddZddZddd d!d"d#d$gZdd%d&d'd(d)d*d+d,d-d.d/d0g
Z dee fd1d2Z!Gd3d4d4e"Z#d5Z$e$d6Z%ed7e$d8e%d9ej&ej'BZ(Gd:dde"Z)Gd;dde)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.
NCookieError
BaseCookieSimpleCookiez;  c@seZdZdS)rN)__name__
__module____qualname__r
r
1/opt/alt/python37/lib64/python3.7/http/cookies.pyrsz!#$%&'*+-.^_`|~:z
 ()/<=>?@[]{}cCsi|]}d||qS)z\%03or
).0nr
r
r
<dictcomp>sr"z\"\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|VqdS)N)_control_character_researchstr)rvr
r
r	<genexpr>sz)_has_control_character.<locals>.<genexpr>)any)valr
r
r_has_control_charactersrcCs*|dkst|r|Sd|tdSdS)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_Translator)rr
r
r_quotesrz\\(?:([0-3][0-7][0-7])|(.))cCs&|drtt|ddS|dSdS)N)chrint)mr
r
r_unquote_replacesr$cCsJ|dkst|dkr|S|ddks0|ddkr4|S|dd}tt|S)Nr rrr)len_unquote_subr$)rr
r
r_unquotesr(ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc	CsRddlm}m}|}|||\	}}}}	}
}}}
}d|||||||	|
|fS)Nr)gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r*r))ZfutureZweekdaynameZ	monthnamer)r*ZnowZyearZmonthZdayZhhZmmZssZwdyzr
r
r_getdates
r-c	@seZdZdZdddddddd	d
ZddhZd
dZeddZeddZ	eddZ
ddZd3ddZddZ
ejZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd4d+d,ZeZd-d.Zd5d/d0Zd6d1d2ZdS)7MorselaA 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.  This is most useful when Python
    objects are pickled for network transit.
    expiresZPathCommentZDomainzMax-AgeZSecureZHttpOnlyZVersion)r/pathcommentZdomainzmax-agesecurehttponlyversionr3r4cCs4d|_|_|_x|jD]}t||dqWdS)Nr)_key_value_coded_value	_reserveddict__setitem__)selfkeyr
r
r__init__szMorsel.__init__cCs|jS)N)r6)r<r
r
rr=sz
Morsel.keycCs|jS)N)r7)r<r
r
rvalue#szMorsel.valuecCs|jS)N)r8)r<r
r
rcoded_value'szMorsel.coded_valuecCsP|}||jkr td|ft||r>td|d|t|||dS)NzInvalid attribute %rz.Control characters are not allowed in cookies r)lowerr9rrr:r;)r<KVr
r
rr;+s

zMorsel.__setitem__NcCsH|}||jkr td|ft||r:td||ft|||S)NzInvalid attribute %rz3Control characters are not allowed in cookies %r %r)rAr9rrr:
setdefault)r<r=rr
r
rrD3s

zMorsel.setdefaultcCs>t|tstSt||o<|j|jko<|j|jko<|j|jkS)N)
isinstancer.NotImplementedr:__eq__r7r6r8)r<morselr
r
rrG;s
z
Morsel.__eq__cCs$t}t|||j|j|S)N)r.r:update__dict__)r<rHr
r
rcopyEszMorsel.copycCsti}x^t|D]N\}}|}||jkr:td|ft||rXtd|d||||<qWt||dS)NzInvalid attribute %rz.Control characters are not allowed in cookies r)r:itemsrAr9rrrI)r<valuesdatar=rr
r
rrIKs

z
Morsel.updatecCs|||S)N)rI)r<rMr
r
r__ior__Ws
zMorsel.__ior__cCs||jkS)N)rAr9)r<rBr
r
r
isReservedKey[szMorsel.isReservedKeycCsf||jkrtd|ft|s2td|ft|||rPtd|||f||_||_||_dS)Nz Attempt to set a reserved key %rzIllegal key %rz6Control characters are not allowed in cookies %r %r %r)rAr9rrrr6r7r8)r<r=rZ	coded_valr
r
rset^sz
Morsel.setcCs|j|j|jdS)N)r=r?r@)r6r7r8)r<r
r
r__getstate__lszMorsel.__getstate__cCsT|d}|d}|d}t|||r>td|d|d|||_||_||_dS)Nr=r?r@z.Control characters are not allowed in cookies r)rrr6r7r8)r<stater=r?r@r
r
r__setstate__sszMorsel.__setstate__Set-Cookie:cCsd|||fS)Nz%s %s)OutputString)r<attrsheaderr
r
routput~sz
Morsel.outputcCsd|jj|fS)Nz<%s: %s>)	__class__rrV)r<r
r
r__repr__szMorsel.__repr__cCsBddl}||}t|r"td||dd}d|fS)Nrz-Control characters are not allowed in cookieszutf-8asciiz
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = atob("%s");
        // end hiding -->
        </script>
        )base64rVrrZ	b64encodeencodedecode)r<rWr]Z
output_stringZoutput_encodedr
r
r	js_outputs
zMorsel.js_outputcCs(g}|j}|d|j|jf|dkr,|j}t|}x|D]\}}|dkrPq>||krZq>|dkrt|tr|d|j|t|fq>|dkrt|tr|d|j||fq>|dkrt|t	r|d|j|t
|fq>||jkr|r|t	|j|q>|d|j||fq>Wt|S)Nz%s=%srr/zmax-agez%s=%dr2)
appendr=r@r9sortedrLrEr"r-rr_flags_semispacejoin)r<rWresultrarLr=r?r
r
rrVs,zMorsel.OutputString)N)NrU)N)N)rrr	__doc__r9rcr>propertyr=r?r@r;rDrGobject__ne__rKrIrOrPrQrRrTrY__str__r[r`rVr
r
r
rr.s<


r.z,\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=z\[\]z
    \s*                            # Optional whitespace at start of cookie
    (?P<key>                       # 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<val>                         # 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
ZddZdddZ	e	Z
ddZdddZ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
)r<rr
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.
        )r)r<rstrvalr
r
rvalue_encodeszBaseCookie.value_encodeNcCs|r||dS)N)load)r<inputr
r
rr>szBaseCookie.__init__cCs.||t}||||t|||dS)z+Private method for setting a cookie's valueN)getr.rQr:r;)r<r=Z
real_valuer@Mr
r
rZ__setszBaseCookie.__setcCs:t|trt|||n||\}}||||dS)zDictionary style assignment.N)rEr.r:r;rm_BaseCookie__set)r<r=r?rvalcvalr
r
rr;s
zBaseCookie.__setitem__Set-Cookie:
c	CsRg}t|}x6|D].\}}|||}t|r:td||qW||S)z"Return a string suitable for HTTP.z-Control characters are not allowed in cookies)rbrLrYrrrajoin)	r<rWrXseprerLr=r?Zvalue_outputr
r
rrYszBaseCookie.outputcCsNg}t|}x(|D] \}}|d|t|jfqWd|jjt|fS)Nz%s=%sz<%s: %s>)rbrLrareprr?rZr
_spacejoin)r<lrLr=r?r
r
rr[s
zBaseCookie.__repr__cCs:g}t|}x |D]\}}|||qWt|S)z(Return a string suitable for JavaScript.)rbrLrar`	_nulljoin)r<rWrerLr=r?r
r
rr`s
zBaseCookie.js_outputcCs8t|tr||nx|D]\}}|||<q WdS)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)rEr_BaseCookie__parse_stringrL)r<Zrawdatar=r?r
r
rrns

zBaseCookie.loadcCsd}t|}g}d}d}d}xd|kr6|krnn|||}	|	sLP|	d|	d}
}|	d}|
ddkr|s~q |||
dd|fq |
tjkr|sdS|dkr|
tjkr|||
dfqdSn|||
t	|fq |dk	r|||
|
|fd}q dSq Wd}xb|D]Z\}
}
}|
|krV|dk	sLt|||
<n,|
|ksdt|\}}||
||||
}q*WdS)	NrFrr r=r$T)
r&matchgroupendrarAr.r9rcr(rkAssertionErrorrr)r<rZpattir
Zparsed_itemsZmorsel_seenZTYPE_ATTRIBUTEZ
TYPE_KEYVALUErr=r?rqtprsrtr
r
rZ__parse_string-sJ



zBaseCookie.__parse_string)N)Nrurv)N)rrr	rfrkrmr>rrr;rYrjr[r`rn_CookiePatternr}r
r
r
rrs		
	

c@s eZdZdZddZddZdS)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.
    cCst||fS)N)r()r<rr
r
rrkqszSimpleCookie.value_decodecCst|}|t|fS)N)rr)r<rrlr
r
rrmtszSimpleCookie.value_encodeN)rrr	rfrkrmr
r
r
rrjs)+rfrestring__all__rwr|rdrz	ExceptionrZ
ascii_lettersZdigitsZ_LegalCharsZ_UnescapedCharsrQrangemapordrrIcompileescape	fullmatchrrrrsubr'r$r(Z_weekdaynameZ
_monthnamer-r:r.Z_LegalKeyCharsZ_LegalValueCharsASCIIVERBOSErrrr
r
r
r<module>sH


O