00001 """ 00002 This package is not currently used by slimpy 00003 """ 00004 00005 __copyright__ = """ 00006 Copyright 2008 Sean Ross-Ross 00007 """ 00008 __license__ = """ 00009 This file is part of SLIMpy . 00010 00011 SLIMpy is free software: you can redistribute it and/or modify 00012 it under the terms of the GNU Lesser General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 SLIMpy is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public License 00022 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>. 00023 """ 00024 00025 00026 class checktype(object): 00027 00028 def __init__(self,f,p,k,Return): 00029 print "checktype" 00030 self.f = f 00031 self.p = p 00032 self.k = k 00033 self.Return = Return 00034 00035 def __call__(self,*q,**r): 00036 print "call" 00037 self.check(q, r) 00038 Return = self.f(*q,**r) 00039 if self.Return is not None and not isinstance(Return, self.Return): 00040 raise Exception 00041 return Return 00042 00043 def check(self,q,r): 00044 for i in range(len(self.p)): 00045 print i 00046 print self.p[i] , type(q[i]) 00047 if not isinstance(q[i],self.p[i] ): 00048 raise Exception 00049 for i in self.k.keys(): 00050 if i in r: 00051 if not isinstance(r[i],self.k[i] ): 00052 raise Exception 00053 00054 00055 def prototype(Return=None,*p,**k): 00056 print "check" 00057 def func(f): 00058 print "func" 00059 return checktype(f,p,k,Return=Return) 00060 return func 00061 00062 00063 00064 def abstractmethod(method): 00065 """Decorator for tagging a method as abstract. """ 00066 def NotImplementedMethod(*p,**k): 00067 raise NotImplementedError, "Abstract method %s not implemented" % method 00068 return NotImplementedMethod 00069 00070 00071 00072 00073 class abstractclass(object): 00074 def __abstractmethods(self): 00075 for methodname in dir(self): 00076 method = getattr(self, methodname, None) 00077 if not callable(method): 00078 continue 00079 if hasattr(method, "abstract"): 00080 raise NotImplementedError, ("Abstract method %s not implemented" % 00081 method) 00082 00083 def __getattribute__(self,attribute): 00084 method = object.__getattribute__(self,attribute) 00085 if hasattr(method, "abstract"): 00086 raise NotImplementedError, ("Abstract method %s not implemented" % 00087 method) 00088 return method 00089 00090 00091 class interface(object): 00092 00093 def __new__(self): 00094 raise Exception, "Unimplemented interface" 00095 00096 00097 00098 class implements(abstractclass): 00099 def __abstractmethods(self): 00100 pass 00101 00102 def __getattribute__(self,attribute): 00103 return object.__getattribute__(self,attribute) 00104 00105