Message81847
On Py3 strptime("2009", "%Y") fails:
>>> strptime("2009", "%Y")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/local/lib/python3.0/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data '2009' does not match format '%Y'
but non-ascii numbers are supported elsewhere:
>>> int("2009")
2009
>>> re.match("^\d{4}$", "2009").group()
'2009'
The problem seems to be at the line 265 of _strptime.py:
return re_compile(self.pattern(format), IGNORECASE | ASCII)
The ASCII flag prevent the regex to work properly with '2009':
>>> re.match("^\d{4}$", "2009", re.ASCII)
>>>
I tried to remove the ASCII flag and it worked fine.
On Py2.x the problem is the same:
>>> strptime(u"2009", "%Y")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/_strptime.py", line 330, in strptime
(data_string, format))
ValueError>>>
>>> int(u"2009")
2009
>>> re.match("^\d{4}$", u"2009")
Here there's probably to add the re.UNICODE flag at the line 265 (untested):
return re_compile(self.pattern(format), IGNORECASE | UNICODE)
in order to make it work:
>>> re.match("^\d{4}$", u"2009", re.U).group()
u'\uff12\uff10\uff10\uff19' |
|
Date |
User |
Action |
Args |
2009-02-13 01:46:35 | ezio.melotti | set | recipients:
+ ezio.melotti |
2009-02-13 01:46:35 | ezio.melotti | set | messageid: <1234489595.64.0.741014433527.issue5239@psf.upfronthosting.co.za> |
2009-02-13 01:46:34 | ezio.melotti | link | issue5239 messages |
2009-02-13 01:46:33 | ezio.melotti | create | |
|