Index: cookielib.py =================================================================== --- cookielib.py (revision 45808) +++ cookielib.py (working copy) @@ -39,15 +39,10 @@ MISSING_FILENAME_TEXT = ("a filename was not supplied (nor was the CookieJar " "instance initialised with one)") -def reraise_unmasked_exceptions(unmasked=()): +def warn_unhandled_exception(): # There are a few catch-all except: statements in this module, for - # catching input that's bad in unexpected ways. - # This function re-raises some exceptions we don't want to trap. - unmasked = unmasked + (KeyboardInterrupt, SystemExit, MemoryError) - etype = sys.exc_info()[0] - if issubclass(etype, unmasked): - raise - # swallowed an exception + # catching input that's bad in unexpected ways. Warn if any + # exceptions are caught there. import warnings, traceback, StringIO f = StringIO.StringIO() traceback.print_exc(None, f) @@ -1552,8 +1547,8 @@ try: cookies = self._cookies_from_attrs_set( split_header_words(rfc2965_hdrs), request) - except: - reraise_unmasked_exceptions() + except Exception: + warn_unhandled_exception() cookies = [] if ns_hdrs and netscape: @@ -1561,8 +1556,8 @@ # RFC 2109 and Netscape cookies ns_cookies = self._cookies_from_attrs_set( parse_ns_headers(ns_hdrs), request) - except: - reraise_unmasked_exceptions() + except Exception: + warn_unhandled_exception() ns_cookies = [] self._process_rfc2109_cookies(ns_cookies) Index: _LWPCookieJar.py =================================================================== --- _LWPCookieJar.py (revision 45808) +++ _LWPCookieJar.py (working copy) @@ -12,9 +12,10 @@ """ import time, re, logging -from cookielib import (reraise_unmasked_exceptions, FileCookieJar, LoadError, - Cookie, MISSING_FILENAME_TEXT, join_header_words, split_header_words, - iso2time, time2isoz) +from cookielib import (warn_unhandled_exception, FileCookieJar, LoadError, + Cookie, MISSING_FILENAME_TEXT, + join_header_words, split_header_words, + iso2time, time2isoz) def lwp_cookie_str(cookie): """Return string representation of Cookie in an the LWP cookie file format. @@ -92,7 +93,8 @@ def _really_load(self, f, filename, ignore_discard, ignore_expires): magic = f.readline() if not re.search(self.magic_re, magic): - msg = "%s does not seem to contain cookies" % filename + msg = ("%r does not look like a Set-Cookie3 (LWP) format " + "file" % filename) raise LoadError(msg) now = time.time() @@ -159,6 +161,10 @@ if not ignore_expires and c.is_expired(now): continue self.set_cookie(c) - except: - reraise_unmasked_exceptions((IOError,)) - raise LoadError("invalid Set-Cookie3 format file %s" % filename) + + except IOError: + raise + except Exception: + warn_unhandled_exception() + raise LoadError("invalid Set-Cookie3 format file %r: %r" % + (filename, line)) Index: _MozillaCookieJar.py =================================================================== --- _MozillaCookieJar.py (revision 45808) +++ _MozillaCookieJar.py (working copy) @@ -2,8 +2,8 @@ import re, time, logging -from cookielib import (reraise_unmasked_exceptions, FileCookieJar, LoadError, - Cookie, MISSING_FILENAME_TEXT) +from cookielib import (warn_unhandled_exception, FileCookieJar, LoadError, + Cookie, MISSING_FILENAME_TEXT) class MozillaCookieJar(FileCookieJar): """ @@ -51,7 +51,7 @@ if not re.search(self.magic_re, magic): f.close() raise LoadError( - "%s does not look like a Netscape format cookies file" % + "%r does not look like a Netscape format cookies file" % filename) try: @@ -104,9 +104,11 @@ continue self.set_cookie(c) - except: - reraise_unmasked_exceptions((IOError,)) - raise LoadError("invalid Netscape format file %s: %s" % + except IOError: + raise + except Exception: + warn_unhandled_exception() + raise LoadError("invalid Netscape format cookies file %r: %r" % (filename, line)) def save(self, filename=None, ignore_discard=False, ignore_expires=False):