This file is indexed.

/usr/lib/python3/dist-packages/aniso8601/timezone.py is in python3-aniso8601 2.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-

# Copyright (c) 2016, Brandon Nielsen
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the BSD license.  See the LICENSE file for details.

import datetime

def parse_timezone(tzstr):
    #tzstr can be Z, ±hh:mm, ±hhmm, ±hh
    if len(tzstr) == 1 and tzstr == 'Z':
        #Z -> UTC
        return UTCOffset(name='UTC', minutes=0)
    elif len(tzstr) == 6:
        #±hh:mm
        tzhour = int(tzstr[1:3])
        tzminute = int(tzstr[4:6])
    elif len(tzstr) == 5:
        #±hhmm
        tzhour = int(tzstr[1:3])
        tzminute = int(tzstr[3:5])
    elif len(tzstr) == 3:
        #±hh
        tzhour = int(tzstr[1:3])
        tzminute = 0
    else:
        raise ValueError('String is not a valid ISO 8601 time offset.')

    if tzstr[0] == '+':
        return UTCOffset(name=tzstr, minutes=(tzhour * 60 + tzminute))
    elif tzhour == 0 and tzminute == 0:
        raise ValueError('Negative ISO 8601 time offset cannot be 0.')

    return UTCOffset(name=tzstr, minutes=-(tzhour * 60 + tzminute))

class UTCOffset(datetime.tzinfo):
    def __init__(self, name=None, minutes=None):
        #We build an offset in this manner since the
        #tzinfo class must have an init that can
        #"method that can be called with no arguments"
        self._name = name

        if minutes is not None:
            self._utcdelta = datetime.timedelta(minutes=minutes)
        else:
            self._utcdelta = None

    def __repr__(self):
        if self._utcdelta >= datetime.timedelta(hours=0):
            return '+{0} UTC'.format(self._utcdelta)

        #From the docs:
        #String representations of timedelta objects are normalized
        #similarly to their internal representation. This leads to
        #somewhat unusual results for negative timedeltas.

        #Clean this up for printing purposes
        correcteddays = abs(self._utcdelta.days + 1) #Negative deltas start at -1 day

        deltaseconds = (24 * 60 * 60) - self._utcdelta.seconds #Negative deltas have a positive seconds

        days, remainder = divmod(deltaseconds, 24 * 60 * 60) #(24 hours / day) * (60 minutes / hour) * (60 seconds / hour)
        hours, remainder = divmod(remainder, 1 * 60 * 60) #(1 hour) * (60 minutes / hour) * (60 seconds / hour)
        minutes, seconds = divmod(remainder, 1 * 60) #(1 minute) * (60 seconds / minute)

        #Add any remaining days to the correctedDays count
        correcteddays += days

        if correcteddays == 0:
            return '-{0}:{1:02}:{2:02} UTC'.format(hours, minutes, seconds)
        elif correcteddays == 1:
            return '-1 day, {0}:{1:02}:{2:02} UTC'.format(hours, minutes, seconds)

        return '-{0} days, {1}:{2:02}:{3:02} UTC'.format(correcteddays, hours, minutes, seconds)

    def utcoffset(self, dt):
        return self._utcdelta

    def tzname(self, dt):
        return self._name

    def dst(self, dt):
        #ISO 8601 specifies offsets should be different if DST is required,
        #instead of allowing for a DST to be specified
        # https://docs.python.org/2/library/datetime.html#datetime.tzinfo.dst
        return datetime.timedelta(0)