exceptions.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. '''
  2. Custom exceptions raised by pytz.
  3. '''
  4. __all__ = [
  5. 'UnknownTimeZoneError', 'InvalidTimeError', 'AmbiguousTimeError',
  6. 'NonExistentTimeError',
  7. ]
  8. class Error(Exception):
  9. '''Base class for all exceptions raised by the pytz library'''
  10. class UnknownTimeZoneError(KeyError, Error):
  11. '''Exception raised when pytz is passed an unknown timezone.
  12. >>> isinstance(UnknownTimeZoneError(), LookupError)
  13. True
  14. This class is actually a subclass of KeyError to provide backwards
  15. compatibility with code relying on the undocumented behavior of earlier
  16. pytz releases.
  17. >>> isinstance(UnknownTimeZoneError(), KeyError)
  18. True
  19. And also a subclass of pytz.exceptions.Error, as are other pytz
  20. exceptions.
  21. >>> isinstance(UnknownTimeZoneError(), Error)
  22. True
  23. '''
  24. pass
  25. class InvalidTimeError(Error):
  26. '''Base class for invalid time exceptions.'''
  27. class AmbiguousTimeError(InvalidTimeError):
  28. '''Exception raised when attempting to create an ambiguous wallclock time.
  29. At the end of a DST transition period, a particular wallclock time will
  30. occur twice (once before the clocks are set back, once after). Both
  31. possibilities may be correct, unless further information is supplied.
  32. See DstTzInfo.normalize() for more info
  33. '''
  34. class NonExistentTimeError(InvalidTimeError):
  35. '''Exception raised when attempting to create a wallclock time that
  36. cannot exist.
  37. At the start of a DST transition period, the wallclock time jumps forward.
  38. The instants jumped over never occur.
  39. '''