[PEAK] Exception logging and source code encoding

Phillip J. Eby pje at telecommunity.com
Mon Mar 22 11:39:55 EST 2004

My plan for handling this is to add "exception formatting" and "exception 
reporting" services to the core, and the logging system will access an 
exception formatting service to format exceptions.  At that point, you'll 
be able to use a custom exception formatting service to change how the 
traceback is rendered.

And, if possible, I'll actually make the default traceback formatter handle 
source file encodings, assuming there's a way to find out what the encoding 
is without having to parse the file myself.  :)

At 05:33 PM 3/22/04 +0100, Radek Kanovsky wrote:
>There is a little problem with exception logging. I use new python2.3
>feature for specifying default source code encoding for u"..."
>unicode expressions (e.g. ISO-8859-2 in my case). Such expression can
>occasionally be reported in traceback output. Then source code lines
>are retrieved as 8bit string not as unicode and PEAK tries to convert
>them to UTF-8 and that obviously fails because source lines can contain
>character codes grater than 127. I have fixed this by following patch.
>It is not very satisfactory solution but don't know how to correct it
>better now. Original 'utf-8' encoding is good as unicode messages
>are often sent to logger.
>diff -u -r1.1.1.2 logs.py
>--- a/running/logs.py   1 Mar 2004 10:47:27 -0000
>+++ b/running/logs.py   22 Mar 2004 16:17:39 -0000
>@@ -400,8 +400,13 @@
>      def __str__(self):
>-        return self.prefixedString.encode('utf8','replace')
>+        ps = self.prefixedString
>+        try :
>+            return ps.encode('utf8','replace')
>+        except UnicodeDecodeError :
>+            return ps.translate(_asciiTrans)
>+_asciiTrans = "".join([ chr(i) for i in xrange(0,128) ]) + "?" * 128
>PEAK mailing list
>PEAK at eby-sarna.com

More information about the PEAK mailing list