1 def enum(*sequential, **named):
2 enums = dict(zip(sequential, range(len(sequential))), **named)
3 return type('Enum', (), enums)
13 _messages_ = { -1 : "Unknown", 0: "OK", 1: "Session Expired", 2: "Not Implemented", 3: "Backend server unreachable"}
15 # being a dict this can be used with json.dumps
16 class ManifoldResult (dict):
17 def __init__ (self, code=ManifoldCode.SUCCESS, value=None, output=""):
21 self['description'] = '' # Jordan: needed by javascript code
23 def from_json (self, json_string):
24 d=json.dumps(json_string)
25 for k in ['code','value','output']:
29 def code (self): return self['code']
30 def output (self): return self['output']
32 # this returns None if there's a problem, the value otherwise
34 if self['code']==ManifoldCode.SUCCESS:
37 # both data in a single string
39 return "code=%s -- %s"%(self['code'],self['output'])
44 result="[[MFresult %s (code=%s)"%(_messages_.get(code,"???"),code)
47 if isinstance(value,list): result += " [value=list with %d elts]"%len(value)
48 elif isinstance(value,dict): result += " [value=dict with keys %s]"%value.keys()
49 else: result += " [value=%s: %s]"%(type(value).__name__,value)
51 result += " [output=%s]"%self['output']
55 # probably simpler to use a single class and transport the whole result there
56 # instead of a clumsy set of derived classes
57 class ManifoldException (Exception):
58 def __init__ (self, manifold_result):
59 self.manifold_result=manifold_result
61 return "Manifold Exception %s"%(self.manifold_result.error())