Changeset 2dc9fea in git


Ignore:
Timestamp:
Jun 23, 2005, 5:15:36 PM (18 years ago)
Author:
Michael Brickenstein <bricken@…>
Branches:
(u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
Children:
62b33dbe01f95458b81ecda6e278190e3b66d9be
Parents:
a868907fc6dd9b59a0d27bd87056410c92a84223
Message:
*bricken: beautified


git-svn-id: file:///usr/local/Singular/svn/trunk@8387 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/openmathserver/objects.py

    ra86890 r2dc9fea  
    77class XMLAttribute(object):
    88    def __init__(self, name, value):
    9         self.name=name
    10         self.value=value
     9        self.name = name
     10        self.value = value
    1111    def encode(self, context):
    1212        return "".join([self.name,"=\"",self.value,"\""])
     
    3636            self.setChildren(children)
    3737        except AttributeError:
    38                 raise UnsupportedOperationError
     38            raise UnsupportedOperationError
    3939    def __getBody(self):
    4040        try:
     
    5858            self.setBody(body)
    5959        except AttributeError:
    60                 raise UnsupportedOperationError
     60            raise UnsupportedOperationError
    6161    def __getXMLAttributes(self):
    6262        try:
     
    8686    body=property(__getBody,__setBody,__delBody,\
    8787        "xml body,FIXME: at the moment only char data")
    88     XMLAttributes=property(__getXMLAttributes,__setXMLAttributes,__delXMLAttributes,\
     88    XMLAttributes=property(__getXMLAttributes,\
     89        __setXMLAttributes,__delXMLAttributes,\
    8990        "xml attributes")
    9091    def XMLEncode(self, context):
     
    9293        attr=self.XMLAttributes
    9394        if attr:
    94             attrstr=" "+" ".join([a.encode(context) for a in attr])
     95            attrstr = " "+" ".join([a.encode(context) for a in attr])
    9596        else:
    96             attrstr=""
    97         opening="".join(["<", self.XMLtag, attrstr,">"])
    98         children=self.children
     97            attrstr = ""
     98        opening = "".join(["<", self.XMLtag, attrstr,">"])
     99        children = self.children
    99100        if children:
    100             body="".join([context.XMLEncodeObject(c) for c in children])
     101            body = "".join([context.XMLEncodeObject(c) for c in children])
    101102        else:
    102             body=self.body
     103            body = self.body
    103104            if not body:
    104                 body=""
    105             assert body!=None
    106             body=context.XMLEncodeBody(body)
    107             assert body!=None
    108         closing="".join(["</"+self.XMLtag+">"])
     105                body = ""
     106            assert body != None
     107            body = context.XMLEncodeBody(body)
     108            assert body != None
     109        closing = "".join(["</"+self.XMLtag+">"])
    109110        return "".join([opening,body,closing])
    110111class OMObject(OMObjectBase):
    111112    def __init__(self, children):
    112         super(OMObject,self).__init__()
    113         self.children=children
     113        super(OMObject, self).__init__()
     114        self.children = children
    114115    def getChildren(self):
    115116        return self.__children
    116     def setChildren(self,children):
     117    def setChildren(self ,children):
    117118        self.__children=children
    118     XMLtag="OMOBJ"
     119    XMLtag = "OMOBJ"
    119120    def evaluate(self, context):
    120121        return OMObject([context.evaluate(c) for c in self.children])
    121122class OMVar(OMObjectBase):
    122123    def __init__(self,name):
    123         super(OMVar,self).__init__()
    124         self.name=name
    125     def evaluate(self,context):
     124        super(OMVar, self).__init__()
     125        self.name = name
     126    def evaluate(self, context):
    126127        try:
    127128            return context[self.name]
     
    130131    def __str__(self):
    131132        return "OMV(" + self.name +")"
    132     XMLtag="OMV"
     133    XMLtag = "OMV"
    133134    def getXMLAttributes(self):
    134135        return [XMLAttribute("name", self.name)]
     
    136137class OMApply(OMObjectBase):
    137138    def __init__(self, func, args):
    138         super(OMApply,self).__init__()
    139         self.func=func
    140         self.args=args
    141     def evaluate(self,context):
    142         efunc=context.evaluate(self.func)
    143         eargs=[context.evaluate(a) for a in self.args]
     139        super(OMApply, self).__init__()
     140        self.func = func
     141        self.args = args
     142    def evaluate(self, context):
     143        efunc = context.evaluate(self.func)
     144        eargs = [context.evaluate(a) for a in self.args]
    144145        if callable(efunc):
    145146            try:
     
    157158       
    158159class OMSymbol(OMObjectBase):
    159     def __init__(self,name,cd=None):
     160    def __init__(self,name,cd = None):
    160161        super(OMSymbol,self).__init__()
    161         self.cd=cd
    162         self.name=name
     162        self.cd = cd
     163        self.name = name
    163164    def __eq__(self, other):
    164165        try:
    165             return bool(other.name==self.name and self.cd==other.cd)
     166            return bool(other.name == self.name and self.cd == other.cd)
    166167        except:
    167168            return False
    168169    def __str__(self):
    169         return "OMS("+self.name+", "+self.cd.name + ")"
     170        return "OMS(" + self.name + ", " + self.cd.name + ")"
    170171    def __hash__(self):#
    171172        return hash((self.name,self.cd.__hash__()))
     
    175176    def getXMLAttributes(self):
    176177        return [XMLAttribute("name", self.name),\
    177                  XMLAttribute("cdbase",self.cd.base),\
    178                  XMLAttribute("cd",self.cd.name)]
     178                 XMLAttribute("cdbase", self.cd.base),\
     179                 XMLAttribute("cd", self.cd.name)]
    179180    def setXMLAttributes(self):
    180181        raise UnsupportedOperationError
    181182class SimpleValue(OMObjectBase):
    182     def __init__(self,value):
    183         super(SimpleValue,self).__init__()
     183    def __init__(self, value):
     184        super(SimpleValue, self).__init__()
    184185        if (isinstance(value, str)):
    185             value=self.parse(value)
    186         self.value=value
     186            value = self.parse(value)
     187        self.value = value
    187188    def evaluate(self, context):
    188189        return self
     
    195196    def __init__(self,value):
    196197        if not isinstance(value,int):
    197             value=self.parse(value)
     198            value = self.parse(value)
    198199        super(OMint,self).__init__(value)
    199200    def parse(self,value):
     
    209210    XMLtag="OMI"
    210211class OMfloat(SimpleValue):
    211     def __init__(self,value):
    212         super(OMfloat,self).__init__(value)
     212    def __init__(self, value):
     213        super(OMfloat, self).__init__(value)
    213214    def parse(self, value):
    214215        """FIXME: Not fully standard compliant,
     
    217218    def __str__(self):
    218219        return "OMfloat("+repr(self.value)+")"
    219     XMLtag="OMF"
     220    XMLtag = "OMF"
    220221    def getXMLAttributes(self):
    221222        return [XMLAttribute("dec",str(self.value))]
     
    225226    def __str__(self):
    226227        return "OMSTR("+repr(self.value)+")"
    227     XMLtag="OMSTR"
     228    XMLtag = "OMSTR"
    228229    def getBody(self):
    229230        return self.value
     
    232233        super(OMByteArray,self).__init__(value)
    233234    def __str__(self):
    234         return "OMByteArray("+repr(self.value)+")"
     235        return "OMByteArray(" + repr(self.value) + ")"
    235236    def parse(self, value):
    236237        return value
     
    247248        return context.XMLEncodeObject(self.ref)
    248249class OMAttributePair(OMObjectBase):
    249     def __init__(self,key, value):
     250    def __init__(self, key, value):
    250251        super(OMAttributePair,self).__init__()
    251         self.key=key
    252         self.value=value
     252        self.key = key
     253        self.value = value
    253254    def getChildren(self):
    254255        return [self.key, self.value]
     
    260261    def __init__(self, *args):
    261262        super(OMAttribution,self).__init__()
    262         self.attr=list(args[:-1])
    263         self.value=args[-1]
     263        self.attr = list(args[:-1])
     264        self.value = args[-1]
    264265    def getChildren(self):
    265266        #print type(self.attr)
     
    267268        return self.attr+[self.value]
    268269    def evaluate(self, context):
    269         value=copy(self.value)
    270         value.attributes=copy(value.attributes)
     270        value = copy(self.value)
     271        value.attributes = copy(value.attributes)
    271272        for a in self.attr:
    272273            ae=context.evaluate(a)
    273             value.attributes[ae.key]=ae.value
     274            value.attributes[ae.key] = ae.value
    274275        return value
    275     XMLtag="OMATTR"
    276 if __name__=='__main__':
     276    XMLtag = "OMATTR"
     277if __name__ == '__main__':
    277278    from context import *
    278279
    279280    from binding import *
    280281
    281     context=Context()
     282    context = Context()
    282283
    283284    context.push({})
    284285
    285     context["x"]=OMint(1)
    286 
    287     x=OMVar("x")
    288 
    289     y=OMVar("y")
     286    context["x"] = OMint(1)
     287
     288    x = OMVar("x")
     289
     290    y = OMVar("y")
    290291
    291292    print context.evaluate(x)
     
    293294    firstArg=OMBinding(lambdasym,[OMVar("x"), OMVar("y")], OMVar("x"))
    294295    #print context.evaluate(firstArg)
    295     application=OMApply(firstArg, [x,y])
     296    application = OMApply(firstArg, [x,y])
    296297    print context.evaluate(application)
    297     application=OMApply(firstArg,[y,x])
     298    application = OMApply(firstArg, [y,x])
    298299    print context.evaluate(application)
    299300    import arith1
     
    302303    #application=OMApply(arith1.plussym,[x])
    303304    #application=OMApply(arith1.plussym,[x,x])
    304     application=OMApply(OMSymbol("plus",arith1.content),[x,x])
     305    application = OMApply(OMSymbol("plus",arith1.content),[x, x])
    305306   
    306307    print context.evaluate(application)
    307     application=OMApply(OMSymbol("plus",arith1.content),[x,x,x])
     308    application=OMApply(OMSymbol("plus",arith1.content),[x, x, x])
    308309   
    309310    print context.evaluate(application)
    310     i=OMint(22482489)
     311    i =  sOMint(22482489)
    311312    print i.body
    312313    print i.XMLEncode(context)
Note: See TracChangeset for help on using the changeset viewer.