From 120187eb53f69b015cbbcecd38da0901e3e1cd36 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 5 Sep 2009 22:01:43 +0000 Subject: [PATCH] Use _unicode_decode() on the string returned from time.strftime(), in order to avoid a potential UnicodeDecodeError later. Thanks to Markus Duft for reporting. svn path=/main/trunk/; revision=14201 --- pym/_emerge/main.py | 6 +++++- pym/portage/__init__.py | 5 +++-- pym/portage/elog/mod_mail_summary.py | 7 ++++++- pym/portage/elog/mod_save.py | 5 ++++- pym/portage/glsa.py | 3 ++- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index db57f2985..57277ecfb 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -9,6 +9,8 @@ import textwrap import platform import portage from portage import os +from portage import _encodings +from portage import _unicode_decode import _emerge.help import portage.xpak, commands, errno, re, time from portage.output import colorize, xtermTitle, xtermTitleReset @@ -1297,7 +1299,9 @@ def emerge_main(): if not "--pretend" in myopts: emergelog(xterm_titles, "Started emerge on: "+\ - time.strftime("%b %d, %Y %H:%M:%S", time.localtime())) + _unicode_decode( + time.strftime("%b %d, %Y %H:%M:%S", time.localtime()), + encoding=_encodings['content'], errors='replace')) myelogstr="" if myopts: myelogstr=" ".join(myopts) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index dfb9c0fef..f6cf25f53 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -6267,8 +6267,9 @@ def _prepare_workdir(mysettings): logid_path = os.path.join(mysettings["PORTAGE_BUILDDIR"], ".logid") if not os.path.exists(logid_path): open(_unicode_encode(logid_path), 'w') - logid_time = time.strftime("%Y%m%d-%H%M%S", - time.gmtime(os.stat(logid_path).st_mtime)) + logid_time = _unicode_decode(time.strftime("%Y%m%d-%H%M%S", + time.gmtime(os.stat(logid_path).st_mtime)), + encoding=_encodings['content'], errors='replace') mysettings["PORTAGE_LOG_FILE"] = os.path.join( mysettings["PORT_LOGDIR"], "%s:%s:%s.log" % \ (mysettings["CATEGORY"], mysettings["PF"], logid_time)) diff --git a/pym/portage/elog/mod_mail_summary.py b/pym/portage/elog/mod_mail_summary.py index adffd4640..e642dc044 100644 --- a/pym/portage/elog/mod_mail_summary.py +++ b/pym/portage/elog/mod_mail_summary.py @@ -8,6 +8,8 @@ from portage.exception import PortageException from portage.localization import _ from portage.util import writemsg from portage import os +from portage import _encodings +from portage import _unicode_decode import socket import time @@ -15,8 +17,11 @@ import time _items = {} def process(mysettings, key, logentries, fulltext): global _items + time_str = _unicode_decode( + time.strftime("%Y%m%d-%H%M%S %Z", time.localtime(time.time())), + encoding=_encodings['content'], errors='replace') header = _(">>> Messages generated for package %(pkg)s by process %(pid)d on %(time)s:\n\n") % \ - {"pkg": key, "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} config_root = mysettings["PORTAGE_CONFIGROOT"] mysettings, items = _items.setdefault(config_root, (mysettings, {})) items[key] = header + fulltext diff --git a/pym/portage/elog/mod_save.py b/pym/portage/elog/mod_save.py index 0707b00f8..89de71c86 100644 --- a/pym/portage/elog/mod_save.py +++ b/pym/portage/elog/mod_save.py @@ -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.util import ensure_dirs @@ -20,7 +21,9 @@ def process(mysettings, key, logentries, fulltext): elogdir = os.path.join(os.sep, "var", "log", "portage", "elog") ensure_dirs(elogdir, uid=portage_uid, gid=portage_gid, mode=02770) - elogfilename = elogdir+"/"+path+":"+time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time()))+".log" + elogfilename = os.path.join(elogdir, path + ":" + _unicode_decode( + time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time())), + encoding=_encodings['content'], errors='replace') + ".log") elogfile = codecs.open(_unicode_encode(elogfilename, encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['content'], errors='backslashreplace') diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index 6dc73ac67..95c3c813c 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -404,7 +404,8 @@ def format_date(datestr): return datestr # TODO We could format to local date format '%x' here? - return d.strftime("%B %d, %Y") + return _unicode_decode(d.strftime("%B %d, %Y"), + encoding=_encodings['content'], errors='replace') # simple Exception classes to catch specific errors class GlsaTypeException(Exception): -- 2.26.2