|
16 | 16 | CookieJar, DefaultCookiePolicy, LWPCookieJar, MozillaCookieJar, |
17 | 17 | LoadError, lwp_cookie_str, DEFAULT_HTTP_PORT, escape_path, |
18 | 18 | reach, is_HDN, domain_match, user_domain_match, request_path, |
19 | | - request_port, request_host) |
| 19 | + request_port, request_host, NETSCAPE_HEADER_TEXT) |
20 | 20 |
|
21 | 21 | mswindows = (sys.platform == "win32") |
22 | 22 |
|
@@ -2049,31 +2049,29 @@ def test_session_cookies(self): |
2049 | 2049 | self.assertNotEqual(counter["session_before"], 0) |
2050 | 2050 |
|
2051 | 2051 | def test_curl_format(self): |
2052 | | - # Check compatibility with curl / wget cookiejar format. |
2053 | | - # See issue 17164 |
2054 | | - filename = test.support.TESTFN |
2055 | | - try: |
2056 | | - expires = int(time.time() + 3600) |
2057 | | - with open(filename, "w") as f: |
2058 | | - f.write(MozillaCookieJar.header) |
2059 | | - f.write("www.foo.com\tFALSE\t/\tFALSE\t%u\tfoo1\tbar\n" % |
2060 | | - expires) |
2061 | | - f.write("www.foo.com\tFALSE\t/\tFALSE\t0\tfoo2\tbar\n") |
2062 | | - f.write("www.foo.com\tFALSE\t/\tFALSE\t\tfoo3\tbar\n") |
2063 | | - c = MozillaCookieJar() |
2064 | | - c.revert(filename) |
2065 | | - self.assertEqual(len(c), 1) |
2066 | | - c.revert(filename, ignore_discard = True) |
2067 | | - self.assertEqual(len(c), 3) |
2068 | | - c.save(filename, ignore_discard = True) |
2069 | | - with open(filename, "r") as f: |
2070 | | - for line in f: |
2071 | | - if line == '\n' or line.startswith('#'): |
2072 | | - continue |
2073 | | - self.assertRegex(line.split('\t')[4], '^\d+$') |
2074 | | - finally: |
2075 | | - try: os.unlink(filename) |
2076 | | - except OSError: pass |
| 2052 | + # Check compatibility with the curl and Wget cookie file format, |
| 2053 | + # which uses 0 for session cookies (gh-61364). |
| 2054 | + filename = os_helper.TESTFN |
| 2055 | + self.addCleanup(os_helper.unlink, filename) |
| 2056 | + expires = int(time.time() + 3600) |
| 2057 | + with open(filename, "w") as f: |
| 2058 | + f.write(NETSCAPE_HEADER_TEXT) |
| 2059 | + f.write("www.foo.com\tFALSE\t/\tFALSE\t%u\tfoo1\tbar\n" % expires) |
| 2060 | + f.write("www.foo.com\tFALSE\t/\tFALSE\t0\tfoo2\tbar\n") |
| 2061 | + f.write("www.foo.com\tFALSE\t/\tFALSE\t\tfoo3\tbar\n") |
| 2062 | + |
| 2063 | + c = MozillaCookieJar() |
| 2064 | + c.revert(filename) |
| 2065 | + self.assertEqual(len(c), 1) |
| 2066 | + c.revert(filename, ignore_discard=True) |
| 2067 | + self.assertEqual(len(c), 3) |
| 2068 | + |
| 2069 | + # Session cookies are saved with 0, not with an empty field. |
| 2070 | + c.save(filename, ignore_discard=True) |
| 2071 | + with open(filename) as f: |
| 2072 | + for line in f: |
| 2073 | + if line.strip() and not line.startswith('#'): |
| 2074 | + self.assertRegex(line.split('\t')[4], r'^\d+$') |
2077 | 2075 |
|
2078 | 2076 |
|
2079 | 2077 | if __name__ == "__main__": |
|
0 commit comments