Changeset d113d3 in git


Ignore:
Timestamp:
Jun 17, 2005, 11:25:17 AM (18 years ago)
Author:
Michael Brickenstein <bricken@…>
Branches:
(u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
Children:
559396511a24a530616d6e6f0515acad72817234
Parents:
bf5590544366352bc842f5dc754a381cef5c7e0b
Message:
*bricken: + attributions


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

Legend:

Unmodified
Added
Removed
  • modules/openmathserver/context.py

    rbf5590 rd113d3  
    7171        return self.XMLEncoder.encode(body)
    7272    def XMLEncodeObject(self, obj):
    73         return obj.XMLencode(self)
     73        #TODO: Make Attribution List attributes
     74        #TODO: Make all objects __hash__ and __eq__
     75        if (len(obj.attributes)==0):
     76            return obj.XMLencode(self)
     77        else:
     78            toencode=copy(obj)
     79            toencode.attributes={}
     80            #FIXME: look on order
     81            attribution=OMAttribution(*([OMAttributePair(k,obj.attributes[k])\
     82                for k in obj.attributes])+[toencode])
     83            return attribution.XMLencode(self)
     84           
    7485class SimpleXMLEncoder(object):
    7586    def encode(self, string):
  • modules/openmathserver/objects.py

    rbf5590 rd113d3  
    11from omexceptions import *
    22from exceptions import *
     3from copy import copy
    34import base64
    45#TODO: OMOBJ, OME, OMATTR
     
    245246        "FIXME: maybe it should also be able to encode as reference"
    246247        return context.XMLEncodeObject(self.ref)
     248class OMAttributePair(OMObjectBase):
     249    def __init__(self,key, value):
     250        super(OMAttributePair,self).__init__()
     251        self.key=key
     252        self.value=value
     253    def getChildren(self):
     254        return [self.key, self.value]
     255    XMLtag = "OMATP"
     256    def evaluate(self, context):
     257        return OMAttributePair(context.evaluate(self.key),\
     258            context.evaluate(self.value))
     259class OMAttribution(OMObjectBase):
     260    def __init__(self, *args):
     261        super(OMAttribution,self).__init__()
     262        self.attr=list(args[:-1])
     263        self.value=args[-1]
     264    def getChildren(self):
     265        #print type(self.attr)
     266        #print type(self.value)
     267        return self.attr+[self.value]
     268    def evaluate(self, context):
     269        value=copy(self.value)
     270        value.attributes=copy(value.attributes)
     271        for a in self.attr:
     272            ae=context.evaluate(a)
     273            value.attributes[ae.key]=ae.value
     274        return value
     275    XMLtag="OMATTR"
    247276if __name__=='__main__':
    248277    from context import *
  • modules/openmathserver/omxmlreader.py

    rbf5590 rd113d3  
    9898            else:
    9999                raise UnresolvedReference
     100        if (node.nodeName=="OMATP"):
     101            children=[self.buildFromNode(c) for c in node.childNodes]
     102            assert(len(children)==2)
     103            erg=OMAttributePair(children[0],children[1])
     104        if (node.nodeName=="OMATTR"):
     105            children=[self.buildFromNode(c) for c in node.childNodes]
     106            erg=OMAttribution(*children)
    100107        if None==erg:
    101108            raise NotImplementedError
Note: See TracChangeset for help on using the changeset viewer.