Issue 9864: email.utils.{parsedate,parsedate_tz} should have better return types
Created on 2010-09-15 19:05 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue9864.patch | jfinkels, 2010-09-21 03:42 | Computes missing values in email.utils.parsedate_tz | ||
| issue9864.datetime.patch | jfinkels, 2010-09-28 00:36 | email.utils.parsedate() returns datetime.datetime object. | ||
| Messages (15) | |||
|---|---|---|---|
| msg116473 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-09-15 19:05 | |
They both return raw tuples, which are not very intuitive to interpret:
>>> email.utils.parsedate_tz("Wed, 15 Sep 2010 09:53:50 -0700 (PDT)")
(2010, 9, 15, 9, 53, 50, 0, 1, -1, -25200)
It would be much better if they returned some kind of namedtuple, which would preserve backwards compatibility but with much better readability and usability.
Note that parsedate() could also return the existing time.struct_time type (which is compatible with a 9-tuple):
http://docs.python.org/library/time.html#time.struct_time
|
|||
| msg116474 - (view) | Author: Barry A. Warsaw (barry) * ![]() |
Date: 2010-09-15 19:09 | |
+1 |
|||
| msg116475 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-09-15 19:09 | |
By the way, while as mentioned in the docs “indexes 6, 7, and 8 of the result tuple are not usable”, perhaps it would be time to fix it? (at least for 6 and 7, aka. wday and yday) |
|||
| msg117026 - (view) | Author: Jeffrey Finkelstein (jfinkels) * | Date: 2010-09-21 03:42 | |
If the changes I propose in issue9909 are implemented (briefly: a calendar.dayofyear() function), the following patch (with documentation and tests) should fill in the missing fields in the returned tuple. Note that the email._parseaddr module now depends on the calendar module. |
|||
| msg117027 - (view) | Author: Jeffrey Finkelstein (jfinkels) * | Date: 2010-09-21 03:44 | |
I was not clear: the patch I provided REQUIRES the function I provided in issue9909. But I don't know how to change the "Dependencies" field in Roundup. |
|||
| msg117056 - (view) | Author: Alexander Belopolsky (belopolsky) * ![]() |
Date: 2010-09-21 14:55 | |
I've added #9909 as a dependency, but IMO it is less likely to be accepted than this feature request. On this issue, I would much rather see email package to start using datetime objects to represent time rather than named or unnamed tuples. |
|||
| msg117060 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-09-21 15:04 | |
> On this issue, I would much rather see email package to start using > datetime objects to represent time rather than named or unnamed tuples. I agree on the principle, but I don't know if it's acceptable with regards to compatibility. It's up to David and Barry to decide. |
|||
| msg117063 - (view) | Author: Barry A. Warsaw (barry) * ![]() |
Date: 2010-09-21 15:16 | |
It does make sense, and email6 is like Python 3 in the sense that backward compatibility is not a priority. |
|||
| msg117124 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2010-09-22 01:47 | |
Yes, email6 should make use of datetime objects. For email5 Antoine's proposal is better, but the question is will it happen before 3.2 beta :) |
|||
| msg117162 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2010-09-23 02:26 | |
I'm assigning this to myself because I'm assigned on all email issues, but that shouldn't prevent someone from working on a patch implementing Antoine's suggestion. |
|||
| msg117165 - (view) | Author: Jeffrey Finkelstein (jfinkels) * | Date: 2010-09-23 03:45 | |
Where does "email6" live? |
|||
| msg117328 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2010-09-24 19:58 | |
http://launchpad.net/python-email6 |
|||
| msg117496 - (view) | Author: Jeffrey Finkelstein (jfinkels) * | Date: 2010-09-28 00:36 | |
Here's a patch for the python-email6 branch. It seemed to make sense to remove parsedate_tz() and mktime_tz() here, since the parsedate() function now returns a datetime object, including timezone information (if it was parsed from the input string). Also required updating several tests to work with the new return type, and removing a test that checked if the returned value of parsedate() (a time tuple) was "acceptable" for use with functions from the time module. |
|||
| msg117555 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2010-09-28 21:56 | |
Thanks, Jeffrey. I've applied your patch (with minor doc tweaks) to the email6 branch. |
|||
| msg161645 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2012-05-26 03:37 | |
We ended up deciding to keep backward compatibility and add datetime support as a new API. All of these changes are now checked in to default. (See issue 665194, as well as issue 12586.) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:06 | admin | set | github: 54073 |
| 2012-05-26 03:37:38 | r.david.murray | set | status: open -> closed superseder: datetime-RFC2822 roundtripping messages: + msg161645 resolution: duplicate |
| 2010-12-27 17:42:10 | r.david.murray | set | nosy:
barry, belopolsky, pitrou, eric.araujo, r.david.murray, jfinkels versions: + Python 3.3, - Python 3.2 |
| 2010-09-28 21:56:26 | r.david.murray | set | messages: + msg117555 |
| 2010-09-28 00:36:51 | jfinkels | set | files:
+ issue9864.datetime.patch messages: + msg117496 |
| 2010-09-24 19:58:38 | r.david.murray | set | messages: + msg117328 |
| 2010-09-23 03:45:38 | jfinkels | set | messages: + msg117165 |
| 2010-09-23 02:26:29 | r.david.murray | set | assignee: r.david.murray |
| 2010-09-23 02:26:07 | r.david.murray | set | messages: + msg117162 |
| 2010-09-22 01:47:39 | r.david.murray | set | messages: + msg117124 |
| 2010-09-21 15:16:31 | barry | set | messages: + msg117063 |
| 2010-09-21 15:04:47 | pitrou | set | messages: + msg117060 |
| 2010-09-21 14:55:24 | belopolsky | set | nosy:
+ belopolsky dependencies: + request for calendar.dayofyear() function messages: + msg117056 |
| 2010-09-21 03:44:05 | jfinkels | set | messages: + msg117027 |
| 2010-09-21 03:42:02 | jfinkels | set | files:
+ issue9864.patch nosy:
+ jfinkels keywords: + patch |
| 2010-09-20 22:55:55 | eric.araujo | set | nosy:
+ eric.araujo |
| 2010-09-15 19:09:57 | pitrou | set | messages: + msg116475 |
| 2010-09-15 19:09:36 | barry | set | messages: + msg116474 |
| 2010-09-15 19:05:23 | pitrou | create | |
