Changeset bfcf68 in git
- Timestamp:
- Jun 14, 2005, 2:22:52 PM (18 years ago)
- Branches:
- (u'spielwiese', 'f6c3dc58b0df4bd712574325fe76d0626174ad97')
- Children:
- 9b973c144b1c3a7ddd2df88833b75055fc1688ae
- Parents:
- bb3e2b01b8b571e1ce0e1df85bcb71fb0ccb8e9d
- Location:
- modules/openmathserver
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/openmathserver/context.py
rbb3e2b0 rbfcf68 43 43 return impl 44 44 except NotImplementedError: 45 print "not found"45 #TODO log this, report it 46 46 return oms 47 47 def evaluate(self,omobject): … … 61 61 return OMint(val) 62 62 def apply(self,func,args): 63 return func(self,*args) 63 try: 64 return func(self,*args) 65 except: 66 raise EvaluationFailedError 64 67 def XMLEncodeBody(self,body): 65 68 return self.XMLEncoder.encode(body) 66 def XMLEncode (self, obj):67 obj.XMLencode(self)69 def XMLEncodeObject(self, obj): 70 return obj.XMLencode(self) 68 71 class SimpleXMLEncoder(object): 69 72 def encode(self, string): -
modules/openmathserver/objects.py
rbb3e2b0 rbfcf68 95 95 children=self.children 96 96 if children: 97 body="".join([context.XML encode(c) for c in children])97 body="".join([context.XMLEncodeObject(c) for c in children]) 98 98 else: 99 99 body=self.body … … 131 131 return context.apply(efunc, eargs) 132 132 except EvaluationFailedError, NotImplementedError: 133 return self 133 return OMapplication(efunc, eargs) 134 #return self 134 135 else: 135 136 return OMapplication(efunc, eargs) 137 XMLtag="OMA" 138 def getChildren(self): 139 return [self.func]+self.args 140 def setChildren(self): 141 raise UnsupportedOperationError 136 142 class OMsymbol(OMobject): 137 143 def __init__(self,name,cd=None): … … 147 153 def evaluate(self,context): 148 154 return context.evaluateSymbol(self) 155 XMLtag="OMS" 156 def getXMLattributes(self): 157 return [XMLattribute("name", self.name),\ 158 XMLattribute("cdbase",self.cd.base),\ 159 XMLattribute("cd",self.cd.name)] 160 def setXMLattributes(self): 161 raise UnsupportedOperationError 149 162 class SimpleValue(OMobject): 150 163 def __init__(self,value): … … 172 185 return str(self.value) 173 186 def setBody(self, value): 174 raise OperationNotPossibleError187 raise UnsupportedOperationError 175 188 XMLtag="OMI" 176 189 class OMfloat(SimpleValue): … … 183 196 def __str__(self): 184 197 return "OMfloat("+repr(self.value)+")" 198 XMLtag="OMF" 199 def getXMLattributes(self): 200 return [XMLattribute("dec",str(self.value))] 185 201 186 202 if __name__=='__main__': -
modules/openmathserver/omexceptions.py
rbb3e2b0 rbfcf68 7 7 class PackagingFailedError(Exception): 8 8 pass 9 class OperationNotPossibleError(Exception):9 class UnsupportedOperationError(Exception): 10 10 pass -
modules/openmathserver/xmlencodetest.py
rbb3e2b0 rbfcf68 1 1 from objects import * 2 2 from context import * 3 import arith1 3 4 context=Context() 4 5 context.push({}) 5 6 i=OMint(22482489) 6 print i.body7 #print i.body 7 8 print i.XMLencode(context) 9 print context.XMLEncodeObject(i) 8 10 v=OMvar("x") 9 11 print v.XMLencode(context) 10 print v.XMLattributes 12 x=v 13 y=OMvar("y") 14 a=OMapplication(OMsymbol("plus",arith1.content),[x,y,i]) 15 print a.XMLencode(context) 16 print context.XMLEncodeObject(context.evaluate(a)) 17 a1=OMapplication(OMsymbol("plus",arith1.content),[OMint(1),OMint(2)]) 18 a2=OMapplication(OMsymbol("plus",arith1.content),[a1,OMint(2)]) 19 a3=OMapplication(OMsymbol("plus",arith1.content),[a2,x]) 20 context.addCDImplementation(arith1.implementation) 21 print "a3", context.XMLEncodeObject(context.evaluate(a3)) 22 print "a2", context.XMLEncodeObject(context.evaluate(a2)) 23 print "a1", context.XMLEncodeObject(context.evaluate(a1)) 24 25 f=OMfloat(1.23434) 26 print context.XMLEncodeObject(f) 27 #print v.XMLattributes 28
Note: See TracChangeset
for help on using the changeset viewer.