permission.exceptions: 14 total statements, 46.2% covered

Generated: Thu 2012-03-01 14:22 CST

Source file: /home/alisue/Dropbox/Codes/django-permission/permission/exceptions.py

Stats: 6 executed, 7 missed, 1 excluded, 52 ignored

  1. # vim: set fileencoding=utf-8 :
  2. """
  3. Exceptions used in this app.
  4. Exception:
  5. ValidationError
  6. raise when the passed permission handler is not valid.
  7. PermissinDetectionError
  8. raise when the app could not detect the permission from string.
  9. AlreadyRegistered
  10. raise when the handler of model is already registered in registry.
  11. NotRegistered
  12. raise when the handler of model is not registered in registry.
  13. AUTHOR:
  14. lambdalisue[Ali su ae] (lambdalisue@hashnote.net)
  15. License:
  16. The MIT License (MIT)
  17. Copyright (c) 2012 Alisue allright reserved.
  18. Permission is hereby granted, free of charge, to any person obtaining a copy
  19. of this software and associated documentation files (the "Software"), to
  20. deal in the Software without restriction, including without limitation the
  21. rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  22. sell copies of the Software, and to permit persons to whom the Software is
  23. furnished to do so, subject to the following conditions:
  24. The above copyright notice and this permission notice shall be included in
  25. all copies or substantial portions of the Software.
  26. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  29. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  31. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  32. IN THE SOFTWARE.
  33. """
  34. from __future__ import with_statement
  35. class ValidationError(Exception):
  36. """Validation error"""
  37. class PermissionDetectionError(Exception):
  38. """Permission detection error"""
  39. class AlreadyRegistered(Exception):
  40. """PermissionHandler of the model is already registered error"""
  41. def __init__(self, model):
  42. msg = 'Permission handler of the model "%s.%s" is already registered'
  43. msg = msg % (model._meta.app_label, model.__class__.__name__)
  44. super(AlreadyRegistered, self).__init__(msg)
  45. class NotRegistered(Exception):
  46. """PermissionHandler of the model is not registered error"""
  47. def __init__(self, model):
  48. msg = 'Permission handler of the model "%s.%s" is not registered'
  49. msg = msg % (model._meta.app_label, model.__class__.__name__)
  50. super(NotRegistered, self).__init__(msg)