Ticket #13299: 0001-Python-Bindings-Fix-parsing-of-zoneinfo-files_V2.patch

File 0001-Python-Bindings-Fix-parsing-of-zoneinfo-files_V2.patch, 2.2 KB (added by rcrdnalor, 10 months ago)

0001-Python-Bindings-Fix-parsing-of-zoneinfo-files_V2.patch

  • mythtv/bindings/python/MythTV/utility/dt.py

    From 33cca514868a6e064567bb202336e73f28a4e81f Mon Sep 17 00:00:00 2001
    From: rcrdnalor <rcrernst@gmail.com>
    Date: Mon, 9 Jul 2018 21:29:35 +0200
    Subject: [PATCH] Python Bindings: Fix parsing of zoneinfo files
    
    ---
     mythtv/bindings/python/MythTV/utility/dt.py | 18 ++++++++++++++++--
     1 file changed, 16 insertions(+), 2 deletions(-)
    
    diff --git a/mythtv/bindings/python/MythTV/utility/dt.py b/mythtv/bindings/python/MythTV/utility/dt.py
    index f688ea24c6..a3a2866395 100644
    a b class posixtzinfo( basetzinfo ): 
    161161        transitions = []
    162162        for i in range(counts.transitions): # read in epoch time data
    163163            t = unpack(ttmfmt, fd.read(calcsize(ttmfmt)))[0]
    164             tt = time.gmtime(t)
     164            # accept only values that time.time() can handle,
     165            # otherwise, mark this transition as invalid:
     166            try:
     167                tt = time.gmtime(t)
     168            except ValueError:
     169                tt = None
    165170            transitions.append([t, tt, None, None, None, None])
    166171
    167172        # read in transition type indexes
    class posixtzinfo( basetzinfo ): 
    179184            typedefs.append([offset, isdst])
    180185        for i in range(counts.transitions):
    181186            offset,isdst = typedefs[types[i]]
    182             transitions[i][2] = time.gmtime(transitions[i][0] + offset)
     187            # accept only values that time.time() can handle,
     188            # otherwise, mark this transition as invalid:
     189            try:
     190                transitions[i][2] = time.gmtime(transitions[i][0] + offset)
     191            except ValueError:
     192                transitions[i][2] = None
    183193            transitions[i][3] = offset
    184194            transitions[i][5] = isdst
    185195
    class posixtzinfo( basetzinfo ): 
    198208
    199209        for i in range(counts.transitions):
    200210            transitions[i] = self._Transition(*transitions[i])
     211        # delete transitions which have been marked previously as invalid:
     212        for index, t in reversed(list(enumerate(transitions))):
     213            if (t[1] is None) or (t[2] is None):
     214                del transitions[index]
    201215        self._transitions = tuple(transitions)
    202216
    203217