source: git/modules/openmathserver/cd.py @ 859b51

spielwiese
Last change on this file since 859b51 was 68549d, checked in by Michael Brickenstein <bricken@…>, 19 years ago
*bricken: initial version git-svn-id: file:///usr/local/Singular/svn/trunk@8358 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.2 KB
Line 
1from objects import OMsymbol
2from omexceptions import *
3class OMcd(object):
4    def __init__(self,name, base="http://www.openmath.org/cd"):
5        self.name=name
6        self.base=base
7    def  __eq__(self, other):
8        return (self.name==other.name) and (self.base==other.base)
9    def __hash__(self):
10        return hash((self.name,self.base))
11
12class OMcdImplementation(object):
13    def __init__(self,cd):
14        self.cd=cd
15        self.implementations={}
16    def __getitem__(self, name):
17        return self.implementations[name]
18    def __setitem__(self,name,value):
19        self.implementations[name]=value
20    def implement(self,symbolname, func):
21        symbol=OMsymbol(symbolname,self.cd)
22        impl=ImplementedOMsymbol(symbol,func)
23        self[symbol]=impl
24       
25
26
27class ImplementedOMsymbol(OMsymbol):
28    def __init__(self,symbol, func):
29        super(ImplementedOMsymbol,self).__init__(symbol.name, symbol.cd)
30        self.implementation=func
31    def __str__(self):
32        return "ImplementedOMS("+self.name+", " + self.cd.name +")"
33    def __call__(self, context, *args):
34        try:
35            erg=self.implementation(context,*args)
36        except KeyError:
37             raise EvaluationFailedError
38        return context.package(erg)
Note: See TracBrowser for help on using the repository browser.