Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e5cd1d

Browse files
committed
Merged revisions 81465-81466,81468,81679,81735,81760,81868,82183 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r81465 | georg.brandl | 2010-05-22 06:29:19 -0500 (Sat, 22 May 2010) | 2 lines Issue #3924: Ignore cookies with invalid "version" field in cookielib. ........ r81466 | georg.brandl | 2010-05-22 06:31:16 -0500 (Sat, 22 May 2010) | 1 line Underscore the name of an internal utility function. ........ r81468 | georg.brandl | 2010-05-22 06:43:25 -0500 (Sat, 22 May 2010) | 1 line #8635: document enumerate() start parameter in docstring. ........ r81679 | benjamin.peterson | 2010-06-03 16:21:03 -0500 (Thu, 03 Jun 2010) | 1 line use a set for membership testing ........ r81735 | michael.foord | 2010-06-05 06:46:59 -0500 (Sat, 05 Jun 2010) | 1 line Extract error message truncating into a method (unittest.TestCase._truncateMessage). ........ r81760 | michael.foord | 2010-06-05 14:38:42 -0500 (Sat, 05 Jun 2010) | 1 line Issue 8302. SkipTest exception is setUpClass or setUpModule is now reported as a skip rather than an error. ........ r81868 | benjamin.peterson | 2010-06-09 14:45:04 -0500 (Wed, 09 Jun 2010) | 1 line fix code formatting ........ r82183 | benjamin.peterson | 2010-06-23 15:29:26 -0500 (Wed, 23 Jun 2010) | 1 line cpython only gc tests ........
1 parent 63eebe5 commit 3e5cd1d

7 files changed

Lines changed: 43 additions & 14 deletions

File tree

Lib/http/cookiejar.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ def join_header_words(lists):
436436
if attr: headers.append("; ".join(attr))
437437
return ", ".join(headers)
438438

439+
def strip_quotes(text):
440+
if text.startswith('"'):
441+
text = text[1:]
442+
if text.endswith('"'):
443+
text = text[:-1]
444+
return text
445+
439446
def parse_ns_headers(ns_headers):
440447
"""Ad-hoc parser for Netscape protocol cookie-attributes.
441448
@@ -453,7 +460,7 @@ def parse_ns_headers(ns_headers):
453460
"""
454461
known_attrs = ("expires", "domain", "path", "secure",
455462
# RFC 2109 attrs (may turn up in Netscape cookies, too)
456-
"port", "max-age")
463+
"version", "port", "max-age")
457464

458465
result = []
459466
for ns_header in ns_headers:
@@ -473,12 +480,11 @@ def parse_ns_headers(ns_headers):
473480
k = lc
474481
if k == "version":
475482
# This is an RFC 2109 cookie.
483+
v = strip_quotes(v)
476484
version_set = True
477485
if k == "expires":
478486
# convert expires date to seconds since epoch
479-
if v.startswith('"'): v = v[1:]
480-
if v.endswith('"'): v = v[:-1]
481-
v = http2time(v) # None if invalid
487+
v = http2time(strip_quotes(v)) # None if invalid
482488
pairs.append((k, v))
483489

484490
if pairs:
@@ -1446,7 +1452,11 @@ def _cookie_from_cookie_tuple(self, tup, request):
14461452

14471453
# set the easy defaults
14481454
version = standard.get("version", None)
1449-
if version is not None: version = int(version)
1455+
if version is not None:
1456+
try:
1457+
version = int(version)
1458+
except ValueError:
1459+
return None # invalid version, ignore cookie
14501460
secure = standard.get("secure", False)
14511461
# (discard is also set if expires is Absent)
14521462
discard = standard.get("discard", False)

Lib/site.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@ def getsitepackages():
273273
environment, and will return a list of full paths.
274274
"""
275275
sitepackages = []
276-
seen = []
276+
seen = set()
277277

278278
for prefix in PREFIXES:
279279
if not prefix or prefix in seen:
280280
continue
281-
seen.append(prefix)
281+
seen.add(prefix)
282282

283283
if sys.platform in ('os2emx', 'riscos'):
284284
sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))

Lib/test/test_dict.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ def _tracked(self, t):
664664
gc.collect()
665665
self.assertTrue(gc.is_tracked(t), t)
666666

667+
@support.cpython_only
667668
def test_track_literals(self):
668669
# Test GC-optimization of dict literals
669670
x, y, z, w = 1.5, "a", (1, None), []
@@ -681,6 +682,7 @@ def test_track_literals(self):
681682
self._tracked({1: {}})
682683
self._tracked({1: set()})
683684

685+
@support.cpython_only
684686
def test_track_dynamic(self):
685687
# Test GC-optimization of dynamically-created dicts
686688
class MyObject(object):
@@ -744,6 +746,7 @@ class MyObject(object):
744746
d.update([(x, y), (z, w)])
745747
self._tracked(d)
746748

749+
@support.cpython_only
747750
def test_track_subtypes(self):
748751
# Dict subtypes are always tracked
749752
class MyDict(dict):

Lib/test/test_http_cookiejar.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_http2time_garbage(self):
9797

9898

9999
class HeaderTests(TestCase):
100+
100101
def test_parse_ns_headers(self):
101102
# quotes should be stripped
102103
expected = [[('foo', 'bar'), ('expires', 2209069412), ('version', '0')]]
@@ -106,6 +107,16 @@ def test_parse_ns_headers(self):
106107
]:
107108
self.assertEquals(parse_ns_headers([hdr]), expected)
108109

110+
def test_parse_ns_headers_version(self):
111+
112+
# quotes should be stripped
113+
expected = [[('foo', 'bar'), ('version', '1')]]
114+
for hdr in [
115+
'foo=bar; version="1"',
116+
'foo=bar; Version="1"',
117+
]:
118+
self.assertEquals(parse_ns_headers([hdr]), expected)
119+
109120
def test_parse_ns_headers_special_names(self):
110121
# names such as 'expires' are not special in first name=value pair
111122
# of Set-Cookie: header
@@ -1020,6 +1031,8 @@ def cookiejar_from_cookie_headers(headers):
10201031
["Set-Cookie2: a=foo; path=/; Version=1; domain"],
10211032
# bad max-age
10221033
["Set-Cookie: b=foo; max-age=oops"],
1034+
# bad version
1035+
["Set-Cookie: b=foo; version=spam"],
10231036
]:
10241037
c = cookiejar_from_cookie_headers(headers)
10251038
# these bad cookies shouldn't be set

Objects/enumobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ enum_next(enumobject *en)
159159
}
160160

161161
PyDoc_STRVAR(enum_doc,
162-
"enumerate(iterable) -> iterator for index, value of iterable\n"
162+
"enumerate(iterable[, start]) -> iterator for index, value of iterable\n"
163163
"\n"
164164
"Return an enumerate object. iterable must be another object that supports\n"
165165
"iteration. The enumerate object yields pairs containing a count (from\n"
166-
"zero) and a value yielded by the iterable argument. enumerate is useful\n"
167-
"for obtaining an indexed list: (0, seq[0]), (1, seq[1]), (2, seq[2]), ...");
166+
"start, which defaults to zero) and a value yielded by the iterable argument.\n"
167+
"enumerate is useful for obtaining an indexed list:\n"
168+
" (0, seq[0]), (1, seq[1]), (2, seq[2]), ...");
168169

169170
PyTypeObject PyEnum_Type = {
170171
PyVarObject_HEAD_INIT(&PyType_Type, 0)

Parser/asdl_c.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,9 @@ def visitModule(self, mod):
732732
{
733733
int i, result;
734734
PyObject *s, *l = PyTuple_New(num_fields);
735-
if (!l) return 0;
736-
for(i = 0; i < num_fields; i++) {
735+
if (!l)
736+
return 0;
737+
for (i = 0; i < num_fields; i++) {
737738
s = PyUnicode_FromString(attrs[i]);
738739
if (!s) {
739740
Py_DECREF(l);

Python/Python-ast.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
537537
{
538538
int i, result;
539539
PyObject *s, *l = PyTuple_New(num_fields);
540-
if (!l) return 0;
541-
for(i = 0; i < num_fields; i++) {
540+
if (!l)
541+
return 0;
542+
for (i = 0; i < num_fields; i++) {
542543
s = PyUnicode_FromString(attrs[i]);
543544
if (!s) {
544545
Py_DECREF(l);

0 commit comments

Comments
 (0)