[PEAK] Exception logging and source code encoding
Radek Kanovsky
rk at dat.cz
Mon Mar 22 11:33:28 EST 2004
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.
RadekK
diff -u -r1.1.1.2 logs.py
--- a/running/logs.py 1 Mar 2004 10:47:27 -0000 1.1.1.2
+++ 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
More information about the PEAK
mailing list