Ticket #13299: Handle-timezone-files-with-no-modern-transitions-as-well_fixes_29.patch

File Handle-timezone-files-with-no-modern-transitions-as-well_fixes_29.patch, 3.0 KB (added by rcrdnalor, 5 months ago)

Full pach, containing the '0001-python-Handle-massively-negative-initial-zoneinfo-en.patch' and my additions.

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

    diff --git a/mythtv/bindings/python/MythTV/utility/dt.py b/mythtv/bindings/python/MythTV/utility/dt.py
    index f688ea24c6..3f411406d7 100644
    a b class posixtzinfo( basetzinfo ): 
    158158                    1)
    159159            return
    160160
    161         transitions = []
    162         for i in range(counts.transitions): # read in epoch time data
     161        transitions = [None] * counts.transitions
     162        # First transition which is in range for gmtime. Some zoneinfo
     163        # files have massively negative leading entries for e.g. the
     164        # big bang which gmtime() cannot cope with.
     165        first_modern_transition = None
     166        i = 0   # assign i, in case the for-loop is not executed:
     167        for i in range(counts.transitions):  # read in epoch time data
    163168            t = unpack(ttmfmt, fd.read(calcsize(ttmfmt)))[0]
    164             tt = time.gmtime(t)
    165             transitions.append([t, tt, None, None, None, None])
     169
     170            try:
     171                tt = time.gmtime(t)
     172                transitions[i] = ([t, tt, None, None, None, None])
     173                if first_modern_transition is None:
     174                    first_modern_transition = i
     175            except ValueError as e:
     176                # ValueError is only accepted until we have seen a modern
     177                # transition.
     178                if first_modern_transition is not None:
     179                    raise e
     180
     181        # Special case if there are no modern transitions, like e.g. UTC timezone:
     182        if ( (i == 0) and first_modern_transition is None ):
     183            first_modern_transition = counts.transitions
    166184
    167185        # read in transition type indexes
    168186        types = [None]*counts.transitions
    class posixtzinfo( basetzinfo ): 
    177195        for i in range(counts.types):
    178196            offset, isdst, _ = unpack('!lbB', fd.read(6))
    179197            typedefs.append([offset, isdst])
    180         for i in range(counts.transitions):
    181             offset,isdst = typedefs[types[i]]
     198        for i in range(first_modern_transition, counts.transitions):
     199            offset, isdst = typedefs[types[i]]
    182200            transitions[i][2] = time.gmtime(transitions[i][0] + offset)
    183201            transitions[i][3] = offset
    184202            transitions[i][5] = isdst
    185203
    186204        # read in type names
    187205        for i, name in enumerate(fd.read(counts.abbrevs)[:-1].split('\0')):
    188             for j in range(counts.transitions):
     206            for j in range(first_modern_transition, counts.transitions):
    189207                if types[j] == i:
    190208                    transitions[j][4] = name
    191209
    class posixtzinfo( basetzinfo ): 
    196214        # skip utc/local indicators
    197215        fd.seek(counts.gmt_indicators, 1)
    198216
    199         for i in range(counts.transitions):
    200             transitions[i] = self._Transition(*transitions[i])
     217        transitions = [self._Transition(*x)
     218                       for x
     219                       in transitions[first_modern_transition:]]
    201220        self._transitions = tuple(transitions)
    202221
    203222