errors.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # @Base: Miro - an RSS based video player application
  2. # Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
  3. # Participatory Culture Foundation
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. # In addition, as a special exception, the copyright holders give
  20. # permission to link the code of portions of this program with the OpenSSL
  21. # library.
  22. #
  23. # You must obey the GNU General Public License in all respects for all of
  24. # the code used other than OpenSSL. If you modify file(s) with this
  25. # exception, you may extend this exception to your version of the file(s),
  26. # but you are not obligated to do so. If you do not wish to do so, delete
  27. # this exception statement from your version. If you delete this exception
  28. # statement from all source files in the program, then also delete it here.
  29. """``lvc.errors`` -- lvc exceptions.
  30. """
  31. class ActionUnavailableError(ValueError):
  32. """The action attempted can not be done in the current state."""
  33. def __init__(self, reason):
  34. self.reason = reason
  35. class WidgetActionError(ActionUnavailableError):
  36. """The widget is not in the right state to perform the requested action.
  37. This usually is not serious, but if not handled the UI will likely be in an
  38. incorrect state.
  39. """
  40. class WidgetDomainError(WidgetActionError):
  41. """The widget element requested is not available at this time. This may be a
  42. temporary condition or a result of permanent changes.
  43. """
  44. def __init__(self, domain, needle, haystack, details=None):
  45. self.domain = domain
  46. self.needle = needle
  47. self.haystack = haystack
  48. self.details = details
  49. @property
  50. def reason(self):
  51. reason = "looked for {0} in {2}, but found only {1}".format(
  52. repr(self.needle), repr(self.haystack), self.domain)
  53. if self.details:
  54. reason += ": " + self.details
  55. return reason
  56. class WidgetRangeError(WidgetDomainError):
  57. """Class to handle neat display of ranges in WidgetDomainErrors. Handlers
  58. should generally catch a parent of this.
  59. """
  60. def __init__(self, domain, needle, start_range, end_range, details=None):
  61. haystack = "{0} to {1}".format(repr(start_range), repr(end_range))
  62. WidgetDomainError.__init__(self, domain, needle, haystack, details)
  63. class WidgetNotReadyError(WidgetActionError):
  64. """The widget is not ready to perfom the action given; this must be a
  65. temporary condition that will be resolved when the widget finishes setting
  66. up.
  67. """
  68. def __init__(self, waiting_for):
  69. self.waiting_for = waiting_for
  70. @property
  71. def reason(self):
  72. return "waiting for {0}".format(self.waiting_for)
  73. class UnexpectedWidgetError(ActionUnavailableError):
  74. """The Spanish Inquisition of widget errors. A widget was asked to do
  75. something, had every reason to do so, yet refused. This should always cause
  76. at least a soft_failure; the UI is now in an incorrect state.
  77. """
  78. class WidgetUsageError(UnexpectedWidgetError):
  79. """A widget error that is likely the result of incorrect widget usage."""