Issue 5236: time.strptime should reject bytes arguments on Py3
Issue5236
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 | tleeuwenburg@gmail.com, 2009-03-12 23:47 | |||
| strptime_patch_v2.txt | tleeuwenburg@gmail.com, 2009-03-17 22:05 | |||
| Messages (10) | |||
|---|---|---|---|
| msg81834 - (view) | Author: Ezio Melotti (ezio.melotti) * ![]() |
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 (tleeuwenburg@gmail.com) ![]() |
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 (tleeuwenburg@gmail.com) ![]() |
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 (tleeuwenburg@gmail.com) ![]() |
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) * ![]() |
Date: 2009-03-12 05:52 | |
If you want to work on it, Tennesse, then go for it! |
|||
| msg83506 - (view) | Author: Tennessee Leeuwenburg (tleeuwenburg@gmail.com) ![]() |
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) * ![]() |
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 (tleeuwenburg@gmail.com) ![]() |
Date: 2009-03-17 21:57 | |
Thanks for the comments all and sorry for the delay -- life! |
|||
| msg84643 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
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) * ![]() |
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:45 | admin | set | github: 49486 |
| 2009-03-30 21:31:25 | brett.cannon | set | status: open -> closed resolution: accepted messages: + msg84655 versions: - Python 3.0 |
| 2009-03-30 20:42:45 | brett.cannon | set | messages: + msg84643 |
| 2009-03-17 22:05:27 | tleeuwenburg@gmail.com | set | files: + strptime_patch_v2.txt |
| 2009-03-17 21:57:30 | tleeuwenburg@gmail.com | set | messages: + msg83702 |
| 2009-03-17 21:55:25 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg83701 |
| 2009-03-13 10:04:22 | tleeuwenburg@gmail.com | set | stage: test needed -> patch review |
| 2009-03-12 23:47:31 | tleeuwenburg@gmail.com | set | files:
+ strptime_patch.txt messages: + msg83506 |
| 2009-03-12 05:52:36 | brett.cannon | set | priority: normal messages:
+ msg83488 |
| 2009-03-12 03:41:42 | tleeuwenburg@gmail.com | set | messages: + msg83487 |
| 2009-03-12 01:33:33 | tleeuwenburg@gmail.com | set | messages: + msg83486 |
| 2009-03-12 01:23:43 | tleeuwenburg@gmail.com | set | nosy:
+ tleeuwenburg@gmail.com messages: + msg83485 components: + Extension Modules, - Library (Lib), Unicode |
| 2009-02-13 19:03:24 | brett.cannon | set | assignee: brett.cannon nosy: + brett.cannon stage: test needed |
| 2009-02-12 22:50:32 | ezio.melotti | create | |

