diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/http/cookiejar.py | 6 | ||||
| -rw-r--r-- | Lib/test/test_http_cookiejar.py | 25 |
2 files changed, 27 insertions, 4 deletions
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py index 0ba8200f32..befe7653c5 100644 --- a/Lib/http/cookiejar.py +++ b/Lib/http/cookiejar.py @@ -28,6 +28,7 @@ http://wwwsearch.sf.net/): __all__ = ['Cookie', 'CookieJar', 'CookiePolicy', 'DefaultCookiePolicy', 'FileCookieJar', 'LWPCookieJar', 'LoadError', 'MozillaCookieJar'] +import os import copy import datetime import re @@ -1762,10 +1763,7 @@ class FileCookieJar(CookieJar): """ CookieJar.__init__(self, policy) if filename is not None: - try: - filename+"" - except: - raise ValueError("filename must be string-like") + filename = os.fspath(filename) self.filename = filename self.delayload = bool(delayload) diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py index 8dbea3325d..170549caf5 100644 --- a/Lib/test/test_http_cookiejar.py +++ b/Lib/test/test_http_cookiejar.py @@ -6,6 +6,7 @@ import test.support import time import unittest import urllib.request +import pathlib from http.cookiejar import (time2isoz, http2time, iso2time, time2netscape, parse_ns_headers, join_header_words, split_header_words, Cookie, @@ -313,6 +314,30 @@ def _interact(cookiejar, url, set_cookie_hdrs, hdr_name): class FileCookieJarTests(unittest.TestCase): + def test_constructor_with_str(self): + filename = test.support.TESTFN + c = LWPCookieJar(filename) + self.assertEqual(c.filename, filename) + + def test_constructor_with_path_like(self): + filename = pathlib.Path(test.support.TESTFN) + c = LWPCookieJar(filename) + self.assertEqual(c.filename, os.fspath(filename)) + + def test_constructor_with_none(self): + c = LWPCookieJar(None) + self.assertIsNone(c.filename) + + def test_constructor_with_other_types(self): + class A: + pass + + for type_ in (int, float, A): + with self.subTest(filename=type_): + with self.assertRaises(TypeError): + instance = type_() + c = LWPCookieJar(filename=instance) + def test_lwp_valueless_cookie(self): # cookies with no value should be saved and loaded consistently filename = test.support.TESTFN |
