diff options
author | Julien Cristau <julien.cristau@logilab.fr> | 2012-11-13 07:47:04 +0100 |
---|---|---|
committer | Julien Cristau <julien.cristau@logilab.fr> | 2012-11-13 07:47:04 +0100 |
commit | ff4d1160a08c5925b4d98eba350a231bea2bd03f (patch) | |
tree | 499d735c689395943f97ec8533e5c7b82fa86405 | |
parent | 6c87841bc7f0a1224df6708e88e376af29c4f535 (diff) | |
download | logilab-common-ff4d1160a08c5925b4d98eba350a231bea2bd03f.tar.gz |
ustrftime: ask the system for the encoding instead of trying to guess
strftime uses the encoding corresponding to the LC_TIME locale setting.
Closes #109740
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | date.py | 6 |
2 files changed, 6 insertions, 7 deletions
@@ -1,9 +1,10 @@ ChangeLog for logilab.common ============================ - -- - * fix logilab.common.date.ustrftime() for python3 (closes #82161, - patch by Arfrever Frehtes Taifersar Arahesis) +-- + * date: fix ustrftime() impl. for python3 (closes #82161, patch by Arfrever + Frehtes Taifersar Arahesis) and encoding detection for python2 (closes + #109740) 2012-07-30 -- 0.58.2 * modutils: fixes (closes #100757 and #100935) @@ -23,7 +23,7 @@ __docformat__ = "restructuredtext en" import math import re import sys -from locale import getpreferredencoding +from locale import getlocale, LC_TIME from datetime import date, time, datetime, timedelta from time import strptime as time_strptime from calendar import monthrange, timegm @@ -281,8 +281,6 @@ def last_day(somedate): def ustrftime(somedate, fmt='%Y-%m-%d'): """like strftime, but returns a unicode string instead of an encoded string which may be problematic with localized date. - - When using Python 2, encoding is guessed by locale.getpreferredencoding(). """ if sys.version_info >= (3, 3): # datetime.date.strftime() supports dates since year 1 in Python >=3.3. @@ -290,7 +288,7 @@ def ustrftime(somedate, fmt='%Y-%m-%d'): else: try: if sys.version_info < (3, 0): - encoding = getpreferredencoding(do_setlocale=False) or 'UTF-8' + encoding = getlocale(LC_TIME)[1] or 'ascii' return unicode(somedate.strftime(str(fmt)), encoding) else: return somedate.strftime(fmt) |