Changeset bfcf68 in git for modules


Ignore:
Timestamp:
Jun 14, 2005, 2:22:52 PM (19 years ago)
Author:
Michael Brickenstein <bricken@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '4188d308699580d975efd0f6cca8dcb41c396f70')
Children:
9b973c144b1c3a7ddd2df88833b75055fc1688ae
Parents:
bb3e2b01b8b571e1ce0e1df85bcb71fb0ccb8e9d
Message:
*bricken: can do this all day


git-svn-id: file:///usr/local/Singular/svn/trunk@8362 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
modules/openmathserver
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • modules/openmathserver/context.py

    rbb3e2b0 rbfcf68  
    4343            return impl
    4444        except NotImplementedError:
    45             print "not found"
     45            #TODO log this, report it
    4646            return oms
    4747    def evaluate(self,omobject):
     
    6161                return OMint(val)
    6262    def apply(self,func,args):
    63         return func(self,*args)
     63        try:
     64            return func(self,*args)
     65        except:
     66            raise EvaluationFailedError
    6467    def XMLEncodeBody(self,body):
    6568        return self.XMLEncoder.encode(body)
    66     def XMLEncode(self, obj):
    67         obj.XMLencode(self)
     69    def XMLEncodeObject(self, obj):
     70        return obj.XMLencode(self)
    6871class SimpleXMLEncoder(object):
    6972    def encode(self, string):
  • modules/openmathserver/objects.py

    rbb3e2b0 rbfcf68  
    9595        children=self.children
    9696        if children:
    97             body="".join([context.XMLencode(c) for c in children])
     97            body="".join([context.XMLEncodeObject(c) for c in children])
    9898        else:
    9999            body=self.body
     
    131131                return context.apply(efunc, eargs)
    132132            except EvaluationFailedError, NotImplementedError:
    133                 return self
     133                return OMapplication(efunc, eargs)
     134                #return self
    134135        else:
    135136            return OMapplication(efunc, eargs)
     137    XMLtag="OMA"
     138    def getChildren(self):
     139        return [self.func]+self.args
     140    def setChildren(self):
     141        raise UnsupportedOperationError
    136142class OMsymbol(OMobject):
    137143    def __init__(self,name,cd=None):
     
    147153    def evaluate(self,context):
    148154        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
    149162class SimpleValue(OMobject):
    150163    def __init__(self,value):
     
    172185        return str(self.value)
    173186    def setBody(self, value):
    174         raise OperationNotPossibleError
     187        raise UnsupportedOperationError
    175188    XMLtag="OMI"
    176189class OMfloat(SimpleValue):
     
    183196    def __str__(self):
    184197        return "OMfloat("+repr(self.value)+")"
     198    XMLtag="OMF"
     199    def getXMLattributes(self):
     200        return [XMLattribute("dec",str(self.value))]
    185201       
    186202if __name__=='__main__':
  • modules/openmathserver/omexceptions.py

    rbb3e2b0 rbfcf68  
    77class PackagingFailedError(Exception):
    88    pass
    9 class OperationNotPossibleError(Exception):
     9class UnsupportedOperationError(Exception):
    1010    pass
  • modules/openmathserver/xmlencodetest.py

    rbb3e2b0 rbfcf68  
    11from objects import *
    22from context import *
     3import arith1
    34context=Context()
    45context.push({})
    56i=OMint(22482489)
    6 print i.body
     7#print i.body
    78print i.XMLencode(context)
     9print context.XMLEncodeObject(i)
    810v=OMvar("x")
    911print v.XMLencode(context)
    10 print v.XMLattributes
     12x=v
     13y=OMvar("y")
     14a=OMapplication(OMsymbol("plus",arith1.content),[x,y,i])
     15print a.XMLencode(context)
     16print context.XMLEncodeObject(context.evaluate(a))
     17a1=OMapplication(OMsymbol("plus",arith1.content),[OMint(1),OMint(2)])
     18a2=OMapplication(OMsymbol("plus",arith1.content),[a1,OMint(2)])
     19a3=OMapplication(OMsymbol("plus",arith1.content),[a2,x])
     20context.addCDImplementation(arith1.implementation)
     21print "a3", context.XMLEncodeObject(context.evaluate(a3))
     22print "a2", context.XMLEncodeObject(context.evaluate(a2))
     23print "a1", context.XMLEncodeObject(context.evaluate(a1))
     24
     25f=OMfloat(1.23434)
     26print context.XMLEncodeObject(f)
     27#print v.XMLattributes
     28
Note: See TracChangeset for help on using the changeset viewer.