diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-09 22:29:55 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-09 22:29:55 +0000 |
commit | bc4f975f09c0e36040f983e581ae7caa69d1fe1d (patch) | |
tree | 7331049652a0de372f365cfb533e8f6c59a306b5 | |
parent | cc79c5f566861e91c8ff007902cf8c29e6ac247f (diff) | |
download | portage-bc4f975f09c0e36040f983e581ae7caa69d1fe1d.tar.gz portage-bc4f975f09c0e36040f983e581ae7caa69d1fe1d.tar.bz2 portage-bc4f975f09c0e36040f983e581ae7caa69d1fe1d.zip |
Encode unicode messages as bytes in order to avoid TypeError from
syslog.syslog() with python-2.x.
svn path=/main/trunk/; revision=13962
-rw-r--r-- | pym/portage/elog/mod_syslog.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/pym/portage/elog/mod_syslog.py b/pym/portage/elog/mod_syslog.py index bb66b2b74..0fe205644 100644 --- a/pym/portage/elog/mod_syslog.py +++ b/pym/portage/elog/mod_syslog.py @@ -3,20 +3,28 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +import sys import syslog from portage.const import EBUILD_PHASES +_pri = { + "INFO" : syslog.LOG_INFO, + "WARN" : syslog.LOG_WARNING, + "ERROR" : syslog.LOG_ERR, + "LOG" : syslog.LOG_NOTICE, + "QA" : syslog.LOG_WARNING +} + def process(mysettings, key, logentries, fulltext): syslog.openlog("portage", syslog.LOG_ERR | syslog.LOG_WARNING | syslog.LOG_INFO | syslog.LOG_NOTICE, syslog.LOG_LOCAL5) for phase in EBUILD_PHASES: if not phase in logentries: continue for msgtype,msgcontent in logentries[phase]: - pri = {"INFO": syslog.LOG_INFO, - "WARN": syslog.LOG_WARNING, - "ERROR": syslog.LOG_ERR, - "LOG": syslog.LOG_NOTICE, - "QA": syslog.LOG_WARNING} msgtext = "".join(msgcontent) - syslog.syslog(pri[msgtype], "%s: %s: %s" % (key, phase, msgtext)) + msgtext = "%s: %s: %s" % (key, phase, msgtext) + if sys.hexversion < 0x3000000 and isinstance(msgtext, unicode): + # Avoid TypeError from syslog.syslog() + msgtext = msgtext.encode('utf_8', 'replace') + syslog.syslog(_pri[msgtype], msgtext) syslog.closelog() |