source: git/modules/openmathserver/cd.py @ 1667822

spielwiese
Last change on this file since 1667822 was 1667822, checked in by Michael Brickenstein <bricken@…>, 19 years ago
*bricken: refactoring git-svn-id: file:///usr/local/Singular/svn/trunk@8370 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.3 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        try:
9            return (self.name==other.name) and (self.base==other.base)
10        except:
11            return False
12    def __hash__(self):
13        return hash((self.name,self.base))
14
15class OMcdImplementation(object):
16    def __init__(self,cd):
17        self.cd=cd
18        self.implementations={}
19    def __getitem__(self, name):
20        return self.implementations[name]
21    def __setitem__(self,name,value):
22        self.implementations[name]=value
23    def implement(self,symbolname, func):
24        symbol=OMSymbol(symbolname,self.cd)
25        impl=ImplementedOMSymbol(symbol,func)
26        self[symbol]=impl
27       
28
29
30class ImplementedOMSymbol(OMSymbol):
31    def __init__(self,symbol, func):
32        super(ImplementedOMSymbol,self).__init__(symbol.name, symbol.cd)
33        self.implementation=func
34    def __str__(self):
35        return "ImplementedOMS("+self.name+", " + self.cd.name +")"
36    def __call__(self, context, *args):
37        try:
38            erg=self.implementation(context,*args)
39        except KeyError:
40             raise EvaluationFailedError
41        return context.package(erg)
Note: See TracBrowser for help on using the repository browser.