Changeset 01cd17f in git
- Timestamp:
- Jun 15, 2005, 1:52:50 PM (18 years ago)
- Branches:
- (u'spielwiese', 'f6c3dc58b0df4bd712574325fe76d0626174ad97')
- Children:
- aeb6d365075d1f830530abf950058c3afdc8f977
- Parents:
- 16678227fe277530e8904f607ce8e6128f93df2a
- Location:
- modules/openmathserver
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/openmathserver/objects.py
r1667822 r01cd17f 2 2 from exceptions import * 3 3 #from cd import * 4 class XML attribute(object):4 class XMLAttribute(object): 5 5 def __init__(self, name, value): 6 6 self.name=name … … 56 56 except AttributeError: 57 57 raise UnsupportedOperationError 58 def __getXML attributes(self):59 try: 60 return self.getXML attributes()61 except AttributeError: 62 try: 63 return self.__XML attributes58 def __getXMLAttributes(self): 59 try: 60 return self.getXMLAttributes() 61 except AttributeError: 62 try: 63 return self.__XMLAttributes 64 64 except AttributeError: 65 65 #do return None, cause if modifiying a new list, changes will not be saved 66 66 return [] 67 def __delXML attributes(self):68 try: 69 self.delXML attributes()67 def __delXMLAttributes(self): 68 try: 69 self.delXMLAttributes() 70 70 return 71 71 except AttributeError: 72 72 try: 73 del self.__XML attributes73 del self.__XMLAttributes 74 74 except AttributeError: 75 75 pass 76 def __setXML attributes(self,XMLattributes):77 try: 78 self.setBody(XML attributes)76 def __setXMLAttributes(self,XMLAttributes): 77 try: 78 self.setBody(XMLAttributes) 79 79 except AttributeError: 80 80 raise UnsupportedOperationError … … 83 83 body=property(__getBody,__setBody,__delBody,\ 84 84 "xml body,FIXME: at the moment only char data") 85 XML attributes=property(__getXMLattributes,__setXMLattributes,__delXMLattributes,\85 XMLAttributes=property(__getXMLAttributes,__setXMLAttributes,__delXMLAttributes,\ 86 86 "xml attributes") 87 87 def XMLencode(self, context): 88 88 89 attr=self.XML attributes89 attr=self.XMLAttributes 90 90 if attr: 91 91 attrstr=" "+" ".join([a.encode(context) for a in attr]) … … 117 117 return "OMV(" + self.name +")" 118 118 XMLtag="OMV" 119 def getXML attributes(self):120 return [XML attribute("name", self.name)]119 def getXMLAttributes(self): 120 return [XMLAttribute("name", self.name)] 121 121 122 class OM application(OMObjectBase):122 class OMApply(OMObjectBase): 123 123 def __init__(self, func, args): 124 super(OM application,self).__init__()124 super(OMApply,self).__init__() 125 125 self.func=func 126 126 self.args=args … … 132 132 return context.apply(efunc, eargs) 133 133 except EvaluationFailedError, NotImplementedError: 134 return OM application(efunc, eargs)134 return OMApply(efunc, eargs) 135 135 #return self 136 136 else: 137 return OM application(efunc, eargs)137 return OMApply(efunc, eargs) 138 138 XMLtag="OMA" 139 139 def getChildren(self): … … 159 159 return context.evaluateSymbol(self) 160 160 XMLtag="OMS" 161 def getXML attributes(self):162 return [XML attribute("name", self.name),\163 XML attribute("cdbase",self.cd.base),\164 XML attribute("cd",self.cd.name)]165 def setXML attributes(self):161 def getXMLAttributes(self): 162 return [XMLAttribute("name", self.name),\ 163 XMLAttribute("cdbase",self.cd.base),\ 164 XMLAttribute("cd",self.cd.name)] 165 def setXMLAttributes(self): 166 166 raise UnsupportedOperationError 167 167 class SimpleValue(OMObjectBase): … … 204 204 return "OMfloat("+repr(self.value)+")" 205 205 XMLtag="OMF" 206 def getXML attributes(self):207 return [XML attribute("dec",str(self.value))]206 def getXMLAttributes(self): 207 return [XMLAttribute("dec",str(self.value))] 208 208 class OMRef(OMObjectBase): 209 209 def __init__(self, ref): … … 233 233 firstArg=OMbinding(lambdasym,[OMVar("x"), OMVar("y")], OMVar("x")) 234 234 #print context.evaluate(firstArg) 235 application=OM application(firstArg, [x,y])236 print context.evaluate(application) 237 application=OM application(firstArg,[y,x])235 application=OMApply(firstArg, [x,y]) 236 print context.evaluate(application) 237 application=OMApply(firstArg,[y,x]) 238 238 print context.evaluate(application) 239 239 import arith1 240 240 context.addCDImplementation(arith1.implementation) 241 241 #print type(context.lookupImplementation(arith1.plussym)) 242 #application=OM application(arith1.plussym,[x])243 #application=OM application(arith1.plussym,[x,x])244 application=OM application(OMSymbol("plus",arith1.content),[x,x])242 #application=OMApply(arith1.plussym,[x]) 243 #application=OMApply(arith1.plussym,[x,x]) 244 application=OMApply(OMSymbol("plus",arith1.content),[x,x]) 245 245 246 246 print context.evaluate(application) 247 application=OM application(OMSymbol("plus",arith1.content),[x,x,x])247 application=OMApply(OMSymbol("plus",arith1.content),[x,x,x]) 248 248 249 249 print context.evaluate(application) -
modules/openmathserver/omxmlreader.py
r1667822 r01cd17f 51 51 name=node.getAttribute("name") #node.attributes["name"] 52 52 #print dir(name) 53 erg= OM var(name)53 erg= OMVar(name) 54 54 if (node.nodeName=="OMS"): 55 55 if node.hasAttribute("cdbase"): … … 67 67 else: 68 68 cd=OMcd(cdname,cdbase) 69 erg=OM symbol(name,cd)69 erg=OMSymbol(name,cd) 70 70 if (node.nodeName=="OMA"): 71 71 children=[self.buildFromNode(c) for c in node.childNodes] … … 82 82 if (node.nodeName=="OMR"): 83 83 if node.hasAttribute("xref"): 84 erg=OM ref(node.getAttribute("xref"))84 erg=OMRef(node.getAttribute("xref")) 85 85 self.refs.append(erg) 86 86 else: -
modules/openmathserver/xmlencodetest.py
r1667822 r01cd17f 8 8 print i.XMLencode(context) 9 9 print context.XMLEncodeObject(i) 10 v=OM var("x")10 v=OMVar("x") 11 11 print v.XMLencode(context) 12 12 x=v 13 y=OM var("y")14 a=OMapplication(OM symbol("plus",arith1.content),[x,y,i])13 y=OMVar("y") 14 a=OMapplication(OMSymbol("plus",arith1.content),[x,y,i]) 15 15 print a.XMLencode(context) 16 16 print context.XMLEncodeObject(context.evaluate(a)) 17 a1=OMapplication(OM symbol("plus",arith1.content),[OMint(1),OMint(2)])18 a2=OMapplication(OM symbol("plus",arith1.content),[a1,OMint(2)])19 a3=OMapplication(OM symbol("plus",arith1.content),[a2,x])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 20 context.addCDImplementation(arith1.implementation) 21 21 print "a3", context.XMLEncodeObject(context.evaluate(a3))
Note: See TracChangeset
for help on using the changeset viewer.