summaryrefslogtreecommitdiffstats
path: root/pym/portage/elog/mod_save_summary.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2013-01-18 13:33:08 -0800
committerZac Medico <zmedico@gentoo.org>2013-01-18 13:36:47 -0800
commit71235479ab208318dff391420f9695f5cfaa9594 (patch)
treed36bc22802e3b13c8ca5dce4328540a287c6eb3f /pym/portage/elog/mod_save_summary.py
parent0d732def5d30b29ab2941f0c66919a3ec4e8eb02 (diff)
downloadportage-71235479ab208318dff391420f9695f5cfaa9594.tar.gz
portage-71235479ab208318dff391420f9695f5cfaa9594.tar.bz2
portage-71235479ab208318dff391420f9695f5cfaa9594.zip
Use unicode_literals more.
This helps to ensure consistent results, regardless of whether we're using Python 2 or Python 3.
Diffstat (limited to 'pym/portage/elog/mod_save_summary.py')
-rw-r--r--pym/portage/elog/mod_save_summary.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/pym/portage/elog/mod_save_summary.py b/pym/portage/elog/mod_save_summary.py
index 3ad1dd3b8..786f89454 100644
--- a/pym/portage/elog/mod_save_summary.py
+++ b/pym/portage/elog/mod_save_summary.py
@@ -1,9 +1,12 @@
# elog/mod_save_summary.py - elog dispatch module
-# Copyright 2006-2012 Gentoo Foundation
+# Copyright 2006-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+from __future__ import unicode_literals
+
import errno
import io
+import sys
import time
import portage
from portage import os
@@ -71,17 +74,19 @@ def process(mysettings, key, logentries, fulltext):
apply_permissions(elogfilename, uid=logfile_uid, gid=elogdir_gid,
mode=elogdir_grp_mode, mask=0)
- time_str = time.strftime("%Y-%m-%d %H:%M:%S %Z",
- time.localtime(time.time()))
- # Avoid potential UnicodeDecodeError later.
+ time_fmt = "%Y-%m-%d %H:%M:%S %Z"
+ if sys.hexversion < 0x3000000:
+ time_fmt = _unicode_encode(time_fmt)
+ time_str = time.strftime(time_fmt, time.localtime(time.time()))
+ # Avoid potential UnicodeDecodeError in Python 2, since strftime
+ # returns bytes in Python 2, and %Z may contain non-ascii chars.
time_str = _unicode_decode(time_str,
encoding=_encodings['content'], errors='replace')
- elogfile.write(_unicode_decode(
- _(">>> Messages generated by process " +
+ elogfile.write(_(">>> Messages generated by process "
"%(pid)d on %(time)s for package %(pkg)s:\n\n") %
- {"pid": os.getpid(), "time": time_str, "pkg": key}))
+ {"pid": os.getpid(), "time": time_str, "pkg": key})
elogfile.write(_unicode_decode(fulltext))
- elogfile.write(_unicode_decode("\n"))
+ elogfile.write("\n")
elogfile.close()
return elogfilename