[pypy-commit] pypy py3.6: Handle locale in time.strftime(). Fixes #3079
rlamy
pypy.commits at gmail.com
Sun Sep 22 07:44:15 EDT 2019
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.6
Changeset: r97590:7392d01b93d0
Date: 2019-09-22 12:42 +0100
http://bitbucket.org/pypy/pypy/changeset/7392d01b93d0/
Log: Handle locale in time.strftime(). Fixes #3079
diff --git a/lib-python/3/test/test_time.py b/lib-python/3/test/test_time.py
--- a/lib-python/3/test/test_time.py
+++ b/lib-python/3/test/test_time.py
@@ -530,6 +530,8 @@
self.skipTest('could not set locale.LC_ALL to fr_FR')
# This should not cause an exception
time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
+ # PyPy addition:
+ time.strftime("%B", (2009,8,1,0,0,0,0,0,0)).lower()
class _TestAsctimeYear:
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -6,6 +6,8 @@
from pypy.interpreter.timeutils import (
SECS_TO_NS, MS_TO_NS, US_TO_NS, monotonic as _monotonic, timestamp_w)
from pypy.interpreter.unicodehelper import decode_utf8sp
+from pypy.module._codecs.locale import (
+ str_decode_locale_surrogateescape, unicode_encode_locale_surrogateescape)
from rpython.rtyper.lltypesystem import lltype
from rpython.rlib.rarithmetic import (
intmask, r_ulonglong, r_longfloat, widen, ovfcheck, ovfcheck_float_to_int)
@@ -338,8 +340,8 @@
"void pypy__tzset();"],
separate_module_sources = ["""
long pypy_get_timezone() {
- long timezone;
- _get_timezone(&timezone);
+ long timezone;
+ _get_timezone(&timezone);
return timezone;
};
int pypy_get_daylight() {
@@ -359,7 +361,7 @@
c_get_timezone = external('pypy_get_timezone', [], rffi.LONG, win_eci)
c_get_daylight = external('pypy_get_daylight', [], rffi.INT, win_eci)
c_get_tzname = external('pypy_get_tzname',
- [rffi.SIZE_T, rffi.INT, rffi.CCHARP],
+ [rffi.SIZE_T, rffi.INT, rffi.CCHARP],
rffi.INT, win_eci, calling_conv='c')
c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P],
@@ -869,6 +871,7 @@
raise oefmt(space.w_ValueError, "invalid format string")
i += 1
+ format = unicode_encode_locale_surrogateescape(format.decode('utf8'))
i = 1024
while True:
outbuf = lltype.malloc(rffi.CCHARP.TO, i, flavor='raw')
@@ -881,7 +884,8 @@
# e.g. an empty format, or %Z when the timezone
# is unknown.
result = rffi.charp2strn(outbuf, intmask(buflen))
- return space.newtext(result)
+ decoded, size = str_decode_locale_surrogateescape(result)
+ return space.newutf8(decoded, size)
finally:
lltype.free(outbuf, flavor='raw')
i += i
More information about the pypy-commit
mailing list