[mythtv-commits] Ticket #13299: Python Bindings fail to calculate date-time object
MythTV
noreply at mythtv.org
Thu May 9 19:52:33 UTC 2019
#13299: Python Bindings fail to calculate date-time object
-------------------------------+--------------------------------
Reporter: rcrdnalor | Owner: Raymond Wagner
Type: Patch - Bug Fix | Status: new
Priority: minor | Milestone: needs_triage
Component: Bindings - Python | Version: Unspecified
Severity: medium | Resolution:
Keywords: | Ticket locked: 0
-------------------------------+--------------------------------
Comment (by rcrdnalor):
Replying to [comment:6 rcrdnalor]:
> I am fine with the patch "0001-python-Handle-massively-negative-initial-
zoneinfo-en.patch".
> I tested successfully all proposed patches with the timezone-info for
ubuntu (trusty, bionic) and debian (jessie, stretch, sid) in respect to
the time zomes 'Europe/Vienna' and 'Antartica/Macquarie'. The latter one
is known to be problematic in the mailing lists of 'iana.org/time-zones'.
>
Unfortunately, I spoke to soon:
With the applied patch '0001-python-Handle-massively-negative-initial-
zoneinfo-en.patch',
MythTV Python Bindings cannot load timezone files containing no
transitions or no modern transitions.
Those timezones are of type 'UTC' or 'GMT+x'.
On import of the 'datetime' module, MythTV python fails to create a
posixtzinfo for 'UTC'.
Procedure to show the error:
On fixes/30 or master, if you change the MythTV's Python Bindings utility
'datetime' to raise an error upon this, like in the following snippet:
{{{
file utility/datetime.py
@classmethod
def UTCTZ(cls):
try:
return posixtzinfo('Etc/UTC')
except:
raise
# return offsettzinfo()
}}}
You will get the traceback like this when you import datetime from MythTV:
{{{
$ python2
>>> from MythTV import datetime
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MythTV/__init__.py", line 41, in <module>
from .dataheap import *
File "MythTV/dataheap.py", line 20, in <module>
_default_datetime = datetime(1900,1,1, tzinfo=datetime.UTCTZ())
File "MythTV/utility/dt.py", line 290, in UTCTZ
return posixtzinfo('Etc/UTC')
File "MythTV/utility/singleton.py", line 49, in __call__
inst = type.__call__(cls, *args, **kwargs)
File "MythTV/utility/dt.py", line 230, in __init__
self._process(fd, version)
File "MythTV/utility/dt.py", line 193, in _process
for i in range(first_modern_transition, counts.transitions):
TypeError: range() integer start argument expected, got NoneType.
}}}
This can be verified by (without the code change):
{{{
$ python2
>>> from MythTV import datetime
>>>
>>> datetime.now()
datetime(2019, 5, 9, 19, 48, 55, 765719,
tzinfo=<MythTV.utility.dt.posixtzinfo object at 0x7fa41d8a4150>)
>>>
>>> datetime.utcnow()
datetime(2019, 5, 9, 17, 49, 8, 21672,
tzinfo=<MythTV.utility.dt.offsettzinfo object at 0x7fa4251970d0>)
}}}
Note the 'posixtzinfo' reference for local time-zone and the
'offsettzinfo' reference to the UTC time-zone.
This shows, that the Python Bindings do not load the posix zonefile for
'UTC' in a correct way.
Expected output is (with applied additional patches attached to this
ticket):
{{{
$ python2
>>> from MythTV import datetime
>>>
>>> datetime.now()
datetime(2019, 5, 9, 19, 56, 16, 232801,
tzinfo=<MythTV.utility.dt.posixtzinfo object at 0x7febb282c150>)
>>>
>>> datetime.utcnow()
datetime(2019, 5, 9, 17, 56, 28, 960914,
tzinfo=<MythTV.utility.dt.posixtzinfo object at 0x7febb2812ad0>)
>>>
}}}
The attached patches handle the corner cases where the zone-info files
have no 'modern transitions' or no transitions at all.
This is valid for timezones of type 'UTC' or 'GMT+x'.
With these patches applied, I get the expected datetime object with
'posixtzinfo' as 'tzinfo' object.
Note: The 'offsettzinfo' object only provides a simple static offset to
the timezone. Therefore the 'posixtzinfo' method is the preferred method.
Attached patches for fixes/30 and master and for fixes/29.
--
Ticket URL: <https://code.mythtv.org/trac/ticket/13299#comment:14>
MythTV <http://www.mythtv.org>
MythTV Media Center
More information about the mythtv-commits
mailing list