Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_common.py 932B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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