Use _unicode_decode() on the string retunred from time.strftime(), in order
authorZac Medico <zmedico@gentoo.org>
Thu, 3 Sep 2009 01:06:52 +0000 (01:06 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 3 Sep 2009 01:06:52 +0000 (01:06 -0000)
to avoid a potential UnicodeDecodeError later. Thanks to Markus Duft
<mduft@gentoo.org> for reporting.

svn path=/main/trunk/; revision=14180

pym/portage/elog/mod_save_summary.py

index f35c71c831ee439faec40dde0d766467385410cf..9aeb89fc92fd1e9d15daa7e3306eb63d3fc5f5f6 100644 (file)
@@ -7,6 +7,7 @@ import codecs
 import time
 from portage import os
 from portage import _encodings
+from portage import _unicode_decode
 from portage import _unicode_encode
 from portage.data import portage_uid, portage_gid
 from portage.localization import _
@@ -25,8 +26,13 @@ def process(mysettings, key, logentries, fulltext):
                encoding=_encodings['fs'], errors='strict'),
                mode='a', encoding=_encodings['content'], errors='backslashreplace')
        apply_permissions(elogfilename, mode=060, mask=0)
+       time_str = time.strftime("%Y-%m-%d %H:%M:%S %Z",
+               time.localtime(time.time()))
+       # Avoid potential UnicodeDecodeError later.
+       time_str = _unicode_decode(time_str,
+               encoding=_encodings['content'], errors='replace')
        elogfile.write(_(">>> Messages generated by process %(pid)d on %(time)s for package %(pkg)s:\n\n") %
-                       {"pid": os.getpid(), "time": time.strftime("%Y-%m-%d %H:%M:%S %Z", time.localtime(time.time())), "pkg": key})
+                       {"pid": os.getpid(), "time": time_str, "pkg": key})
        elogfile.write(fulltext)
        elogfile.write("\n")
        elogfile.close()