1
"""
2
Common code used in multiple modules.
3
"""
4

5

6 20
class weekday(object):
7 20
    __slots__ = ["weekday", "n"]
8

9 20
    def __init__(self, weekday, n=None):
10 20
        self.weekday = weekday
11 20
        self.n = n
12

13 20
    def __call__(self, n):
14 20
        if n == self.n:
15 20
            return self
16
        else:
17 20
            return self.__class__(self.weekday, n)
18

19 20
    def __eq__(self, other):
20 20
        try:
21 20
            if self.weekday != other.weekday or self.n != other.n:
22 20
                return False
23 20
        except AttributeError:
24 20
            return False
25 20
        return True
26

27 20
    def __hash__(self):
28 0
        return hash((
29
          self.weekday,
30
          self.n,
31
        ))
32

33 20
    def __ne__(self, other):
34 20
        return not (self == other)
35

36 20
    def __repr__(self):
37 20
        s = ("MO", "TU", "WE", "TH", "FR", "SA", "SU")[self.weekday]
38 20
        if not self.n:
39 20
            return s
40
        else:
41 20
            return "%s(%+d)" % (s, self.n)
42

43
# vim:ts=4:sw=4:et

Read our documentation on viewing source code .

Loading