| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 63eebe5 commit 3e5cd1d
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -436,6 +436,13 @@ def join_header_words(lists): | |||
| 436 | 436 | if attr: headers.append("; ".join(attr)) | |
| 437 | 437 | return ", ".join(headers) | |
| 438 | 438 | ||
| 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 | + | ||
| 439 | 446 | def parse_ns_headers(ns_headers): | |
| 440 | 447 | """Ad-hoc parser for Netscape protocol cookie-attributes. | |
| 441 | 448 | ||
@@ -453,7 +460,7 @@ def parse_ns_headers(ns_headers): | |||
| 453 | 460 | """ | |
| 454 | 461 | known_attrs = ("expires", "domain", "path", "secure", | |
| 455 | 462 | # RFC 2109 attrs (may turn up in Netscape cookies, too) | |
| 456 | - "port", "max-age") | ||
| 463 | + "version", "port", "max-age") | ||
| 457 | 464 | ||
| 458 | 465 | result = [] | |
| 459 | 466 | for ns_header in ns_headers: | |
@@ -473,12 +480,11 @@ def parse_ns_headers(ns_headers): | |||
| 473 | 480 | k = lc | |
| 474 | 481 | if k == "version": | |
| 475 | 482 | # This is an RFC 2109 cookie. | |
| 483 | + v = strip_quotes(v) | ||
| 476 | 484 | version_set = True | |
| 477 | 485 | if k == "expires": | |
| 478 | 486 | # 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 | ||
| 482 | 488 | pairs.append((k, v)) | |
| 483 | 489 | ||
| 484 | 490 | if pairs: | |
@@ -1446,7 +1452,11 @@ def _cookie_from_cookie_tuple(self, tup, request): | |||
| 1446 | 1452 | ||
| 1447 | 1453 | # set the easy defaults | |
| 1448 | 1454 | 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 | ||
| 1450 | 1460 | secure = standard.get("secure", False) | |
| 1451 | 1461 | # (discard is also set if expires is Absent) | |
| 1452 | 1462 | discard = standard.get("discard", False) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -273,12 +273,12 @@ def getsitepackages(): | |||
| 273 | 273 | environment, and will return a list of full paths. | |
| 274 | 274 | """ | |
| 275 | 275 | sitepackages = [] | |
| 276 | - seen = [] | ||
| 276 | + seen = set() | ||
| 277 | 277 | ||
| 278 | 278 | for prefix in PREFIXES: | |
| 279 | 279 | if not prefix or prefix in seen: | |
| 280 | 280 | continue | |
| 281 | - seen.append(prefix) | ||
| 281 | + seen.add(prefix) | ||
| 282 | 282 | ||
| 283 | 283 | if sys.platform in ('os2emx', 'riscos'): | |
| 284 | 284 | sitepackages.append(os.path.join(prefix, "Lib", "site-packages")) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -664,6 +664,7 @@ def _tracked(self, t): | |||
| 664 | 664 | gc.collect() | |
| 665 | 665 | self.assertTrue(gc.is_tracked(t), t) | |
| 666 | 666 | ||
| 667 | + @support.cpython_only | ||
| 667 | 668 | def test_track_literals(self): | |
| 668 | 669 | # Test GC-optimization of dict literals | |
| 669 | 670 | x, y, z, w = 1.5, "a", (1, None), [] | |
@@ -681,6 +682,7 @@ def test_track_literals(self): | |||
| 681 | 682 | self._tracked({1: {}}) | |
| 682 | 683 | self._tracked({1: set()}) | |
| 683 | 684 | ||
| 685 | + @support.cpython_only | ||
| 684 | 686 | def test_track_dynamic(self): | |
| 685 | 687 | # Test GC-optimization of dynamically-created dicts | |
| 686 | 688 | class MyObject(object): | |
@@ -744,6 +746,7 @@ class MyObject(object): | |||
| 744 | 746 | d.update([(x, y), (z, w)]) | |
| 745 | 747 | self._tracked(d) | |
| 746 | 748 | ||
| 749 | + @support.cpython_only | ||
| 747 | 750 | def test_track_subtypes(self): | |
| 748 | 751 | # Dict subtypes are always tracked | |
| 749 | 752 | class MyDict(dict): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,6 +97,7 @@ def test_http2time_garbage(self): | |||
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | 99 | class HeaderTests(TestCase): | |
| 100 | + | ||
| 100 | 101 | def test_parse_ns_headers(self): | |
| 101 | 102 | # quotes should be stripped | |
| 102 | 103 | expected = [[('foo', 'bar'), ('expires', 2209069412), ('version', '0')]] | |
@@ -106,6 +107,16 @@ def test_parse_ns_headers(self): | |||
| 106 | 107 | ]: | |
| 107 | 108 | self.assertEquals(parse_ns_headers([hdr]), expected) | |
| 108 | 109 | ||
| 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 | + | ||
| 109 | 120 | def test_parse_ns_headers_special_names(self): | |
| 110 | 121 | # names such as 'expires' are not special in first name=value pair | |
| 111 | 122 | # of Set-Cookie: header | |
@@ -1020,6 +1031,8 @@ def cookiejar_from_cookie_headers(headers): | |||
| 1020 | 1031 | ["Set-Cookie2: a=foo; path=/; Version=1; domain"], | |
| 1021 | 1032 | # bad max-age | |
| 1022 | 1033 | ["Set-Cookie: b=foo; max-age=oops"], | |
| 1034 | + # bad version | ||
| 1035 | + ["Set-Cookie: b=foo; version=spam"], | ||
| 1023 | 1036 | ]: | |
| 1024 | 1037 | c = cookiejar_from_cookie_headers(headers) | |
| 1025 | 1038 | # these bad cookies shouldn't be set | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,12 +159,13 @@ enum_next(enumobject *en) | |||
| 159 | 159 | } | |
| 160 | 160 | ||
| 161 | 161 | 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" | ||
| 163 | 163 | "\n" | |
| 164 | 164 | "Return an enumerate object. iterable must be another object that supports\n" | |
| 165 | 165 | "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]), ..."); | ||
| 168 | 169 | ||
| 169 | 170 | PyTypeObject PyEnum_Type = { | |
| 170 | 171 | PyVarObject_HEAD_INIT(&PyType_Type, 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -732,8 +732,9 @@ def visitModule(self, mod): | |||
| 732 | 732 | { | |
| 733 | 733 | int i, result; | |
| 734 | 734 | 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++) { | ||
| 737 | 738 | s = PyUnicode_FromString(attrs[i]); | |
| 738 | 739 | if (!s) { | |
| 739 | 740 | Py_DECREF(l); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -537,8 +537,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) | |||
| 537 | 537 | { | |
| 538 | 538 | int i, result; | |
| 539 | 539 | 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++) { | ||
| 542 | 543 | s = PyUnicode_FromString(attrs[i]); | |
| 543 | 544 | if (!s) { | |
| 544 | 545 | Py_DECREF(l); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments