Fix non-ASCII exception handling.

This commit is contained in:
Bastian Kleineidam 2012-10-24 22:14:45 +02:00
parent 64de760b97
commit dd2c963fac
2 changed files with 10 additions and 7 deletions

View file

@ -5,6 +5,8 @@ Changes:
and the file is accessible by others.
- checking: Add debug statements for unparseable content types.
Closing: SF bug #3579714
- checking: Fix handling of non-ASCII exceptions (regression in 8.1).
Closing: SF bug #3579766
8.1 "Safety Not Guaranteed" (released 14.10.2012)

View file

@ -577,18 +577,19 @@ class UrlBase (object):
"""
An exception occurred. Log it and set the cache flag.
"""
etype, value = sys.exc_info()[:2]
log.debug(LOG_CHECK, "Error in %s: %s %s", self.url, etype, value, exception=True)
etype, evalue = sys.exc_info()[:2]
log.debug(LOG_CHECK, "Error in %s: %s %s", self.url, etype, evalue, exception=True)
# note: etype must be the exact class, not a subclass
if (etype in ExcNoCacheList) or \
(etype == socket.error and value.args[0]==errno.EBADF) or \
not value:
(etype == socket.error and evalue.args[0]==errno.EBADF) or \
not evalue:
# EBADF occurs when operating on an already socket
self.caching = False
# format unicode message "<exception name>: <error message>"
errmsg = unicode(etype.__name__)
if unicode(value):
# use Exception class name
errmsg += u": %s" % unicode(value)
uvalue = strformat.unicode_safe(evalue)
if uvalue:
errmsg += u": %s" % uvalue
# limit length to 240
return strformat.limit(errmsg, length=240)