_common.py 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. Common code used in multiple modules.
  3. """
  4. class weekday(object):
  5. __slots__ = ["weekday", "n"]
  6. def __init__(self, weekday, n=None):
  7. self.weekday = weekday
  8. self.n = n
  9. def __call__(self, n):
  10. if n == self.n:
  11. return self
  12. else:
  13. return self.__class__(self.weekday, n)
  14. def __eq__(self, other):
  15. try:
  16. if self.weekday != other.weekday or self.n != other.n:
  17. return False
  18. except AttributeError:
  19. return False
  20. return True
  21. def __hash__(self):
  22. return hash((
  23. self.weekday,
  24. self.n,
  25. ))
  26. def __ne__(self, other):
  27. return not (self == other)
  28. def __repr__(self):
  29. s = ("MO", "TU", "WE", "TH", "FR", "SA", "SU")[self.weekday]
  30. if not self.n:
  31. return s
  32. else:
  33. return "%s(%+d)" % (s, self.n)
  34. # vim:ts=4:sw=4:et