1 def enum(*sequential, **named):
2 enums = dict(zip(sequential, range(len(sequential))), **named)
3 return type('Enum', (), enums)
12 # being a dict this can be used with json.dumps
13 class ManifoldResult (dict):
14 def __init__ (self, code=ManifoldCode.SUCCESS, value=None, output=""):
18 self['description'] = '' # Jordan: needed by javascript code
20 def from_json (self, json_string):
21 d=json.dumps(json_string)
22 for k in ['code','value','output']:
26 def code (self): return self['code']
27 def output (self): return self['output']
29 # this returns None if there's a problem, the value otherwise
31 if self['code']==ManifoldCode.SUCCESS:
34 # both data in a single string
36 return "code=%s -- %s"%(self['code'],self['output'])
40 result="[[MFresult code=%s"%self['code']
43 if isinstance(value,list): result += " [value=list with %d elts]"%len(value)
44 elif isinstance(value,dict): result += " [value=dict with keys %s]"%value.keys()
45 else: result += " [value=%s: %s]"%(type(value).__name__,value)
47 result += " [output=%s]"%self['output']
51 # probably simpler to use a single class and transport the whole result there
52 # instead of a clumsy set of derived classes
53 class ManifoldException (Exception):
54 def __init__ (self, manifold_result):
55 self.manifold_result=manifold_result
57 return "Manifold Exception %s"%(self.manifold_result.error())