Bug hunting and polishing
Change-Id: I0f05730dd4e01e926ab0c4870c27ed5754f3ccfd
This commit is contained in:
@ -45,6 +45,7 @@ from messages import *
|
||||
from errors import *
|
||||
from secop.lib.parsing import format_time
|
||||
|
||||
|
||||
class Dispatcher(object):
|
||||
|
||||
def __init__(self, logger, options):
|
||||
@ -205,7 +206,7 @@ class Dispatcher(object):
|
||||
|
||||
def get_descriptive_data(self):
|
||||
# XXX: be lazy and cache this?
|
||||
result = {'modules':{}}
|
||||
result = {'modules': {}}
|
||||
for modulename in self._export:
|
||||
module = self.get_module(modulename)
|
||||
# some of these need rework !
|
||||
@ -335,9 +336,9 @@ class Dispatcher(object):
|
||||
res = self._setParamValue(msg.module, 'target', msg.value)
|
||||
res.parameter = 'target'
|
||||
# self.broadcast_event(res)
|
||||
if conn in self._active_connections:
|
||||
return None # already send to myself
|
||||
return res # send reply to inactive conns
|
||||
# if conn in self._active_connections:
|
||||
# return None # already send to myself
|
||||
return res
|
||||
|
||||
def handle_Command(self, conn, msg):
|
||||
# notify all by sending CommandReply
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
from secop.protocol.encoding import MessageEncoder
|
||||
from secop.protocol.messages import *
|
||||
from secop.protocol.errors import ProtocollError
|
||||
from secop.protocol.errors import ProtocolError
|
||||
|
||||
import ast
|
||||
import re
|
||||
@ -389,7 +389,7 @@ class DemoEncoder_MZ(MessageEncoder):
|
||||
# errors
|
||||
ErrorReply: lambda msg: "",
|
||||
InternalError: lambda msg: "",
|
||||
ProtocollError: lambda msg: "",
|
||||
ProtocolError: lambda msg: "",
|
||||
CommandFailedError: lambda msg: "error CommandError %s:%s %s" % (msg.device, msg.param, msg.error),
|
||||
NoSuchCommandError: lambda msg: "error NoSuchCommand %s:%s" % (msg.device, msg.param, msg.error),
|
||||
NoSuchDeviceError: lambda msg: "error NoSuchModule %s" % msg.device,
|
||||
|
@ -28,7 +28,7 @@
|
||||
from secop.lib.parsing import format_time
|
||||
from secop.protocol.encoding import MessageEncoder
|
||||
from secop.protocol.messages import *
|
||||
from secop.protocol.errors import ProtocollError
|
||||
#from secop.protocol.errors import ProtocolError
|
||||
|
||||
import ast
|
||||
import re
|
||||
@ -71,7 +71,7 @@ HELPREQUEST = 'help' # literal
|
||||
HELPREPLY = 'helping' # +line number +json_text
|
||||
ERRORCLASSES = ['NoSuchDevice', 'NoSuchParameter', 'NoSuchCommand',
|
||||
'CommandFailed', 'ReadOnly', 'BadValue', 'CommunicationFailed',
|
||||
'IsBusy', 'IsError', 'SyntaxError', 'InternalError',
|
||||
'IsBusy', 'IsError', 'ProtocolError', 'InternalError',
|
||||
'CommandRunning', 'Disabled', ]
|
||||
# note: above strings need to be unique in the sense, that none is/or
|
||||
# starts with another
|
||||
@ -83,15 +83,18 @@ def encode_cmd_result(msgobj):
|
||||
q['t'] = format_time(q['t'])
|
||||
return msgobj.result, q
|
||||
|
||||
|
||||
def encode_value_data(vobj):
|
||||
q = vobj.qualifiers.copy()
|
||||
if 't' in q:
|
||||
q['t'] = format_time(q['t'])
|
||||
return vobj.value, q
|
||||
|
||||
|
||||
def encode_error_msg(emsg):
|
||||
# note: result is JSON-ified....
|
||||
return [emsg.origin, dict( (k,getattr(emsg, k)) for k in emsg.ARGS if k != 'origin')]
|
||||
return [emsg.origin, dict((k, getattr(emsg, k))
|
||||
for k in emsg.ARGS if k != 'origin')]
|
||||
|
||||
|
||||
class DemoEncoder(MessageEncoder):
|
||||
@ -163,6 +166,14 @@ class DemoEncoder(MessageEncoder):
|
||||
ENABLEEVENTSREQUEST, DISABLEEVENTSREQUEST)
|
||||
return '\n'.join('%s %d %s' % (HELPREPLY, i + 1, l.strip())
|
||||
for i, l in enumerate(text.split('\n')[:-1]))
|
||||
if isinstance(msg, HeartbeatRequest):
|
||||
if msg.nonce:
|
||||
return 'ping %s' % msg.nonce
|
||||
return 'ping'
|
||||
if isinstance(msg, HeartbeatReply):
|
||||
if msg.nonce:
|
||||
return 'pong %s' % msg.nonce
|
||||
return 'pong'
|
||||
for msgcls, parts in self.ENCODEMAP.items():
|
||||
if isinstance(msg, msgcls):
|
||||
# resolve lambdas
|
||||
@ -183,12 +194,12 @@ class DemoEncoder(MessageEncoder):
|
||||
return IdentifyReply(version_string=encoded)
|
||||
|
||||
return HelpMessage()
|
||||
return ErrorMessage(errorclass='SyntaxError',
|
||||
errorinfo='Regex did not match!',
|
||||
is_request=True)
|
||||
# return ErrorMessage(errorclass='Protocol',
|
||||
# errorinfo='Regex did not match!',
|
||||
# is_request=True)
|
||||
msgtype, msgspec, data = match.groups()
|
||||
if msgspec is None and data:
|
||||
return ErrorMessage(errorclass='InternalError',
|
||||
return ErrorMessage(errorclass='Internal',
|
||||
errorinfo='Regex matched json, but not spec!',
|
||||
is_request=True,
|
||||
origin=encoded)
|
||||
@ -206,10 +217,10 @@ class DemoEncoder(MessageEncoder):
|
||||
errorinfo=[repr(err), str(encoded)],
|
||||
origin=encoded)
|
||||
msg = self.DECODEMAP[msgtype](msgspec, data)
|
||||
msg.setvalue("origin",encoded)
|
||||
msg.setvalue("origin", encoded)
|
||||
return msg
|
||||
return ErrorMessage(
|
||||
errorclass='SyntaxError',
|
||||
errorclass='Protocol',
|
||||
errorinfo='%r: No Such Messagetype defined!' %
|
||||
encoded,
|
||||
is_request=True,
|
||||
|
@ -30,12 +30,26 @@ class SECOPError(RuntimeError):
|
||||
for k, v in kwds.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
def __repr__(self):
|
||||
args = ', '.join(map(repr, self.args))
|
||||
kwds = ', '.join(['%s=%r' % i for i in self.__dict__.items()])
|
||||
res = []
|
||||
if args:
|
||||
res.append(args)
|
||||
if kwds:
|
||||
res.append(kwds)
|
||||
return '%s(%s)' % (self.name, ', '.join(res))
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.__class__.__name__[:-len('Error')]
|
||||
|
||||
|
||||
class InternalError(SECOPError):
|
||||
pass
|
||||
|
||||
|
||||
class ProtocollError(SECOPError):
|
||||
class ProtocolError(SECOPError):
|
||||
pass
|
||||
|
||||
|
||||
@ -56,6 +70,10 @@ class ReadonlyError(SECOPError):
|
||||
pass
|
||||
|
||||
|
||||
class BadValueError(SECOPError):
|
||||
pass
|
||||
|
||||
|
||||
class CommandFailedError(SECOPError):
|
||||
pass
|
||||
|
||||
@ -64,6 +82,18 @@ class InvalidParamValueError(SECOPError):
|
||||
pass
|
||||
|
||||
|
||||
EXCEPTIONS = dict(
|
||||
Internal=InternalError,
|
||||
Protocol=ProtocolError,
|
||||
NoSuchModule=NoSuchModuleError,
|
||||
NoSuchParam=NoSuchParamError,
|
||||
NoSuchCommand=NoSuchCommandError,
|
||||
BadValue=BadValueError,
|
||||
Readonly=ReadonlyError,
|
||||
CommandFailed=CommandFailedError,
|
||||
InvalidParam=InvalidParamValueError,
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Minimal testing of errors....")
|
||||
|
||||
|
@ -69,11 +69,12 @@ class Value(object):
|
||||
devspec = '%s:%s()' % (devspec, self.command)
|
||||
return '%s:Value(%s)' % (devspec, ', '.join(
|
||||
[repr(self.value)] +
|
||||
['%s=%s' % (k, format_time(v) if k=="timestamp" else repr(v)) for k, v in self.qualifiers.items()]))
|
||||
['%s=%s' % (k, format_time(v) if k == "timestamp" else repr(v)) for k, v in self.qualifiers.items()]))
|
||||
|
||||
|
||||
class Request(Message):
|
||||
is_request = True
|
||||
|
||||
def get_reply(self):
|
||||
"""returns a Reply object prefilled with the attributes from this request."""
|
||||
m = Message()
|
||||
@ -93,12 +94,12 @@ class Request(Message):
|
||||
m.origin = self.origin
|
||||
for k in self.ARGS:
|
||||
m.setvalue(k, self.__dict__[k])
|
||||
m.setvalue("errorclass", errorclass[:-5]
|
||||
if errorclass.endswith('rror')
|
||||
else errorclass)
|
||||
m.setvalue("errorclass", errorclass[:-5]
|
||||
if errorclass.endswith('rror')
|
||||
else errorclass)
|
||||
m.setvalue("errorinfo", errorinfo)
|
||||
return m
|
||||
|
||||
|
||||
|
||||
class IdentifyRequest(Request):
|
||||
pass
|
||||
@ -190,6 +191,4 @@ class ErrorMessage(Message):
|
||||
|
||||
|
||||
class HelpMessage(Request):
|
||||
is_reply = True #!sic!
|
||||
|
||||
|
||||
is_reply = True # !sic!
|
||||
|
Reference in New Issue
Block a user