summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/http/cookiejar.py20
-rw-r--r--Lib/site.py4
-rw-r--r--Lib/test/test_dict.py3
-rw-r--r--Lib/test/test_http_cookiejar.py13
-rw-r--r--Objects/enumobject.c7
-rwxr-xr-xParser/asdl_c.py5
-rw-r--r--Python/Python-ast.c5
7 files changed, 43 insertions, 14 deletions
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index e9efab8..657faa1 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -436,6 +436,13 @@ def join_header_words(lists):
if attr: headers.append("; ".join(attr))
return ", ".join(headers)
+def strip_quotes(text):
+ if text.startswith('"'):
+ text = text[1:]
+ if text.endswith('"'):
+ text = text[:-1]
+ return text
+
def parse_ns_headers(ns_headers):
"""Ad-hoc parser for Netscape protocol cookie-attributes.
@@ -453,7 +460,7 @@ def parse_ns_headers(ns_headers):
"""
known_attrs = ("expires", "domain", "path", "secure",
# RFC 2109 attrs (may turn up in Netscape cookies, too)
- "port", "max-age")
+ "version", "port", "max-age")
result = []
for ns_header in ns_headers:
@@ -473,12 +480,11 @@ def parse_ns_headers(ns_headers):
k = lc
if k == "version":
# This is an RFC 2109 cookie.
+ v = strip_quotes(v)
version_set = True
if k == "expires":
# convert expires date to seconds since epoch
- if v.startswith('"'): v = v[1:]
- if v.endswith('"'): v = v[:-1]
- v = http2time(v) # None if invalid
+ v = http2time(strip_quotes(v)) # None if invalid
pairs.append((k, v))
if pairs:
@@ -1446,7 +1452,11 @@ class CookieJar:
# set the easy defaults
version = standard.get("version", None)
- if version is not None: version = int(version)
+ if version is not None:
+ try:
+ version = int(version)
+ except ValueError:
+ return None # invalid version, ignore cookie
secure = standard.get("secure", False)
# (discard is also set if expires is Absent)
discard = standard.get("discard", False)
diff --git a/Lib/site.py b/Lib/site.py
index 8563df2..4624bf3 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -273,12 +273,12 @@ def getsitepackages():
environment, and will return a list of full paths.
"""
sitepackages = []
- seen = []
+ seen = set()
for prefix in PREFIXES:
if not prefix or prefix in seen:
continue
- seen.append(prefix)
+ seen.add(prefix)
if sys.platform in ('os2emx', 'riscos'):
sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 6c5f682..818c99e 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -664,6 +664,7 @@ class DictTest(unittest.TestCase):
gc.collect()
self.assertTrue(gc.is_tracked(t), t)
+ @support.cpython_only
def test_track_literals(self):
# Test GC-optimization of dict literals
x, y, z, w = 1.5, "a", (1, None), []
@@ -681,6 +682,7 @@ class DictTest(unittest.TestCase):
self._tracked({1: {}})
self._tracked({1: set()})
+ @support.cpython_only
def test_track_dynamic(self):
# Test GC-optimization of dynamically-created dicts
class MyObject(object):
@@ -744,6 +746,7 @@ class DictTest(unittest.TestCase):
d.update([(x, y), (z, w)])
self._tracked(d)
+ @support.cpython_only
def test_track_subtypes(self):
# Dict subtypes are always tracked
class MyDict(dict):
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
index 1c047b4..5a648e7 100644
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -97,6 +97,7 @@ class DateTimeTests(TestCase):
class HeaderTests(TestCase):
+
def test_parse_ns_headers(self):
# quotes should be stripped
expected = [[('foo', 'bar'), ('expires', 2209069412), ('version', '0')]]
@@ -106,6 +107,16 @@ class HeaderTests(TestCase):
]:
self.assertEquals(parse_ns_headers([hdr]), expected)
+ def test_parse_ns_headers_version(self):
+
+ # quotes should be stripped
+ expected = [[('foo', 'bar'), ('version', '1')]]
+ for hdr in [
+ 'foo=bar; version="1"',
+ 'foo=bar; Version="1"',
+ ]:
+ self.assertEquals(parse_ns_headers([hdr]), expected)
+
def test_parse_ns_headers_special_names(self):
# names such as 'expires' are not special in first name=value pair
# of Set-Cookie: header
@@ -1020,6 +1031,8 @@ class CookieTests(TestCase):
["Set-Cookie2: a=foo; path=/; Version=1; domain"],
# bad max-age
["Set-Cookie: b=foo; max-age=oops"],
+ # bad version
+ ["Set-Cookie: b=foo; version=spam"],
]:
c = cookiejar_from_cookie_headers(headers)
# these bad cookies shouldn't be set
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index b579f96..00a3346 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -159,12 +159,13 @@ enum_next(enumobject *en)
}
PyDoc_STRVAR(enum_doc,
-"enumerate(iterable) -> iterator for index, value of iterable\n"
+"enumerate(iterable[, start]) -> iterator for index, value of iterable\n"
"\n"
"Return an enumerate object. iterable must be another object that supports\n"
"iteration. The enumerate object yields pairs containing a count (from\n"
-"zero) and a value yielded by the iterable argument. enumerate is useful\n"
-"for obtaining an indexed list: (0, seq[0]), (1, seq[1]), (2, seq[2]), ...");
+"start, which defaults to zero) and a value yielded by the iterable argument.\n"
+"enumerate is useful for obtaining an indexed list:\n"
+" (0, seq[0]), (1, seq[1]), (2, seq[2]), ...");
PyTypeObject PyEnum_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 2b3be2b..c71c4ef 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -732,8 +732,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
{
int i, result;
PyObject *s, *l = PyTuple_New(num_fields);
- if (!l) return 0;
- for(i = 0; i < num_fields; i++) {
+ if (!l)
+ return 0;
+ for (i = 0; i < num_fields; i++) {
s = PyUnicode_FromString(attrs[i]);
if (!s) {
Py_DECREF(l);
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 54c4e01..c37dda7 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -537,8 +537,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
{
int i, result;
PyObject *s, *l = PyTuple_New(num_fields);
- if (!l) return 0;
- for(i = 0; i < num_fields; i++) {
+ if (!l)
+ return 0;
+ for (i = 0; i < num_fields; i++) {
s = PyUnicode_FromString(attrs[i]);
if (!s) {
Py_DECREF(l);