exception.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Copyright (C) 2009 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. """This module holds exception classes specific for bindctl"""
  16. class BindCtlException(Exception):
  17. """Abstract base class shared by all bindctl exceptions"""
  18. def __str__(self):
  19. return "Big tool has problem"
  20. # Begin define Format exception
  21. class CmdFormatError(BindCtlException):
  22. """Command is malformed"""
  23. def __str__(self):
  24. return "Command is malformed"
  25. class CmdModuleNameFormatError(CmdFormatError):
  26. """module name format error"""
  27. def __str__(self):
  28. return "Module name format error: the character of name can only be '0-9a-zA-Z_'"
  29. class CmdCommandNameFormatError(CmdFormatError):
  30. """command name format error"""
  31. def __init__(self, module):
  32. self.module = module
  33. def __str__(self):
  34. return "Command name format error: the character of name can only be '0-9a-zA-Z_'"
  35. class CmdMissCommandNameFormatError(CmdFormatError):
  36. """Module name isn't finished"""
  37. def __init__(self, module):
  38. self.module = module
  39. def __str__(self):
  40. return "command name is missed"
  41. class CmdParamFormatError(CmdFormatError):
  42. """Command is malformed which parameter isn't key value pair"""
  43. def __init__(self, module, command):
  44. self.module = module
  45. self.command = command
  46. def __str__(self):
  47. return "Parameter format error, it should be 'key = value'"
  48. # Begin define the exception for syntax
  49. class CmdSyntaxError(BindCtlException):
  50. """Command line has syntax error"""
  51. def __str__(self):
  52. return "Command line has syntax error"
  53. class CmdUnknownModuleSyntaxError(CmdSyntaxError):
  54. """Command is unknown"""
  55. def __init__(self, module):
  56. self.module = module
  57. def __str__(self):
  58. return str("Unknown module '%s'" % self.module)
  59. class CmdUnknownCmdSyntaxError(CmdSyntaxError):
  60. """Command is unknown"""
  61. def __init__(self, module, command):
  62. self.module = module
  63. self.command = command
  64. def __str__(self):
  65. return str("Unknown command '%s' to module '%s'" %
  66. (self.command, self.module))
  67. class CmdUnknownParamSyntaxError(CmdSyntaxError):
  68. """The parameter of command is unknown"""
  69. def __init__(self, module, command, param):
  70. self.module = module
  71. self.command = command
  72. self.param = param
  73. def __str__(self):
  74. return str("Unknown parameter '%s' to command '%s' of module '%s'" %
  75. (self.param, self.command, self.module))
  76. class CmdMissParamSyntaxError(CmdSyntaxError):
  77. """The parameter of one command is missed"""
  78. def __init__(self, module, command, param):
  79. self.module = module
  80. self.command = command
  81. self.param = param
  82. def __str__(self):
  83. return str("Parameter '%s' is missed for command '%s' of module '%s'" %
  84. (self.param, self.command, self.module))
  85. class FailToLogin(BindCtlException):
  86. def __str__(self):
  87. return "Fail to login to cmdctl"