command - is the command that raised the exception, expressed as a list of
paths (or subcommands).
"""
+ pass
- def __init__(self, command):
- r"""Initialize the Error object.
+class HandlerError(Error):
+ r"""
+ HandlerError(command) -> HandlerError instance :: Base handlers exception.
- See Error class documentation for more info.
- """
- self.command = command
+ All exceptions raised by the handlers should inherit from this one, so
+ dispatching errors could be separated from real programming errors (bugs).
+ """
+ pass
- def __str__(self):
- return 'Command not found: "%s"' % ' '.join(self.command)
class CommandNotFoundError(Error):
r"""
This exception is raised when the command received can't be dispatched
because there is no handlers to process it.
"""
- pass
+
+ def __init__(self, command):
+ r"""Initialize the Error object.
+
+ See Error class documentation for more info.
+ """
+ self.command = command
+
+ def __str__(self):
+ return 'Command not found: "%s"' % ' '.join(self.command)
def handler(f):
f._dispatcher_handler = True
if result is not None:
result = serializer.serialize(result)
response = u'OK '
+ except dispatcher.Error, e:
+ result = unicode(e) + u'\n'
+ response = u'ERROR '
except Exception, e:
- result = unicode(e)
+ import traceback
+ result = u'Internal server error'
+ traceback.print_exc() # TODO logging!
response = u'ERROR '
if result is None:
response += u'0'
except ImportError:
import pickle
-import seqtools
try:
- from dispatcher import handler
+ from seqtools import Sequence
except ImportError:
- def handler(f): return f # NOP for testing
+ # NOP for testing
+ class Sequence: pass
+try:
+ from dispatcher import handler, HandlerError
+except ImportError:
+ # NOP for testing
+ class HandlerError(RuntimeError): pass
+ def handler(f): return f
__ALL__ = ('DhcpHandler',)
template_dir = path.join(path.dirname(__file__), 'templates')
-class Error(RuntimeError):
+class Error(HandlerError):
r"""
Error(command) -> Error instance :: Base DhcpHandler exception class.
self.message = 'Parameter not found: "%s"' % paramname
-class Host(seqtools.Sequence):
+class Host(Sequence):
r"""Host(name, ip, mac) -> Host instance :: Class representing a host.
name - Host name, should be a fully qualified name, but no checks are done.