Commit d9eb0444 authored by Shane Hathaway's avatar Shane Hathaway

Added support for ExtensionClass to the Interfaces package.

parent 0aa0a900
from iclass import Interface, Class, ClassType, Base, assertTypeImplements, _typeImplements #uuh..
from iclass import Interface, Class, ClassTypes, Base, \
assertTypeImplements, _typeImplements #uuh..
from types import FunctionType from types import FunctionType
def impliedInterface(klass, __name__=None, __doc__=None): def impliedInterface(klass, __name__=None, __doc__=None):
"""Create an interface object from a class """Create an interface object from a class
...@@ -26,7 +29,7 @@ def objectImplements(object, tiget=_typeImplements.get): ...@@ -26,7 +29,7 @@ def objectImplements(object, tiget=_typeImplements.get):
r=[] r=[]
t=type(object) t=type(object)
if t is ClassType: if t in ClassTypes:
if hasattr(object, '__class_implements__'): if hasattr(object, '__class_implements__'):
implements=object.__class_implements__ implements=object.__class_implements__
else: else:
...@@ -48,7 +51,7 @@ def instancesOfObjectImplements(klass, tiget=_typeImplements.get): ...@@ -48,7 +51,7 @@ def instancesOfObjectImplements(klass, tiget=_typeImplements.get):
""" """
r=[] r=[]
if type(klass) is ClassType: if type(klass) in ClassTypes:
if hasattr(klass, '__implements__'): if hasattr(klass, '__implements__'):
implements=klass.__implements__ implements=klass.__implements__
else: return r else: return r
......
...@@ -15,6 +15,15 @@ from types import FunctionType, ClassType ...@@ -15,6 +15,15 @@ from types import FunctionType, ClassType
import Exceptions import Exceptions
from InterfaceBase import InterfaceBase from InterfaceBase import InterfaceBase
try:
from ExtensionClass import Base
except ImportError:
ClassTypes = (ClassType,)
else:
class dummy (Base): pass
ClassTypes = (type(dummy), ClassType)
_typeImplements={} _typeImplements={}
class Interface(InterfaceBase): class Interface(InterfaceBase):
...@@ -68,7 +77,7 @@ class Interface(InterfaceBase): ...@@ -68,7 +77,7 @@ class Interface(InterfaceBase):
"""Does the given object implement the interface? """Does the given object implement the interface?
""" """
t=type(object) t=type(object)
if t is ClassType: if t in ClassTypes:
if hasattr(object, '__class_implements__'): if hasattr(object, '__class_implements__'):
implements=object.__class_implements__ implements=object.__class_implements__
else: implements=Class else: implements=Class
...@@ -87,7 +96,7 @@ class Interface(InterfaceBase): ...@@ -87,7 +96,7 @@ class Interface(InterfaceBase):
tiget=_typeImplements.get): tiget=_typeImplements.get):
"""Do instances of the given class implement the interface? """Do instances of the given class implement the interface?
""" """
if type(klass) is ClassType: if type(klass) in ClassTypes:
if hasattr(klass, '__implements__'): if hasattr(klass, '__implements__'):
implements=klass.__implements__ implements=klass.__implements__
else: return 0 else: return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment