[issue41083] plistlib can't decode date from year 0

2020-06-23 Thread Michael Shields


Michael Shields  added the comment:

You're correct that there is no year 0, but as you see Apple does use 
-12-30T00:00:00Z in their plists. I did not set that in order 
to test plistlib; it's what I found on my system.

If it's a goal that plistlib be able to parse system-generated plists and 
round-trip them to an equivalent serialization -- and I think that should be a 
goal -- then using strings or None also won't work. Maybe there could be a 
plistlib.Datetime for dates which are outside what datetime can represent?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41083] plistlib can't decode date from year 0

2020-06-23 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

Year 0 does exist in ISO 8601 though, but that wouldn't help us here as year 0 
in that standard is year 1 BCE which is not representable in Python's datetime 
module.

I'm not sure what we can do about this. The best we could do with plistlib is 
probably to add an option to either set unrepresentable dates to None or 
represent those dates as strings.

A more comprehensive fix is to change datetime to be able to represent these 
dates, but that's a much larger change that likely requires a PEP.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41083] plistlib can't decode date from year 0

2020-06-23 Thread Christian Heimes


Christian Heimes  added the comment:

By the way most datetime libraries will give you incorrect values for dates 
before 1582, 1752, 1926, 1949 or any dates in that range depending on your 
country and the predominant religion of your country, county, state, or 
principality. Dates before 1970 are generally problematic unless the date 
format also references a calendar system.

It's ... messy.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41083] plistlib can't decode date from year 0

2020-06-23 Thread Christian Heimes


Christian Heimes  added the comment:

There is no year 0. It does not exist. The year after 1 BC is the year 1 AD.

--
nosy: +christian.heimes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41083] plistlib can't decode date from year 0

2020-06-22 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
components: +macOS
nosy: +ned.deily, ronaldoussoren

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41083] plistlib can't decode date from year 0

2020-06-22 Thread Michael Shields


New submission from Michael Shields :

On macOS 10.5.5:

/tmp $ defaults export com.apple.security.KCN -

http://www.apple.com/DTDs/PropertyList-1.0.dtd;>


absentCircleWithNoReason

applicationDate
-12-30T00:00:00Z
lastCircleStatus
-1
lastWritten
2019-10-15T17:23:33Z
pendingApplicationReminder
4001-01-01T00:00:00Z
pendingApplicationReminderInterval
86400


/tmp $ cat plist_date_reduction.py 
#!/usr/bin/env python3

import plistlib
import subprocess

if __name__ == "__main__":
plist = subprocess.check_output(["defaults", "export", 
"com.apple.security.KCN", "-"])
print(plistlib.loads(plist, fmt=plistlib.FMT_XML))
/tmp $ python3.8 plist_date_reduction.py 
Traceback (most recent call last):
  File "plist_date_reduction.py", line 8, in 
print(plistlib.loads(plist, fmt=plistlib.FMT_XML))
  File 
"/usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/lib/python3.8/plistlib.py",
 line 1000, in loads
return load(
  File 
"/usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/lib/python3.8/plistlib.py",
 line 992, in load
return p.parse(fp)
  File 
"/usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/lib/python3.8/plistlib.py",
 line 288, in parse
self.parser.ParseFile(fileobj)
  File 
"/private/tmp/python@3.8-20200527-50093-16hak5w/Python-3.8.3/Modules/pyexpat.c",
 line 461, in EndElement
  File 
"/usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/lib/python3.8/plistlib.py",
 line 300, in handle_end_element
handler()
  File 
"/usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/lib/python3.8/plistlib.py",
 line 376, in end_date
self.add_object(_date_from_string(self.get_data()))
  File 
"/usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/lib/python3.8/plistlib.py",
 line 254, in _date_from_string
return datetime.datetime(*lst)
ValueError: year 0 is out of range

--
components: Library (Lib)
messages: 372131
nosy: shields-fn
priority: normal
severity: normal
status: open
title: plistlib can't decode date from year 0
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com