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: datetime violates Postel's law
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: gkuenning, r.david.murray
Priority: normal Keywords:

Created on 2017-10-24 22:56 by gkuenning, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg304944 - (view) Author: Geoff Kuenning (gkuenning) Date: 2017-10-24 22:56
The datetime package is too eager to reject nonconforming VCALENDAR-format files.  The particular issue I encountered is related to time zones.  RFC 5545 clearly states that the DTSTART field is required.  However, there are situations where DTSTART isn't strictly necessary because the zone in question doesn't observe daylight-savings time and never has.

For example, I have a VCALENDAR file that was generated by a program that omits DTSTART for such zones.  Here's an example:

BEGIN:VTIMEZONE
TZID:America/Phoenix
X-LIC-LOCATION:America/Phoenix
BEGIN:DAYLIGHT
TZOFFSETFROM:-0700
TZOFFSETTO:-0700
TZNAME:Ariz
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
TZOFFSETTO:-0700
TZNAME:Ariz
END:STANDARD
END:VTIMEZONE

Clearly, this file violates RFC 5445, and I have reported that fact to the program's maintainer (who will fix the problem soon).  Nevertheless, feeding an ICS file to datetime._parse_rfc with this error causes a ValueError exception, which makes the VCALENDAR file unreadable.

In keeping with Postel's law ("Be conservative in what you do, be liberal in what you accept from others"), _parse_rfc should attempt to accept VCALENDAR files whenever it is possible to make sense of them.  Thus, for example:

    if not founddtstart:
        rrulelines.append('DTSTART:19000101T020000')

The above could be improved a bit, for example by still rejecting entries in which the standard and daylight sections had different offsets (although even then it seems valid to assume a DTSTART in the distant past).

Although the dtstart issue is the one that prompted this report, I also noticed the following in _parse_rfc:

    if name == "BEGIN":
        if value in ("STANDARD", "DAYLIGHT"):
            # Process component
            pass
        else:
            raise ValueError("unknown component: "+value)

Again, there's an opportunity to be more robust here.  One could issue a warning message, but then ignore the unknown component.

In both cases (and I suspect numerous others), halting parsing is an extreme response to various errors, since it leaves the user of the package with no way to process a nonconforming file.  That's especially problematic since VCALENDAR files are generated by so many different programs, many of which are written by programmers who haven't bothered to read RFC 5445--or who have read it but then made some minor mistake that produces broken files.
msg304945 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-10-24 23:03
The python standard library does not parse files, nor does it have a _parse_rfc message. You say you reported the problem you are having to "the program's maintainer", and that is appropriate.  There does not appear to be anything in this report related to the python standard library, which is what would be appropriate for this bug tracker.
msg304946 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-10-24 23:04
I meant the python standard library datetime package doesn't parse files, of course :)  Other parts of the stdlib certainly do parse files.
msg304947 - (view) Author: Geoff Kuenning (gkuenning) Date: 2017-10-24 23:22
Duh, my mistake.  The problem is in dateutil, which AFAICT is indeed not part of the Python standard library.  I'll hang my head in shame and go report the problem in the right place.
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 76045
2017-10-24 23:23:34ned.deilysetstatus: open -> closed
resolution: third party
2017-10-24 23:22:53gkuenningsetstatus: closed -> open
resolution: third party -> (no value)
messages: + msg304947
2017-10-24 23:04:02r.david.murraysetmessages: + msg304946
2017-10-24 23:03:05r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg304945

resolution: third party
stage: resolved
2017-10-24 22:57:01gkuenningsettype: behavior
components: + Library (Lib)
versions: + Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
2017-10-24 22:56:14gkuenningcreate