exceptions.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ##############################################################################
  2. #
  3. # Copyright (c) 2002 Zope Foundation and Contributors.
  4. # All Rights Reserved.
  5. #
  6. # This software is subject to the provisions of the Zope Public License,
  7. # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
  8. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  9. # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10. # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  11. # FOR A PARTICULAR PURPOSE.
  12. #
  13. ##############################################################################
  14. """Interface-specific exceptions
  15. """
  16. class Invalid(Exception):
  17. """A specification is violated
  18. """
  19. class DoesNotImplement(Invalid):
  20. """ This object does not implement """
  21. def __init__(self, interface):
  22. self.interface = interface
  23. def __str__(self):
  24. return """An object does not implement interface %(interface)s
  25. """ % self.__dict__
  26. class BrokenImplementation(Invalid):
  27. """An attribute is not completely implemented.
  28. """
  29. def __init__(self, interface, name):
  30. self.interface=interface
  31. self.name=name
  32. def __str__(self):
  33. return """An object has failed to implement interface %(interface)s
  34. The %(name)s attribute was not provided.
  35. """ % self.__dict__
  36. class BrokenMethodImplementation(Invalid):
  37. """An method is not completely implemented.
  38. """
  39. def __init__(self, method, mess):
  40. self.method=method
  41. self.mess=mess
  42. def __str__(self):
  43. return """The implementation of %(method)s violates its contract
  44. because %(mess)s.
  45. """ % self.__dict__
  46. class InvalidInterface(Exception):
  47. """The interface has invalid contents
  48. """
  49. class BadImplements(TypeError):
  50. """An implementation assertion is invalid
  51. because it doesn't contain an interface or a sequence of valid
  52. implementation assertions.
  53. """