This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients ezio.melotti
Date 2009-02-13.01:46:32
SpamBayes Score 7.378516e-10
Marked as misclassified No
Message-id <1234489595.64.0.741014433527.issue5239@psf.upfronthosting.co.za>
In-reply-to
Content
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'
History
Date User Action Args
2009-02-13 01:46:35ezio.melottisetrecipients: + ezio.melotti
2009-02-13 01:46:35ezio.melottisetmessageid: <1234489595.64.0.741014433527.issue5239@psf.upfronthosting.co.za>
2009-02-13 01:46:34ezio.melottilinkissue5239 messages
2009-02-13 01:46:33ezio.melotticreate