Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../http
File: cookiejar.py
(cookie.version == 0 and self.strict_ns_set_path)) and
[1000] Fix | Delete
not self.path_return_ok(cookie.path, request)):
[1001] Fix | Delete
_debug(" path attribute %s is not a prefix of request "
[1002] Fix | Delete
"path %s", cookie.path, req_path)
[1003] Fix | Delete
return False
[1004] Fix | Delete
return True
[1005] Fix | Delete
[1006] Fix | Delete
def set_ok_domain(self, cookie, request):
[1007] Fix | Delete
if self.is_blocked(cookie.domain):
[1008] Fix | Delete
_debug(" domain %s is in user block-list", cookie.domain)
[1009] Fix | Delete
return False
[1010] Fix | Delete
if self.is_not_allowed(cookie.domain):
[1011] Fix | Delete
_debug(" domain %s is not in user allow-list", cookie.domain)
[1012] Fix | Delete
return False
[1013] Fix | Delete
if cookie.domain_specified:
[1014] Fix | Delete
req_host, erhn = eff_request_host(request)
[1015] Fix | Delete
domain = cookie.domain
[1016] Fix | Delete
if self.strict_domain and (domain.count(".") >= 2):
[1017] Fix | Delete
# XXX This should probably be compared with the Konqueror
[1018] Fix | Delete
# (kcookiejar.cpp) and Mozilla implementations, but it's a
[1019] Fix | Delete
# losing battle.
[1020] Fix | Delete
i = domain.rfind(".")
[1021] Fix | Delete
j = domain.rfind(".", 0, i)
[1022] Fix | Delete
if j == 0: # domain like .foo.bar
[1023] Fix | Delete
tld = domain[i+1:]
[1024] Fix | Delete
sld = domain[j+1:i]
[1025] Fix | Delete
if sld.lower() in ("co", "ac", "com", "edu", "org", "net",
[1026] Fix | Delete
"gov", "mil", "int", "aero", "biz", "cat", "coop",
[1027] Fix | Delete
"info", "jobs", "mobi", "museum", "name", "pro",
[1028] Fix | Delete
"travel", "eu") and len(tld) == 2:
[1029] Fix | Delete
# domain like .co.uk
[1030] Fix | Delete
_debug(" country-code second level domain %s", domain)
[1031] Fix | Delete
return False
[1032] Fix | Delete
if domain.startswith("."):
[1033] Fix | Delete
undotted_domain = domain[1:]
[1034] Fix | Delete
else:
[1035] Fix | Delete
undotted_domain = domain
[1036] Fix | Delete
embedded_dots = (undotted_domain.find(".") >= 0)
[1037] Fix | Delete
if not embedded_dots and domain != ".local":
[1038] Fix | Delete
_debug(" non-local domain %s contains no embedded dot",
[1039] Fix | Delete
domain)
[1040] Fix | Delete
return False
[1041] Fix | Delete
if cookie.version == 0:
[1042] Fix | Delete
if (not erhn.endswith(domain) and
[1043] Fix | Delete
(not erhn.startswith(".") and
[1044] Fix | Delete
not ("."+erhn).endswith(domain))):
[1045] Fix | Delete
_debug(" effective request-host %s (even with added "
[1046] Fix | Delete
"initial dot) does not end with %s",
[1047] Fix | Delete
erhn, domain)
[1048] Fix | Delete
return False
[1049] Fix | Delete
if (cookie.version > 0 or
[1050] Fix | Delete
(self.strict_ns_domain & self.DomainRFC2965Match)):
[1051] Fix | Delete
if not domain_match(erhn, domain):
[1052] Fix | Delete
_debug(" effective request-host %s does not domain-match "
[1053] Fix | Delete
"%s", erhn, domain)
[1054] Fix | Delete
return False
[1055] Fix | Delete
if (cookie.version > 0 or
[1056] Fix | Delete
(self.strict_ns_domain & self.DomainStrictNoDots)):
[1057] Fix | Delete
host_prefix = req_host[:-len(domain)]
[1058] Fix | Delete
if (host_prefix.find(".") >= 0 and
[1059] Fix | Delete
not IPV4_RE.search(req_host)):
[1060] Fix | Delete
_debug(" host prefix %s for domain %s contains a dot",
[1061] Fix | Delete
host_prefix, domain)
[1062] Fix | Delete
return False
[1063] Fix | Delete
return True
[1064] Fix | Delete
[1065] Fix | Delete
def set_ok_port(self, cookie, request):
[1066] Fix | Delete
if cookie.port_specified:
[1067] Fix | Delete
req_port = request_port(request)
[1068] Fix | Delete
if req_port is None:
[1069] Fix | Delete
req_port = "80"
[1070] Fix | Delete
else:
[1071] Fix | Delete
req_port = str(req_port)
[1072] Fix | Delete
for p in cookie.port.split(","):
[1073] Fix | Delete
try:
[1074] Fix | Delete
int(p)
[1075] Fix | Delete
except ValueError:
[1076] Fix | Delete
_debug(" bad port %s (not numeric)", p)
[1077] Fix | Delete
return False
[1078] Fix | Delete
if p == req_port:
[1079] Fix | Delete
break
[1080] Fix | Delete
else:
[1081] Fix | Delete
_debug(" request port (%s) not found in %s",
[1082] Fix | Delete
req_port, cookie.port)
[1083] Fix | Delete
return False
[1084] Fix | Delete
return True
[1085] Fix | Delete
[1086] Fix | Delete
def return_ok(self, cookie, request):
[1087] Fix | Delete
"""
[1088] Fix | Delete
If you override .return_ok(), be sure to call this method. If it
[1089] Fix | Delete
returns false, so should your subclass (assuming your subclass wants to
[1090] Fix | Delete
be more strict about which cookies to return).
[1091] Fix | Delete
[1092] Fix | Delete
"""
[1093] Fix | Delete
# Path has already been checked by .path_return_ok(), and domain
[1094] Fix | Delete
# blocking done by .domain_return_ok().
[1095] Fix | Delete
_debug(" - checking cookie %s=%s", cookie.name, cookie.value)
[1096] Fix | Delete
[1097] Fix | Delete
for n in "version", "verifiability", "secure", "expires", "port", "domain":
[1098] Fix | Delete
fn_name = "return_ok_"+n
[1099] Fix | Delete
fn = getattr(self, fn_name)
[1100] Fix | Delete
if not fn(cookie, request):
[1101] Fix | Delete
return False
[1102] Fix | Delete
return True
[1103] Fix | Delete
[1104] Fix | Delete
def return_ok_version(self, cookie, request):
[1105] Fix | Delete
if cookie.version > 0 and not self.rfc2965:
[1106] Fix | Delete
_debug(" RFC 2965 cookies are switched off")
[1107] Fix | Delete
return False
[1108] Fix | Delete
elif cookie.version == 0 and not self.netscape:
[1109] Fix | Delete
_debug(" Netscape cookies are switched off")
[1110] Fix | Delete
return False
[1111] Fix | Delete
return True
[1112] Fix | Delete
[1113] Fix | Delete
def return_ok_verifiability(self, cookie, request):
[1114] Fix | Delete
if request.unverifiable and is_third_party(request):
[1115] Fix | Delete
if cookie.version > 0 and self.strict_rfc2965_unverifiable:
[1116] Fix | Delete
_debug(" third-party RFC 2965 cookie during unverifiable "
[1117] Fix | Delete
"transaction")
[1118] Fix | Delete
return False
[1119] Fix | Delete
elif cookie.version == 0 and self.strict_ns_unverifiable:
[1120] Fix | Delete
_debug(" third-party Netscape cookie during unverifiable "
[1121] Fix | Delete
"transaction")
[1122] Fix | Delete
return False
[1123] Fix | Delete
return True
[1124] Fix | Delete
[1125] Fix | Delete
def return_ok_secure(self, cookie, request):
[1126] Fix | Delete
if cookie.secure and request.type not in self.secure_protocols:
[1127] Fix | Delete
_debug(" secure cookie with non-secure request")
[1128] Fix | Delete
return False
[1129] Fix | Delete
return True
[1130] Fix | Delete
[1131] Fix | Delete
def return_ok_expires(self, cookie, request):
[1132] Fix | Delete
if cookie.is_expired(self._now):
[1133] Fix | Delete
_debug(" cookie expired")
[1134] Fix | Delete
return False
[1135] Fix | Delete
return True
[1136] Fix | Delete
[1137] Fix | Delete
def return_ok_port(self, cookie, request):
[1138] Fix | Delete
if cookie.port:
[1139] Fix | Delete
req_port = request_port(request)
[1140] Fix | Delete
if req_port is None:
[1141] Fix | Delete
req_port = "80"
[1142] Fix | Delete
for p in cookie.port.split(","):
[1143] Fix | Delete
if p == req_port:
[1144] Fix | Delete
break
[1145] Fix | Delete
else:
[1146] Fix | Delete
_debug(" request port %s does not match cookie port %s",
[1147] Fix | Delete
req_port, cookie.port)
[1148] Fix | Delete
return False
[1149] Fix | Delete
return True
[1150] Fix | Delete
[1151] Fix | Delete
def return_ok_domain(self, cookie, request):
[1152] Fix | Delete
req_host, erhn = eff_request_host(request)
[1153] Fix | Delete
domain = cookie.domain
[1154] Fix | Delete
[1155] Fix | Delete
if domain and not domain.startswith("."):
[1156] Fix | Delete
dotdomain = "." + domain
[1157] Fix | Delete
else:
[1158] Fix | Delete
dotdomain = domain
[1159] Fix | Delete
[1160] Fix | Delete
# strict check of non-domain cookies: Mozilla does this, MSIE5 doesn't
[1161] Fix | Delete
if (cookie.version == 0 and
[1162] Fix | Delete
(self.strict_ns_domain & self.DomainStrictNonDomain) and
[1163] Fix | Delete
not cookie.domain_specified and domain != erhn):
[1164] Fix | Delete
_debug(" cookie with unspecified domain does not string-compare "
[1165] Fix | Delete
"equal to request domain")
[1166] Fix | Delete
return False
[1167] Fix | Delete
[1168] Fix | Delete
if cookie.version > 0 and not domain_match(erhn, domain):
[1169] Fix | Delete
_debug(" effective request-host name %s does not domain-match "
[1170] Fix | Delete
"RFC 2965 cookie domain %s", erhn, domain)
[1171] Fix | Delete
return False
[1172] Fix | Delete
if cookie.version == 0 and not ("."+erhn).endswith(dotdomain):
[1173] Fix | Delete
_debug(" request-host %s does not match Netscape cookie domain "
[1174] Fix | Delete
"%s", req_host, domain)
[1175] Fix | Delete
return False
[1176] Fix | Delete
return True
[1177] Fix | Delete
[1178] Fix | Delete
def domain_return_ok(self, domain, request):
[1179] Fix | Delete
# Liberal check of. This is here as an optimization to avoid
[1180] Fix | Delete
# having to load lots of MSIE cookie files unless necessary.
[1181] Fix | Delete
req_host, erhn = eff_request_host(request)
[1182] Fix | Delete
if not req_host.startswith("."):
[1183] Fix | Delete
req_host = "."+req_host
[1184] Fix | Delete
if not erhn.startswith("."):
[1185] Fix | Delete
erhn = "."+erhn
[1186] Fix | Delete
if domain and not domain.startswith("."):
[1187] Fix | Delete
dotdomain = "." + domain
[1188] Fix | Delete
else:
[1189] Fix | Delete
dotdomain = domain
[1190] Fix | Delete
if not (req_host.endswith(dotdomain) or erhn.endswith(dotdomain)):
[1191] Fix | Delete
#_debug(" request domain %s does not match cookie domain %s",
[1192] Fix | Delete
# req_host, domain)
[1193] Fix | Delete
return False
[1194] Fix | Delete
[1195] Fix | Delete
if self.is_blocked(domain):
[1196] Fix | Delete
_debug(" domain %s is in user block-list", domain)
[1197] Fix | Delete
return False
[1198] Fix | Delete
if self.is_not_allowed(domain):
[1199] Fix | Delete
_debug(" domain %s is not in user allow-list", domain)
[1200] Fix | Delete
return False
[1201] Fix | Delete
[1202] Fix | Delete
return True
[1203] Fix | Delete
[1204] Fix | Delete
def path_return_ok(self, path, request):
[1205] Fix | Delete
_debug("- checking cookie path=%s", path)
[1206] Fix | Delete
req_path = request_path(request)
[1207] Fix | Delete
pathlen = len(path)
[1208] Fix | Delete
if req_path == path:
[1209] Fix | Delete
return True
[1210] Fix | Delete
elif (req_path.startswith(path) and
[1211] Fix | Delete
(path.endswith("/") or req_path[pathlen:pathlen+1] == "/")):
[1212] Fix | Delete
return True
[1213] Fix | Delete
[1214] Fix | Delete
_debug(" %s does not path-match %s", req_path, path)
[1215] Fix | Delete
return False
[1216] Fix | Delete
[1217] Fix | Delete
def vals_sorted_by_key(adict):
[1218] Fix | Delete
keys = sorted(adict.keys())
[1219] Fix | Delete
return map(adict.get, keys)
[1220] Fix | Delete
[1221] Fix | Delete
def deepvalues(mapping):
[1222] Fix | Delete
"""Iterates over nested mapping, depth-first, in sorted order by key."""
[1223] Fix | Delete
values = vals_sorted_by_key(mapping)
[1224] Fix | Delete
for obj in values:
[1225] Fix | Delete
mapping = False
[1226] Fix | Delete
try:
[1227] Fix | Delete
obj.items
[1228] Fix | Delete
except AttributeError:
[1229] Fix | Delete
pass
[1230] Fix | Delete
else:
[1231] Fix | Delete
mapping = True
[1232] Fix | Delete
yield from deepvalues(obj)
[1233] Fix | Delete
if not mapping:
[1234] Fix | Delete
yield obj
[1235] Fix | Delete
[1236] Fix | Delete
[1237] Fix | Delete
# Used as second parameter to dict.get() method, to distinguish absent
[1238] Fix | Delete
# dict key from one with a None value.
[1239] Fix | Delete
class Absent: pass
[1240] Fix | Delete
[1241] Fix | Delete
class CookieJar:
[1242] Fix | Delete
"""Collection of HTTP cookies.
[1243] Fix | Delete
[1244] Fix | Delete
You may not need to know about this class: try
[1245] Fix | Delete
urllib.request.build_opener(HTTPCookieProcessor).open(url).
[1246] Fix | Delete
"""
[1247] Fix | Delete
[1248] Fix | Delete
non_word_re = re.compile(r"\W")
[1249] Fix | Delete
quote_re = re.compile(r"([\"\\])")
[1250] Fix | Delete
strict_domain_re = re.compile(r"\.?[^.]*")
[1251] Fix | Delete
domain_re = re.compile(r"[^.]*")
[1252] Fix | Delete
dots_re = re.compile(r"^\.+")
[1253] Fix | Delete
[1254] Fix | Delete
magic_re = re.compile(r"^\#LWP-Cookies-(\d+\.\d+)", re.ASCII)
[1255] Fix | Delete
[1256] Fix | Delete
def __init__(self, policy=None):
[1257] Fix | Delete
if policy is None:
[1258] Fix | Delete
policy = DefaultCookiePolicy()
[1259] Fix | Delete
self._policy = policy
[1260] Fix | Delete
[1261] Fix | Delete
self._cookies_lock = _threading.RLock()
[1262] Fix | Delete
self._cookies = {}
[1263] Fix | Delete
[1264] Fix | Delete
def set_policy(self, policy):
[1265] Fix | Delete
self._policy = policy
[1266] Fix | Delete
[1267] Fix | Delete
def _cookies_for_domain(self, domain, request):
[1268] Fix | Delete
cookies = []
[1269] Fix | Delete
if not self._policy.domain_return_ok(domain, request):
[1270] Fix | Delete
return []
[1271] Fix | Delete
_debug("Checking %s for cookies to return", domain)
[1272] Fix | Delete
cookies_by_path = self._cookies[domain]
[1273] Fix | Delete
for path in cookies_by_path.keys():
[1274] Fix | Delete
if not self._policy.path_return_ok(path, request):
[1275] Fix | Delete
continue
[1276] Fix | Delete
cookies_by_name = cookies_by_path[path]
[1277] Fix | Delete
for cookie in cookies_by_name.values():
[1278] Fix | Delete
if not self._policy.return_ok(cookie, request):
[1279] Fix | Delete
_debug(" not returning cookie")
[1280] Fix | Delete
continue
[1281] Fix | Delete
_debug(" it's a match")
[1282] Fix | Delete
cookies.append(cookie)
[1283] Fix | Delete
return cookies
[1284] Fix | Delete
[1285] Fix | Delete
def _cookies_for_request(self, request):
[1286] Fix | Delete
"""Return a list of cookies to be returned to server."""
[1287] Fix | Delete
cookies = []
[1288] Fix | Delete
for domain in self._cookies.keys():
[1289] Fix | Delete
cookies.extend(self._cookies_for_domain(domain, request))
[1290] Fix | Delete
return cookies
[1291] Fix | Delete
[1292] Fix | Delete
def _cookie_attrs(self, cookies):
[1293] Fix | Delete
"""Return a list of cookie-attributes to be returned to server.
[1294] Fix | Delete
[1295] Fix | Delete
like ['foo="bar"; $Path="/"', ...]
[1296] Fix | Delete
[1297] Fix | Delete
The $Version attribute is also added when appropriate (currently only
[1298] Fix | Delete
once per request).
[1299] Fix | Delete
[1300] Fix | Delete
"""
[1301] Fix | Delete
# add cookies in order of most specific (ie. longest) path first
[1302] Fix | Delete
cookies.sort(key=lambda a: len(a.path), reverse=True)
[1303] Fix | Delete
[1304] Fix | Delete
version_set = False
[1305] Fix | Delete
[1306] Fix | Delete
attrs = []
[1307] Fix | Delete
for cookie in cookies:
[1308] Fix | Delete
# set version of Cookie header
[1309] Fix | Delete
# XXX
[1310] Fix | Delete
# What should it be if multiple matching Set-Cookie headers have
[1311] Fix | Delete
# different versions themselves?
[1312] Fix | Delete
# Answer: there is no answer; was supposed to be settled by
[1313] Fix | Delete
# RFC 2965 errata, but that may never appear...
[1314] Fix | Delete
version = cookie.version
[1315] Fix | Delete
if not version_set:
[1316] Fix | Delete
version_set = True
[1317] Fix | Delete
if version > 0:
[1318] Fix | Delete
attrs.append("$Version=%s" % version)
[1319] Fix | Delete
[1320] Fix | Delete
# quote cookie value if necessary
[1321] Fix | Delete
# (not for Netscape protocol, which already has any quotes
[1322] Fix | Delete
# intact, due to the poorly-specified Netscape Cookie: syntax)
[1323] Fix | Delete
if ((cookie.value is not None) and
[1324] Fix | Delete
self.non_word_re.search(cookie.value) and version > 0):
[1325] Fix | Delete
value = self.quote_re.sub(r"\\\1", cookie.value)
[1326] Fix | Delete
else:
[1327] Fix | Delete
value = cookie.value
[1328] Fix | Delete
[1329] Fix | Delete
# add cookie-attributes to be returned in Cookie header
[1330] Fix | Delete
if cookie.value is None:
[1331] Fix | Delete
attrs.append(cookie.name)
[1332] Fix | Delete
else:
[1333] Fix | Delete
attrs.append("%s=%s" % (cookie.name, value))
[1334] Fix | Delete
if version > 0:
[1335] Fix | Delete
if cookie.path_specified:
[1336] Fix | Delete
attrs.append('$Path="%s"' % cookie.path)
[1337] Fix | Delete
if cookie.domain.startswith("."):
[1338] Fix | Delete
domain = cookie.domain
[1339] Fix | Delete
if (not cookie.domain_initial_dot and
[1340] Fix | Delete
domain.startswith(".")):
[1341] Fix | Delete
domain = domain[1:]
[1342] Fix | Delete
attrs.append('$Domain="%s"' % domain)
[1343] Fix | Delete
if cookie.port is not None:
[1344] Fix | Delete
p = "$Port"
[1345] Fix | Delete
if cookie.port_specified:
[1346] Fix | Delete
p = p + ('="%s"' % cookie.port)
[1347] Fix | Delete
attrs.append(p)
[1348] Fix | Delete
[1349] Fix | Delete
return attrs
[1350] Fix | Delete
[1351] Fix | Delete
def add_cookie_header(self, request):
[1352] Fix | Delete
"""Add correct Cookie: header to request (urllib.request.Request object).
[1353] Fix | Delete
[1354] Fix | Delete
The Cookie2 header is also added unless policy.hide_cookie2 is true.
[1355] Fix | Delete
[1356] Fix | Delete
"""
[1357] Fix | Delete
_debug("add_cookie_header")
[1358] Fix | Delete
self._cookies_lock.acquire()
[1359] Fix | Delete
try:
[1360] Fix | Delete
[1361] Fix | Delete
self._policy._now = self._now = int(time.time())
[1362] Fix | Delete
[1363] Fix | Delete
cookies = self._cookies_for_request(request)
[1364] Fix | Delete
[1365] Fix | Delete
attrs = self._cookie_attrs(cookies)
[1366] Fix | Delete
if attrs:
[1367] Fix | Delete
if not request.has_header("Cookie"):
[1368] Fix | Delete
request.add_unredirected_header(
[1369] Fix | Delete
"Cookie", "; ".join(attrs))
[1370] Fix | Delete
[1371] Fix | Delete
# if necessary, advertise that we know RFC 2965
[1372] Fix | Delete
if (self._policy.rfc2965 and not self._policy.hide_cookie2 and
[1373] Fix | Delete
not request.has_header("Cookie2")):
[1374] Fix | Delete
for cookie in cookies:
[1375] Fix | Delete
if cookie.version != 1:
[1376] Fix | Delete
request.add_unredirected_header("Cookie2", '$Version="1"')
[1377] Fix | Delete
break
[1378] Fix | Delete
[1379] Fix | Delete
finally:
[1380] Fix | Delete
self._cookies_lock.release()
[1381] Fix | Delete
[1382] Fix | Delete
self.clear_expired_cookies()
[1383] Fix | Delete
[1384] Fix | Delete
def _normalized_cookie_tuples(self, attrs_set):
[1385] Fix | Delete
"""Return list of tuples containing normalised cookie information.
[1386] Fix | Delete
[1387] Fix | Delete
attrs_set is the list of lists of key,value pairs extracted from
[1388] Fix | Delete
the Set-Cookie or Set-Cookie2 headers.
[1389] Fix | Delete
[1390] Fix | Delete
Tuples are name, value, standard, rest, where name and value are the
[1391] Fix | Delete
cookie name and value, standard is a dictionary containing the standard
[1392] Fix | Delete
cookie-attributes (discard, secure, version, expires or max-age,
[1393] Fix | Delete
domain, path and port) and rest is a dictionary containing the rest of
[1394] Fix | Delete
the cookie-attributes.
[1395] Fix | Delete
[1396] Fix | Delete
"""
[1397] Fix | Delete
cookie_tuples = []
[1398] Fix | Delete
[1399] Fix | Delete
boolean_attrs = "discard", "secure"
[1400] Fix | Delete
value_attrs = ("version",
[1401] Fix | Delete
"expires", "max-age",
[1402] Fix | Delete
"domain", "path", "port",
[1403] Fix | Delete
"comment", "commenturl")
[1404] Fix | Delete
[1405] Fix | Delete
for cookie_attrs in attrs_set:
[1406] Fix | Delete
name, value = cookie_attrs[0]
[1407] Fix | Delete
[1408] Fix | Delete
# Build dictionary of standard cookie-attributes (standard) and
[1409] Fix | Delete
# dictionary of other cookie-attributes (rest).
[1410] Fix | Delete
[1411] Fix | Delete
# Note: expiry time is normalised to seconds since epoch. V0
[1412] Fix | Delete
# cookies should have the Expires cookie-attribute, and V1 cookies
[1413] Fix | Delete
# should have Max-Age, but since V1 includes RFC 2109 cookies (and
[1414] Fix | Delete
# since V0 cookies may be a mish-mash of Netscape and RFC 2109), we
[1415] Fix | Delete
# accept either (but prefer Max-Age).
[1416] Fix | Delete
max_age_set = False
[1417] Fix | Delete
[1418] Fix | Delete
bad_cookie = False
[1419] Fix | Delete
[1420] Fix | Delete
standard = {}
[1421] Fix | Delete
rest = {}
[1422] Fix | Delete
for k, v in cookie_attrs[1:]:
[1423] Fix | Delete
lc = k.lower()
[1424] Fix | Delete
# don't lose case distinction for unknown fields
[1425] Fix | Delete
if lc in value_attrs or lc in boolean_attrs:
[1426] Fix | Delete
k = lc
[1427] Fix | Delete
if k in boolean_attrs and v is None:
[1428] Fix | Delete
# boolean cookie-attribute is present, but has no value
[1429] Fix | Delete
# (like "discard", rather than "port=80")
[1430] Fix | Delete
v = True
[1431] Fix | Delete
if k in standard:
[1432] Fix | Delete
# only first value is significant
[1433] Fix | Delete
continue
[1434] Fix | Delete
if k == "domain":
[1435] Fix | Delete
if v is None:
[1436] Fix | Delete
_debug(" missing value for domain attribute")
[1437] Fix | Delete
bad_cookie = True
[1438] Fix | Delete
break
[1439] Fix | Delete
# RFC 2965 section 3.3.3
[1440] Fix | Delete
v = v.lower()
[1441] Fix | Delete
if k == "expires":
[1442] Fix | Delete
if max_age_set:
[1443] Fix | Delete
# Prefer max-age to expires (like Mozilla)
[1444] Fix | Delete
continue
[1445] Fix | Delete
if v is None:
[1446] Fix | Delete
_debug(" missing or invalid value for expires "
[1447] Fix | Delete
"attribute: treating as session cookie")
[1448] Fix | Delete
continue
[1449] Fix | Delete
if k == "max-age":
[1450] Fix | Delete
max_age_set = True
[1451] Fix | Delete
try:
[1452] Fix | Delete
v = int(v)
[1453] Fix | Delete
except ValueError:
[1454] Fix | Delete
_debug(" missing or invalid (non-numeric) value for "
[1455] Fix | Delete
"max-age attribute")
[1456] Fix | Delete
bad_cookie = True
[1457] Fix | Delete
break
[1458] Fix | Delete
# convert RFC 2965 Max-Age to seconds since epoch
[1459] Fix | Delete
# XXX Strictly you're supposed to follow RFC 2616
[1460] Fix | Delete
# age-calculation rules. Remember that zero Max-Age
[1461] Fix | Delete
# is a request to discard (old and new) cookie, though.
[1462] Fix | Delete
k = "expires"
[1463] Fix | Delete
v = self._now + v
[1464] Fix | Delete
if (k in value_attrs) or (k in boolean_attrs):
[1465] Fix | Delete
if (v is None and
[1466] Fix | Delete
k not in ("port", "comment", "commenturl")):
[1467] Fix | Delete
_debug(" missing value for %s attribute" % k)
[1468] Fix | Delete
bad_cookie = True
[1469] Fix | Delete
break
[1470] Fix | Delete
standard[k] = v
[1471] Fix | Delete
else:
[1472] Fix | Delete
rest[k] = v
[1473] Fix | Delete
[1474] Fix | Delete
if bad_cookie:
[1475] Fix | Delete
continue
[1476] Fix | Delete
[1477] Fix | Delete
cookie_tuples.append((name, value, standard, rest))
[1478] Fix | Delete
[1479] Fix | Delete
return cookie_tuples
[1480] Fix | Delete
[1481] Fix | Delete
def _cookie_from_cookie_tuple(self, tup, request):
[1482] Fix | Delete
# standard is dict of standard cookie-attributes, rest is dict of the
[1483] Fix | Delete
# rest of them
[1484] Fix | Delete
name, value, standard, rest = tup
[1485] Fix | Delete
[1486] Fix | Delete
domain = standard.get("domain", Absent)
[1487] Fix | Delete
path = standard.get("path", Absent)
[1488] Fix | Delete
port = standard.get("port", Absent)
[1489] Fix | Delete
expires = standard.get("expires", Absent)
[1490] Fix | Delete
[1491] Fix | Delete
# set the easy defaults
[1492] Fix | Delete
version = standard.get("version", None)
[1493] Fix | Delete
if version is not None:
[1494] Fix | Delete
try:
[1495] Fix | Delete
version = int(version)
[1496] Fix | Delete
except ValueError:
[1497] Fix | Delete
return None # invalid version, ignore cookie
[1498] Fix | Delete
secure = standard.get("secure", False)
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function