Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3..../http
File: cookies.py
####
[0] Fix | Delete
# Copyright 2000 by Timothy O'Malley <timo@alum.mit.edu>
[1] Fix | Delete
#
[2] Fix | Delete
# All Rights Reserved
[3] Fix | Delete
#
[4] Fix | Delete
# Permission to use, copy, modify, and distribute this software
[5] Fix | Delete
# and its documentation for any purpose and without fee is hereby
[6] Fix | Delete
# granted, provided that the above copyright notice appear in all
[7] Fix | Delete
# copies and that both that copyright notice and this permission
[8] Fix | Delete
# notice appear in supporting documentation, and that the name of
[9] Fix | Delete
# Timothy O'Malley not be used in advertising or publicity
[10] Fix | Delete
# pertaining to distribution of the software without specific, written
[11] Fix | Delete
# prior permission.
[12] Fix | Delete
#
[13] Fix | Delete
# Timothy O'Malley DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
[14] Fix | Delete
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
[15] Fix | Delete
# AND FITNESS, IN NO EVENT SHALL Timothy O'Malley BE LIABLE FOR
[16] Fix | Delete
# ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
[17] Fix | Delete
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
[18] Fix | Delete
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
[19] Fix | Delete
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
[20] Fix | Delete
# PERFORMANCE OF THIS SOFTWARE.
[21] Fix | Delete
#
[22] Fix | Delete
####
[23] Fix | Delete
#
[24] Fix | Delete
# Id: Cookie.py,v 2.29 2000/08/23 05:28:49 timo Exp
[25] Fix | Delete
# by Timothy O'Malley <timo@alum.mit.edu>
[26] Fix | Delete
#
[27] Fix | Delete
# Cookie.py is a Python module for the handling of HTTP
[28] Fix | Delete
# cookies as a Python dictionary. See RFC 2109 for more
[29] Fix | Delete
# information on cookies.
[30] Fix | Delete
#
[31] Fix | Delete
# The original idea to treat Cookies as a dictionary came from
[32] Fix | Delete
# Dave Mitchell (davem@magnet.com) in 1995, when he released the
[33] Fix | Delete
# first version of nscookie.py.
[34] Fix | Delete
#
[35] Fix | Delete
####
[36] Fix | Delete
[37] Fix | Delete
r"""
[38] Fix | Delete
Here's a sample session to show how to use this module.
[39] Fix | Delete
At the moment, this is the only documentation.
[40] Fix | Delete
[41] Fix | Delete
The Basics
[42] Fix | Delete
----------
[43] Fix | Delete
[44] Fix | Delete
Importing is easy...
[45] Fix | Delete
[46] Fix | Delete
>>> from http import cookies
[47] Fix | Delete
[48] Fix | Delete
Most of the time you start by creating a cookie.
[49] Fix | Delete
[50] Fix | Delete
>>> C = cookies.SimpleCookie()
[51] Fix | Delete
[52] Fix | Delete
Once you've created your Cookie, you can add values just as if it were
[53] Fix | Delete
a dictionary.
[54] Fix | Delete
[55] Fix | Delete
>>> C = cookies.SimpleCookie()
[56] Fix | Delete
>>> C["fig"] = "newton"
[57] Fix | Delete
>>> C["sugar"] = "wafer"
[58] Fix | Delete
>>> C.output()
[59] Fix | Delete
'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer'
[60] Fix | Delete
[61] Fix | Delete
Notice that the printable representation of a Cookie is the
[62] Fix | Delete
appropriate format for a Set-Cookie: header. This is the
[63] Fix | Delete
default behavior. You can change the header and printed
[64] Fix | Delete
attributes by using the .output() function
[65] Fix | Delete
[66] Fix | Delete
>>> C = cookies.SimpleCookie()
[67] Fix | Delete
>>> C["rocky"] = "road"
[68] Fix | Delete
>>> C["rocky"]["path"] = "/cookie"
[69] Fix | Delete
>>> print(C.output(header="Cookie:"))
[70] Fix | Delete
Cookie: rocky=road; Path=/cookie
[71] Fix | Delete
>>> print(C.output(attrs=[], header="Cookie:"))
[72] Fix | Delete
Cookie: rocky=road
[73] Fix | Delete
[74] Fix | Delete
The load() method of a Cookie extracts cookies from a string. In a
[75] Fix | Delete
CGI script, you would use this method to extract the cookies from the
[76] Fix | Delete
HTTP_COOKIE environment variable.
[77] Fix | Delete
[78] Fix | Delete
>>> C = cookies.SimpleCookie()
[79] Fix | Delete
>>> C.load("chips=ahoy; vienna=finger")
[80] Fix | Delete
>>> C.output()
[81] Fix | Delete
'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger'
[82] Fix | Delete
[83] Fix | Delete
The load() method is darn-tootin smart about identifying cookies
[84] Fix | Delete
within a string. Escaped quotation marks, nested semicolons, and other
[85] Fix | Delete
such trickeries do not confuse it.
[86] Fix | Delete
[87] Fix | Delete
>>> C = cookies.SimpleCookie()
[88] Fix | Delete
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
[89] Fix | Delete
>>> print(C)
[90] Fix | Delete
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"
[91] Fix | Delete
[92] Fix | Delete
Each element of the Cookie also supports all of the RFC 2109
[93] Fix | Delete
Cookie attributes. Here's an example which sets the Path
[94] Fix | Delete
attribute.
[95] Fix | Delete
[96] Fix | Delete
>>> C = cookies.SimpleCookie()
[97] Fix | Delete
>>> C["oreo"] = "doublestuff"
[98] Fix | Delete
>>> C["oreo"]["path"] = "/"
[99] Fix | Delete
>>> print(C)
[100] Fix | Delete
Set-Cookie: oreo=doublestuff; Path=/
[101] Fix | Delete
[102] Fix | Delete
Each dictionary element has a 'value' attribute, which gives you
[103] Fix | Delete
back the value associated with the key.
[104] Fix | Delete
[105] Fix | Delete
>>> C = cookies.SimpleCookie()
[106] Fix | Delete
>>> C["twix"] = "none for you"
[107] Fix | Delete
>>> C["twix"].value
[108] Fix | Delete
'none for you'
[109] Fix | Delete
[110] Fix | Delete
The SimpleCookie expects that all values should be standard strings.
[111] Fix | Delete
Just to be sure, SimpleCookie invokes the str() builtin to convert
[112] Fix | Delete
the value to a string, when the values are set dictionary-style.
[113] Fix | Delete
[114] Fix | Delete
>>> C = cookies.SimpleCookie()
[115] Fix | Delete
>>> C["number"] = 7
[116] Fix | Delete
>>> C["string"] = "seven"
[117] Fix | Delete
>>> C["number"].value
[118] Fix | Delete
'7'
[119] Fix | Delete
>>> C["string"].value
[120] Fix | Delete
'seven'
[121] Fix | Delete
>>> C.output()
[122] Fix | Delete
'Set-Cookie: number=7\r\nSet-Cookie: string=seven'
[123] Fix | Delete
[124] Fix | Delete
Finis.
[125] Fix | Delete
"""
[126] Fix | Delete
[127] Fix | Delete
#
[128] Fix | Delete
# Import our required modules
[129] Fix | Delete
#
[130] Fix | Delete
import re
[131] Fix | Delete
import string
[132] Fix | Delete
[133] Fix | Delete
__all__ = ["CookieError", "BaseCookie", "SimpleCookie"]
[134] Fix | Delete
[135] Fix | Delete
_nulljoin = ''.join
[136] Fix | Delete
_semispacejoin = '; '.join
[137] Fix | Delete
_spacejoin = ' '.join
[138] Fix | Delete
[139] Fix | Delete
def _warn_deprecated_setter(setter):
[140] Fix | Delete
import warnings
[141] Fix | Delete
msg = ('The .%s setter is deprecated. The attribute will be read-only in '
[142] Fix | Delete
'future releases. Please use the set() method instead.' % setter)
[143] Fix | Delete
warnings.warn(msg, DeprecationWarning, stacklevel=3)
[144] Fix | Delete
[145] Fix | Delete
#
[146] Fix | Delete
# Define an exception visible to External modules
[147] Fix | Delete
#
[148] Fix | Delete
class CookieError(Exception):
[149] Fix | Delete
pass
[150] Fix | Delete
[151] Fix | Delete
[152] Fix | Delete
# These quoting routines conform to the RFC2109 specification, which in
[153] Fix | Delete
# turn references the character definitions from RFC2068. They provide
[154] Fix | Delete
# a two-way quoting algorithm. Any non-text character is translated
[155] Fix | Delete
# into a 4 character sequence: a forward-slash followed by the
[156] Fix | Delete
# three-digit octal equivalent of the character. Any '\' or '"' is
[157] Fix | Delete
# quoted with a preceding '\' slash.
[158] Fix | Delete
# Because of the way browsers really handle cookies (as opposed to what
[159] Fix | Delete
# the RFC says) we also encode "," and ";".
[160] Fix | Delete
#
[161] Fix | Delete
# These are taken from RFC2068 and RFC2109.
[162] Fix | Delete
# _LegalChars is the list of chars which don't require "'s
[163] Fix | Delete
# _Translator hash-table for fast quoting
[164] Fix | Delete
#
[165] Fix | Delete
_LegalChars = string.ascii_letters + string.digits + "!#$%&'*+-.^_`|~:"
[166] Fix | Delete
_UnescapedChars = _LegalChars + ' ()/<=>?@[]{}'
[167] Fix | Delete
[168] Fix | Delete
_Translator = {n: '\\%03o' % n
[169] Fix | Delete
for n in set(range(256)) - set(map(ord, _UnescapedChars))}
[170] Fix | Delete
_Translator.update({
[171] Fix | Delete
ord('"'): '\\"',
[172] Fix | Delete
ord('\\'): '\\\\',
[173] Fix | Delete
})
[174] Fix | Delete
[175] Fix | Delete
_is_legal_key = re.compile('[%s]+' % re.escape(_LegalChars)).fullmatch
[176] Fix | Delete
[177] Fix | Delete
def _quote(str):
[178] Fix | Delete
r"""Quote a string for use in a cookie header.
[179] Fix | Delete
[180] Fix | Delete
If the string does not need to be double-quoted, then just return the
[181] Fix | Delete
string. Otherwise, surround the string in doublequotes and quote
[182] Fix | Delete
(with a \) special characters.
[183] Fix | Delete
"""
[184] Fix | Delete
if str is None or _is_legal_key(str):
[185] Fix | Delete
return str
[186] Fix | Delete
else:
[187] Fix | Delete
return '"' + str.translate(_Translator) + '"'
[188] Fix | Delete
[189] Fix | Delete
[190] Fix | Delete
_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
[191] Fix | Delete
_QuotePatt = re.compile(r"[\\].")
[192] Fix | Delete
[193] Fix | Delete
def _unquote(str):
[194] Fix | Delete
# If there aren't any doublequotes,
[195] Fix | Delete
# then there can't be any special characters. See RFC 2109.
[196] Fix | Delete
if str is None or len(str) < 2:
[197] Fix | Delete
return str
[198] Fix | Delete
if str[0] != '"' or str[-1] != '"':
[199] Fix | Delete
return str
[200] Fix | Delete
[201] Fix | Delete
# We have to assume that we must decode this string.
[202] Fix | Delete
# Down to work.
[203] Fix | Delete
[204] Fix | Delete
# Remove the "s
[205] Fix | Delete
str = str[1:-1]
[206] Fix | Delete
[207] Fix | Delete
# Check for special sequences. Examples:
[208] Fix | Delete
# \012 --> \n
[209] Fix | Delete
# \" --> "
[210] Fix | Delete
#
[211] Fix | Delete
i = 0
[212] Fix | Delete
n = len(str)
[213] Fix | Delete
res = []
[214] Fix | Delete
while 0 <= i < n:
[215] Fix | Delete
o_match = _OctalPatt.search(str, i)
[216] Fix | Delete
q_match = _QuotePatt.search(str, i)
[217] Fix | Delete
if not o_match and not q_match: # Neither matched
[218] Fix | Delete
res.append(str[i:])
[219] Fix | Delete
break
[220] Fix | Delete
# else:
[221] Fix | Delete
j = k = -1
[222] Fix | Delete
if o_match:
[223] Fix | Delete
j = o_match.start(0)
[224] Fix | Delete
if q_match:
[225] Fix | Delete
k = q_match.start(0)
[226] Fix | Delete
if q_match and (not o_match or k < j): # QuotePatt matched
[227] Fix | Delete
res.append(str[i:k])
[228] Fix | Delete
res.append(str[k+1])
[229] Fix | Delete
i = k + 2
[230] Fix | Delete
else: # OctalPatt matched
[231] Fix | Delete
res.append(str[i:j])
[232] Fix | Delete
res.append(chr(int(str[j+1:j+4], 8)))
[233] Fix | Delete
i = j + 4
[234] Fix | Delete
return _nulljoin(res)
[235] Fix | Delete
[236] Fix | Delete
# The _getdate() routine is used to set the expiration time in the cookie's HTTP
[237] Fix | Delete
# header. By default, _getdate() returns the current time in the appropriate
[238] Fix | Delete
# "expires" format for a Set-Cookie header. The one optional argument is an
[239] Fix | Delete
# offset from now, in seconds. For example, an offset of -3600 means "one hour
[240] Fix | Delete
# ago". The offset may be a floating point number.
[241] Fix | Delete
#
[242] Fix | Delete
[243] Fix | Delete
_weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
[244] Fix | Delete
[245] Fix | Delete
_monthname = [None,
[246] Fix | Delete
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
[247] Fix | Delete
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
[248] Fix | Delete
[249] Fix | Delete
def _getdate(future=0, weekdayname=_weekdayname, monthname=_monthname):
[250] Fix | Delete
from time import gmtime, time
[251] Fix | Delete
now = time()
[252] Fix | Delete
year, month, day, hh, mm, ss, wd, y, z = gmtime(now + future)
[253] Fix | Delete
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % \
[254] Fix | Delete
(weekdayname[wd], day, monthname[month], year, hh, mm, ss)
[255] Fix | Delete
[256] Fix | Delete
[257] Fix | Delete
class Morsel(dict):
[258] Fix | Delete
"""A class to hold ONE (key, value) pair.
[259] Fix | Delete
[260] Fix | Delete
In a cookie, each such pair may have several attributes, so this class is
[261] Fix | Delete
used to keep the attributes associated with the appropriate key,value pair.
[262] Fix | Delete
This class also includes a coded_value attribute, which is used to hold
[263] Fix | Delete
the network representation of the value. This is most useful when Python
[264] Fix | Delete
objects are pickled for network transit.
[265] Fix | Delete
"""
[266] Fix | Delete
# RFC 2109 lists these attributes as reserved:
[267] Fix | Delete
# path comment domain
[268] Fix | Delete
# max-age secure version
[269] Fix | Delete
#
[270] Fix | Delete
# For historical reasons, these attributes are also reserved:
[271] Fix | Delete
# expires
[272] Fix | Delete
#
[273] Fix | Delete
# This is an extension from Microsoft:
[274] Fix | Delete
# httponly
[275] Fix | Delete
#
[276] Fix | Delete
# This dictionary provides a mapping from the lowercase
[277] Fix | Delete
# variant on the left to the appropriate traditional
[278] Fix | Delete
# formatting on the right.
[279] Fix | Delete
_reserved = {
[280] Fix | Delete
"expires" : "expires",
[281] Fix | Delete
"path" : "Path",
[282] Fix | Delete
"comment" : "Comment",
[283] Fix | Delete
"domain" : "Domain",
[284] Fix | Delete
"max-age" : "Max-Age",
[285] Fix | Delete
"secure" : "Secure",
[286] Fix | Delete
"httponly" : "HttpOnly",
[287] Fix | Delete
"version" : "Version",
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
_flags = {'secure', 'httponly'}
[291] Fix | Delete
[292] Fix | Delete
def __init__(self):
[293] Fix | Delete
# Set defaults
[294] Fix | Delete
self._key = self._value = self._coded_value = None
[295] Fix | Delete
[296] Fix | Delete
# Set default attributes
[297] Fix | Delete
for key in self._reserved:
[298] Fix | Delete
dict.__setitem__(self, key, "")
[299] Fix | Delete
[300] Fix | Delete
@property
[301] Fix | Delete
def key(self):
[302] Fix | Delete
return self._key
[303] Fix | Delete
[304] Fix | Delete
@key.setter
[305] Fix | Delete
def key(self, key):
[306] Fix | Delete
_warn_deprecated_setter('key')
[307] Fix | Delete
self._key = key
[308] Fix | Delete
[309] Fix | Delete
@property
[310] Fix | Delete
def value(self):
[311] Fix | Delete
return self._value
[312] Fix | Delete
[313] Fix | Delete
@value.setter
[314] Fix | Delete
def value(self, value):
[315] Fix | Delete
_warn_deprecated_setter('value')
[316] Fix | Delete
self._value = value
[317] Fix | Delete
[318] Fix | Delete
@property
[319] Fix | Delete
def coded_value(self):
[320] Fix | Delete
return self._coded_value
[321] Fix | Delete
[322] Fix | Delete
@coded_value.setter
[323] Fix | Delete
def coded_value(self, coded_value):
[324] Fix | Delete
_warn_deprecated_setter('coded_value')
[325] Fix | Delete
self._coded_value = coded_value
[326] Fix | Delete
[327] Fix | Delete
def __setitem__(self, K, V):
[328] Fix | Delete
K = K.lower()
[329] Fix | Delete
if not K in self._reserved:
[330] Fix | Delete
raise CookieError("Invalid attribute %r" % (K,))
[331] Fix | Delete
dict.__setitem__(self, K, V)
[332] Fix | Delete
[333] Fix | Delete
def setdefault(self, key, val=None):
[334] Fix | Delete
key = key.lower()
[335] Fix | Delete
if key not in self._reserved:
[336] Fix | Delete
raise CookieError("Invalid attribute %r" % (key,))
[337] Fix | Delete
return dict.setdefault(self, key, val)
[338] Fix | Delete
[339] Fix | Delete
def __eq__(self, morsel):
[340] Fix | Delete
if not isinstance(morsel, Morsel):
[341] Fix | Delete
return NotImplemented
[342] Fix | Delete
return (dict.__eq__(self, morsel) and
[343] Fix | Delete
self._value == morsel._value and
[344] Fix | Delete
self._key == morsel._key and
[345] Fix | Delete
self._coded_value == morsel._coded_value)
[346] Fix | Delete
[347] Fix | Delete
__ne__ = object.__ne__
[348] Fix | Delete
[349] Fix | Delete
def copy(self):
[350] Fix | Delete
morsel = Morsel()
[351] Fix | Delete
dict.update(morsel, self)
[352] Fix | Delete
morsel.__dict__.update(self.__dict__)
[353] Fix | Delete
return morsel
[354] Fix | Delete
[355] Fix | Delete
def update(self, values):
[356] Fix | Delete
data = {}
[357] Fix | Delete
for key, val in dict(values).items():
[358] Fix | Delete
key = key.lower()
[359] Fix | Delete
if key not in self._reserved:
[360] Fix | Delete
raise CookieError("Invalid attribute %r" % (key,))
[361] Fix | Delete
data[key] = val
[362] Fix | Delete
dict.update(self, data)
[363] Fix | Delete
[364] Fix | Delete
def isReservedKey(self, K):
[365] Fix | Delete
return K.lower() in self._reserved
[366] Fix | Delete
[367] Fix | Delete
def set(self, key, val, coded_val, LegalChars=_LegalChars):
[368] Fix | Delete
if LegalChars != _LegalChars:
[369] Fix | Delete
import warnings
[370] Fix | Delete
warnings.warn(
[371] Fix | Delete
'LegalChars parameter is deprecated, ignored and will '
[372] Fix | Delete
'be removed in future versions.', DeprecationWarning,
[373] Fix | Delete
stacklevel=2)
[374] Fix | Delete
[375] Fix | Delete
if key.lower() in self._reserved:
[376] Fix | Delete
raise CookieError('Attempt to set a reserved key %r' % (key,))
[377] Fix | Delete
if not _is_legal_key(key):
[378] Fix | Delete
raise CookieError('Illegal key %r' % (key,))
[379] Fix | Delete
[380] Fix | Delete
# It's a good key, so save it.
[381] Fix | Delete
self._key = key
[382] Fix | Delete
self._value = val
[383] Fix | Delete
self._coded_value = coded_val
[384] Fix | Delete
[385] Fix | Delete
def __getstate__(self):
[386] Fix | Delete
return {
[387] Fix | Delete
'key': self._key,
[388] Fix | Delete
'value': self._value,
[389] Fix | Delete
'coded_value': self._coded_value,
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
def __setstate__(self, state):
[393] Fix | Delete
self._key = state['key']
[394] Fix | Delete
self._value = state['value']
[395] Fix | Delete
self._coded_value = state['coded_value']
[396] Fix | Delete
[397] Fix | Delete
def output(self, attrs=None, header="Set-Cookie:"):
[398] Fix | Delete
return "%s %s" % (header, self.OutputString(attrs))
[399] Fix | Delete
[400] Fix | Delete
__str__ = output
[401] Fix | Delete
[402] Fix | Delete
def __repr__(self):
[403] Fix | Delete
return '<%s: %s>' % (self.__class__.__name__, self.OutputString())
[404] Fix | Delete
[405] Fix | Delete
def js_output(self, attrs=None):
[406] Fix | Delete
# Print javascript
[407] Fix | Delete
return """
[408] Fix | Delete
<script type="text/javascript">
[409] Fix | Delete
<!-- begin hiding
[410] Fix | Delete
document.cookie = \"%s\";
[411] Fix | Delete
// end hiding -->
[412] Fix | Delete
</script>
[413] Fix | Delete
""" % (self.OutputString(attrs).replace('"', r'\"'))
[414] Fix | Delete
[415] Fix | Delete
def OutputString(self, attrs=None):
[416] Fix | Delete
# Build up our result
[417] Fix | Delete
#
[418] Fix | Delete
result = []
[419] Fix | Delete
append = result.append
[420] Fix | Delete
[421] Fix | Delete
# First, the key=value pair
[422] Fix | Delete
append("%s=%s" % (self.key, self.coded_value))
[423] Fix | Delete
[424] Fix | Delete
# Now add any defined attributes
[425] Fix | Delete
if attrs is None:
[426] Fix | Delete
attrs = self._reserved
[427] Fix | Delete
items = sorted(self.items())
[428] Fix | Delete
for key, value in items:
[429] Fix | Delete
if value == "":
[430] Fix | Delete
continue
[431] Fix | Delete
if key not in attrs:
[432] Fix | Delete
continue
[433] Fix | Delete
if key == "expires" and isinstance(value, int):
[434] Fix | Delete
append("%s=%s" % (self._reserved[key], _getdate(value)))
[435] Fix | Delete
elif key == "max-age" and isinstance(value, int):
[436] Fix | Delete
append("%s=%d" % (self._reserved[key], value))
[437] Fix | Delete
elif key == "comment" and isinstance(value, str):
[438] Fix | Delete
append("%s=%s" % (self._reserved[key], _quote(value)))
[439] Fix | Delete
elif key in self._flags:
[440] Fix | Delete
if value:
[441] Fix | Delete
append(str(self._reserved[key]))
[442] Fix | Delete
else:
[443] Fix | Delete
append("%s=%s" % (self._reserved[key], value))
[444] Fix | Delete
[445] Fix | Delete
# Return the result
[446] Fix | Delete
return _semispacejoin(result)
[447] Fix | Delete
[448] Fix | Delete
[449] Fix | Delete
#
[450] Fix | Delete
# Pattern for finding cookie
[451] Fix | Delete
#
[452] Fix | Delete
# This used to be strict parsing based on the RFC2109 and RFC2068
[453] Fix | Delete
# specifications. I have since discovered that MSIE 3.0x doesn't
[454] Fix | Delete
# follow the character rules outlined in those specs. As a
[455] Fix | Delete
# result, the parsing rules here are less strict.
[456] Fix | Delete
#
[457] Fix | Delete
[458] Fix | Delete
_LegalKeyChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
[459] Fix | Delete
_LegalValueChars = _LegalKeyChars + r'\[\]'
[460] Fix | Delete
_CookiePattern = re.compile(r"""
[461] Fix | Delete
\s* # Optional whitespace at start of cookie
[462] Fix | Delete
(?P<key> # Start of group 'key'
[463] Fix | Delete
[""" + _LegalKeyChars + r"""]+? # Any word of at least one letter
[464] Fix | Delete
) # End of group 'key'
[465] Fix | Delete
( # Optional group: there may not be a value.
[466] Fix | Delete
\s*=\s* # Equal Sign
[467] Fix | Delete
(?P<val> # Start of group 'val'
[468] Fix | Delete
"(?:[^\\"]|\\.)*" # Any doublequoted string
[469] Fix | Delete
| # or
[470] Fix | Delete
\w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr
[471] Fix | Delete
| # or
[472] Fix | Delete
[""" + _LegalValueChars + r"""]* # Any word or empty string
[473] Fix | Delete
) # End of group 'val'
[474] Fix | Delete
)? # End of optional value group
[475] Fix | Delete
\s* # Any number of spaces.
[476] Fix | Delete
(\s+|;|$) # Ending either at space, semicolon, or EOS.
[477] Fix | Delete
""", re.ASCII | re.VERBOSE) # re.ASCII may be removed if safe.
[478] Fix | Delete
[479] Fix | Delete
[480] Fix | Delete
# At long last, here is the cookie class. Using this class is almost just like
[481] Fix | Delete
# using a dictionary. See this module's docstring for example usage.
[482] Fix | Delete
#
[483] Fix | Delete
class BaseCookie(dict):
[484] Fix | Delete
"""A container class for a set of Morsels."""
[485] Fix | Delete
[486] Fix | Delete
def value_decode(self, val):
[487] Fix | Delete
"""real_value, coded_value = value_decode(STRING)
[488] Fix | Delete
Called prior to setting a cookie's value from the network
[489] Fix | Delete
representation. The VALUE is the value read from HTTP
[490] Fix | Delete
header.
[491] Fix | Delete
Override this function to modify the behavior of cookies.
[492] Fix | Delete
"""
[493] Fix | Delete
return val, val
[494] Fix | Delete
[495] Fix | Delete
def value_encode(self, val):
[496] Fix | Delete
"""real_value, coded_value = value_encode(VALUE)
[497] Fix | Delete
Called prior to setting a cookie's value from the dictionary
[498] Fix | Delete
representation. The VALUE is the value being assigned.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function