diff options
author | ianb <devnull@localhost> | 2008-03-26 02:17:04 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2008-03-26 02:17:04 +0000 |
commit | aed98f824bb54253b9d17ece819e965c532beea4 (patch) | |
tree | 7473f3b66650d5ee7bb224d9c939079823937f1f /paste/exceptions | |
parent | 3bd39f08a20e2231fec8496244833ea960603423 (diff) | |
download | paste-aed98f824bb54253b9d17ece819e965c532beea4.tar.gz |
Fix #240, unicode exceptions cause collector to fail. Also make tests somewhat less fragile
Diffstat (limited to 'paste/exceptions')
-rw-r--r-- | paste/exceptions/collector.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/paste/exceptions/collector.py b/paste/exceptions/collector.py index 1520dd5..65f9ec0 100644 --- a/paste/exceptions/collector.py +++ b/paste/exceptions/collector.py @@ -33,6 +33,7 @@ import warnings DEBUG_EXCEPTION_FORMATTER = True DEBUG_IDENT_PREFIX = 'E-' +FALLBACK_ENCODING = 'UTF-8' __all__ = ['collect_exception', 'ExceptionCollector'] @@ -364,7 +365,7 @@ class ExceptionCollector(object): frames=frames, exception_formatted=self.collectExceptionOnly(etype, value), exception_type=etype, - exception_value=str(value), + exception_value=self.safeStr(value), identification_code=ident, date=time.localtime(), extra_data=extra_data) @@ -379,6 +380,17 @@ class ExceptionCollector(object): pass return result + def safeStr(self, obj): + try: + return str(obj) + except UnicodeEncodeError: + try: + return unicode(obj).encode(FALLBACK_ENCODING, 'replace') + except UnicodeEncodeError: + # This is when something is really messed up, but this can + # happen when the __str__ of an object has to handle unicode + return repr(obj) + limit = 200 class Bunch(object): |