Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,10 @@ def load(self, filename=None, ignore_discard=False, ignore_expires=False):
if self.filename is not None: filename = self.filename
else: raise ValueError(MISSING_FILENAME_TEXT)

with open(filename) as f:
# cookie value should be ASCII, but cookiejar file may contain
# non-ASCII comments or invalid cookies.
# We use "surrogateescape" error handler to read them.
with open(filename, encoding="ascii", errors="surrogateescape") as f:
self._really_load(f, filename, ignore_discard, ignore_expires)

def revert(self, filename=None,
Expand Down Expand Up @@ -1892,7 +1895,7 @@ def save(self, filename=None, ignore_discard=False, ignore_expires=False):

with os.fdopen(
os.open(filename, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600),
'w',
'w', encoding="ascii", errors="surrogateescape",
) as f:
# There really isn't an LWP Cookies 2.0 format, but this indicates
# that there is extra information in here (domain_dot and
Expand Down Expand Up @@ -2086,7 +2089,7 @@ def save(self, filename=None, ignore_discard=False, ignore_expires=False):

with os.fdopen(
os.open(filename, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600),
'w',
'w', encoding="ascii", errors="surrogateescape",
) as f:
f.write(NETSCAPE_HEADER_TEXT)
now = time.time()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed the encoding and error handler used by :class:`http.cookiejar.FileCookieJar` and its subclasses when reading and writing Cookie files to "ASCII" and "surrogateescape".
Loading