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.

classification
Title: time.strptime should reject bytes arguments on Py3
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: amaury.forgeotdarc, brett.cannon, ezio.melotti, [email protected]
Priority: normal Keywords:

Created on 2009-02-12 22:50 by ezio.melotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
strptime_patch.txt [email protected], 2009-03-12 23:47
strptime_patch_v2.txt [email protected], 2009-03-17 22:05
Messages (10)
msg81834 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-02-12 22:50
On Python3 time.strptime(string[, format]) accepts bytes as arguments
and then fails:

>>> strptime(b"2009", "%Y")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Programs\Python30\lib\_strptime.py", line 454, in _strptime_time
    return _strptime(data_string, format)[0]
  File "C:\Programs\Python30\lib\_strptime.py", line 322, in _strptime
    found = format_regex.match(data_string)
TypeError: can't use a string pattern on a bytes-like object

time.strftime already rejects bytes arguments:
>>> strftime(b'%Y')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: strftime() argument 1 must be str, not bytes

time.strptime should do the same and reject bytes for both the arguments
(string and format).

(With Py2.x both str and unicode args work.)
msg83485 - (view) Author: Tennessee Leeuwenburg ([email protected]) (Python triager) Date: 2009-03-12 01:23
I believe this shouldn't be tagged as part of the Lib component...

Also, I am happy to work on this issue, developing tests and a patch.
Would that be appropriate? I may take a little while to get the hang of
things, but I'm happy to put some time into this.
msg83486 - (view) Author: Tennessee Leeuwenburg ([email protected]) (Python triager) Date: 2009-03-12 01:33
My mistake, it is part of the Lib component ... I failed to see the
callback to Python from timemodule.c and jumped to conclusions.

In any case, I'm happy to work on this.
msg83487 - (view) Author: Tennessee Leeuwenburg ([email protected]) (Python triager) Date: 2009-03-12 03:41
See also thread
http://mail.python.org/pipermail/python-dev/2009-March/087104.html
msg83488 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-03-12 05:52
If you want to work on it, Tennesse, then go for it!
msg83506 - (view) Author: Tennessee Leeuwenburg ([email protected]) (Python triager) Date: 2009-03-12 23:47
Python implementation to raise this exception if a bytes argument is
passed in as argument 1.

Test case added to test_time
msg83701 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-03-17 21:55
Please remove the whitespace changes in the patch 
(around "_cache_lock"). Otherwise it is good.
msg83702 - (view) Author: Tennessee Leeuwenburg ([email protected]) (Python triager) Date: 2009-03-17 21:57
Thanks for the comments all and sorry for the delay -- life!
msg84643 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-03-30 20:42
I am going to do a review at http://codereview.appspot.com/28147 ; not
done yet.
msg84655 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-03-30 21:31
Applied in r70755 for py3k. I am not backporting as I changed it to
explicitly check both arguments which is a change in semantics.
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49486
2009-03-30 21:31:25brett.cannonsetstatus: open -> closed
resolution: accepted
messages: + msg84655

versions: - Python 3.0
2009-03-30 20:42:45brett.cannonsetmessages: + msg84643
2009-03-17 22:05:27[email protected]setfiles: + strptime_patch_v2.txt
2009-03-17 21:57:30[email protected]setmessages: + msg83702
2009-03-17 21:55:25amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg83701
2009-03-13 10:04:22[email protected]setstage: test needed -> patch review
2009-03-12 23:47:31[email protected]setfiles: + strptime_patch.txt

messages: + msg83506
2009-03-12 05:52:36brett.cannonsetpriority: normal

messages: + msg83488
components: + Library (Lib), - Extension Modules
2009-03-12 03:41:42[email protected]setmessages: + msg83487
2009-03-12 01:33:33[email protected]setmessages: + msg83486
2009-03-12 01:23:43[email protected]setnosy: + [email protected]
messages: + msg83485
components: + Extension Modules, - Library (Lib), Unicode
2009-02-13 19:03:24brett.cannonsetassignee: brett.cannon
nosy: + brett.cannon
stage: test needed
2009-02-12 22:50:32ezio.melotticreate