Example #1
0
    def isNewStyleClass(o):
        try:
            # would give a NameError on Python <= 2.1
            return issubclass(o,object)
        except TypeError:
            return 0
else:
    def isNewStyleClass(o):	
        return 0

hasSlots	 = lambda o: hasattr(o,'__slots__')
hasInit		 = lambda o: hasattr(o,'__init__')
hasDictAttrs = lambda o: (hasattr(o,'__dict__') and o.__dict__)

isInstanceLike = lazy_any(isInstance, hasDictAttrs, hasSlots)
hasCompoundShape = and_(isInstanceLike, not_(isInstance))

true_container = lambda o: type(o) in containers
true_simpletype = lambda o: type(o) in simpletypes
true_datatype = or_(true_container, true_simpletype)
child_container = and_(not_(true_container), isContainer)
child_simpletype = and_(not_(true_simpletype), isSimpleType)
child_datatype = or_(child_container, child_simpletype)

def hasCoreData(o):
    """Is 'o' an object subclassed from a builtin type?

    (i.e. does it contain data other than attributes)
    We only want subclasses, not the class itself (otherwise we'd
    catch ALL lists, integers, etc.)
    """
Example #2
0
    def isNewStyleClass(o):
        try:
            # would give a NameError on Python <= 2.1
            return issubclass(o,object)
        except TypeError:
            return 0
else:
    def isNewStyleClass(o):	
        return 0

hasSlots	 = lambda o: hasattr(o,'__slots__')
hasInit		 = lambda o: hasattr(o,'__init__')
hasDictAttrs = lambda o: (hasattr(o,'__dict__') and o.__dict__)

isInstanceLike = lazy_any(isInstance, hasDictAttrs, hasSlots)
hasCompoundShape = and_(isInstanceLike, not_(isInstance))

true_container = lambda o: type(o) in containers
true_simpletype = lambda o: type(o) in simpletypes
true_datatype = or_(true_container, true_simpletype)
child_container = and_(not_(true_container), isContainer)
child_simpletype = and_(not_(true_simpletype), isSimpleType)
child_datatype = or_(child_container, child_simpletype)

def hasCoreData(o):
    """Is 'o' an object subclassed from a builtin type?

    (i.e. does it contain data other than attributes)
    We only want subclasses, not the class itself (otherwise we'd
    catch ALL lists, integers, etc.)
    """