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: parsedate and Y2K
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: BreamoreBoy, ajaksu2, eric.araujo, jfinkels, l0nwlf, mnot, r.david.murray
Priority: normal Keywords: easy, patch

Created on 2005-05-03 04:37 by mnot, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue1194222fix.patch jfinkels, 2010-02-21 06:00 Patch which changes behavior of email.utils.parsedate_tz()
issue1194222fix-py3k.diff jfinkels, 2010-02-23 23:01 Patch which changes behavior of email.utils.parsedate_tz()
issue1194222-py3k.diff jfinkels, 2010-08-24 18:19 Patch which changes behavior of email.utils.parsedate_tz()
issue1194222-trunk.diff jfinkels, 2010-08-24 18:50 Patch which changes behavior of email.Utils.parsedate_tz()
issue1194222-py3k.diff jfinkels, 2010-08-24 21:26 Patch which changes behavior of email.utils.parsedate_tz()
issue1194222-trunk.diff jfinkels, 2010-08-24 21:27 Patch which changes behavior of email.Utils.parsedate_tz()
Messages (19)
msg25216 - (view) Author: Mark Nottingham (mnot) Date: 2005-05-03 04:37
rfc822.parsedate and email.Utils.parsedate don't take Y2K into 
account when parsing two-digit years, even though they're allowed by 
RFC822. Even though that spec has since been superseded, there 
are still systems generating dates in the old format, and RFC2616, 
which bases its dates on RFC822, still allows two-digit years.

For example,

>>> email.Utils.parsedate("Sun, 6 Nov 94 08:49:37 GMT")
(94, 11, 6, 8, 49, 37, 0, 0, 0)

Here's a trivial patch to behave as outlined in the time module (I don't 
test for time.accept2dyear because the input is outside the system's 
control, and RFC-specified); it's against 2.3, but should be easy to 
integrate into later versions.

125a126,130
>     if yy < 100:
>         if yy > 68:
>             yy = yy + 1900
>         else:
>             yy = yy + 2000
msg25217 - (view) Author: Mark Nottingham (mnot) Date: 2006-06-23 19:17
Logged In: YES 
user_id=21868

This bug is still present in the 2.5 library. Will it be fixed?
msg83125 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-04 15:21
Confirmed in trunk and py3k.
msg99647 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-02-21 06:00
Here's a patch which changes the behavior of email.utils.parsedate_tz() so that it always returns a four-digit year. I've also included some other simple changes to make some of the surrounding code a little bit clearer.

The code review can be found at http://codereview.appspot.com/216064.
msg99967 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-02-23 23:01
Oh, that previous patch was for the 2.7 branch.

Here's a patch for the py3k branch, and a codereview at http://codereview.appspot.com/217107 .
msg114496 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-21 14:27
I couldn't apply the py3k version of the patch which contains changed unit tests.  Would someone please review this patch.
msg114498 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-08-21 15:00
Sorry about that; the diff paths have the "a/" and "b/" prefixes. Patch with -p1 at the top-level directory:

  patch -p1 < issue1194222fix-py3k.diff
msg114499 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-21 15:04
-p1 is the default for patch, so it should work.

Is this a bug fix or a feature request? It’s unclear. If it’s a bug fix, please add 2.7 and 3.1 to versions.
msg114501 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-08-21 15:31
I suppose this is a bug fix because it changes the behavior of email.utils.parsedate_tz() to match the RFC standards.
msg114506 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-21 16:28
What I wrote on Rietveld:

I don’t know much about email, but the code itself looks good to me. The fact that you didn’t have to change any test but added one is reassuring (unless it reveals lack of coverage).

http://codereview.appspot.com/217107/diff/1/2#newcode1
Lib/email/_parseaddr.py:1: # Copyright (C) 2002-2007, 2010 Python Software Foundation
“2002-2010” would make more sense.

http://codereview.appspot.com/217107/diff/1/2#newcode24
Lib/email/_parseaddr.py:24: DOY_UNKNOWN = 1
Can you add a comment explaining what DOY means, unless it’s obvious for email specialists?
msg114765 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-24 02:07
Thanks for working on this.

I would prefer to have two patches: one that fixes the bug (and adds the unit tests) and a separate one for the cleanups (in a new issue).

I agree that the fact that it isn't complying with the RFC makes it a bug.  It seems unlikely that fixing this would break anyone's code, since if they are already working around the bug the return of a four digit year should cause their workaround code to be skipped.
msg114801 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-08-24 18:19
Attached a patch with just the y2k changes and new unit test, for the py3k branch.
msg114802 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-08-24 18:21
Attached a patch with just the y2k changes and new unit test, for the trunk branch.
msg114803 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-08-24 18:50
Added my copyright information to the patch for trunk.
msg114815 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-24 20:14
Adding a copyright notice for a patch is not something that we generally do (and your current mod is implicitly claiming the whole file, which doesn't seem right in any case).  My understanding is that US copyright law says you have the copyright whether there's a notice or not, so you don't have to worry about putting anything in there (even assuming such a small piece of code is copyrightable, which is debatable).  Signing the contributor agreement is enough to grant redistribution rights to the code, regardless, so really nothing needs to be added.
msg114833 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-08-24 21:26
Removed copyright additions from patch.
msg114834 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-08-24 21:27
Removed copyright additions from patch.
msg114860 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-25 00:48
Applied in r84310.  Leaving issue open pending backport.

Thanks, Jeffrey.
msg114876 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-25 02:01
Ported to 2.7 in r84311 and to 3.1 in r84312.
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 41941
2010-08-25 02:01:34r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg114876

stage: patch review -> resolved
2010-08-25 00:48:24r.david.murraysetmessages: + msg114860
2010-08-24 21:27:56jfinkelssetfiles: + issue1194222-trunk.diff

messages: + msg114834
2010-08-24 21:26:11jfinkelssetfiles: + issue1194222-py3k.diff

messages: + msg114833
2010-08-24 20:14:28r.david.murraysetmessages: + msg114815
2010-08-24 18:50:51jfinkelssetfiles: - issue1194222-trunk.diff
2010-08-24 18:50:39jfinkelssetfiles: + issue1194222-trunk.diff

messages: + msg114803
2010-08-24 18:21:10jfinkelssetfiles: + issue1194222-trunk.diff

messages: + msg114802
2010-08-24 18:19:37jfinkelssetfiles: + issue1194222-py3k.diff

messages: + msg114801
2010-08-24 02:07:11r.david.murraysettype: enhancement -> behavior
messages: + msg114765
2010-08-21 16:28:42eric.araujosetmessages: + msg114506
2010-08-21 15:31:53jfinkelssetmessages: + msg114501
versions: + Python 3.1, Python 2.7
2010-08-21 15:04:05eric.araujosetassignee: r.david.murray

messages: + msg114499
nosy: + eric.araujo, l0nwlf, r.david.murray
2010-08-21 15:00:41jfinkelssetmessages: + msg114498
2010-08-21 14:27:31BreamoreBoysetversions: + Python 3.2, - Python 3.1, Python 2.7
nosy: + BreamoreBoy

messages: + msg114496

stage: test needed -> patch review
2010-02-23 23:01:14jfinkelssetfiles: + issue1194222fix-py3k.diff

messages: + msg99967
2010-02-21 06:00:18jfinkelssetfiles: + issue1194222fix.patch
nosy: + jfinkels
messages: + msg99647

2009-03-04 15:21:36ajaksu2setversions: + Python 3.1, Python 2.7, - Python 2.5
nosy: + ajaksu2
messages: + msg83125
keywords: + patch, easy
type: enhancement
stage: test needed
2005-05-03 04:37:01mnotcreate