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: email.utils.{parsedate,parsedate_tz} should have better return types
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: 9909 Superseder: datetime-RFC2822 roundtripping
View: 665194
Assigned To: r.david.murray Nosy List: barry, belopolsky, eric.araujo, jfinkels, pitrou, r.david.murray
Priority: normal Keywords: patch

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) * (Python committer) 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) * (Python committer) Date: 2010-09-15 19:09
+1
msg116475 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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:06adminsetgithub: 54073
2012-05-26 03:37:38r.david.murraysetstatus: open -> closed
superseder: datetime-RFC2822 roundtripping
messages: + msg161645

resolution: duplicate
stage: needs patch -> resolved
2010-12-27 17:42:10r.david.murraysetnosy: barry, belopolsky, pitrou, eric.araujo, r.david.murray, jfinkels
versions: + Python 3.3, - Python 3.2
2010-09-28 21:56:26r.david.murraysetmessages: + msg117555
2010-09-28 00:36:51jfinkelssetfiles: + issue9864.datetime.patch

messages: + msg117496
2010-09-24 19:58:38r.david.murraysetmessages: + msg117328
2010-09-23 03:45:38jfinkelssetmessages: + msg117165
2010-09-23 02:26:29r.david.murraysetassignee: r.david.murray
2010-09-23 02:26:07r.david.murraysetmessages: + msg117162
2010-09-22 01:47:39r.david.murraysetmessages: + msg117124
2010-09-21 15:16:31barrysetmessages: + msg117063
2010-09-21 15:04:47pitrousetmessages: + msg117060
2010-09-21 14:55:24belopolskysetnosy: + belopolsky
dependencies: + request for calendar.dayofyear() function
messages: + msg117056
2010-09-21 03:44:05jfinkelssetmessages: + msg117027
2010-09-21 03:42:02jfinkelssetfiles: + issue9864.patch

nosy: + jfinkels
messages: + msg117026

keywords: + patch
2010-09-20 22:55:55eric.araujosetnosy: + eric.araujo
2010-09-15 19:09:57pitrousetmessages: + msg116475
2010-09-15 19:09:36barrysetmessages: + msg116474
2010-09-15 19:05:23pitroucreate