Example #1
0
    "A varargs form of isinstance()"
    for t in types:
        if isinstance(o, t): return t

isContainer	 = lambda o: isinstance_any(o, containers)
isSimpleType = lambda o: isinstance_any(o, simpletypes)
isInstance	 = lambda o: type(o) is object
isImmutable	 = lambda o: isinstance_any(o, immutabletypes)

if gnosis.pyconfig.Have_ObjectClass():	
    isNewStyleInstance = lambda o: issubclass(o.__class__,object) and \
                                not type(o) in datatypes
else:
    isNewStyleInstance = lambda o: 0
isOldStyleInstance = lambda o: isinstance(o, type)
isClass			= or_(isOldStyleInstance, isNewStyleInstance)

if gnosis.pyconfig.Have_ObjectClass():
    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__)
Example #2
0
    "A varargs form of isinstance()"
    for t in types:
        if isinstance(o, t): return t

isContainer	 = lambda o: isinstance_any(o, containers)
isSimpleType = lambda o: isinstance_any(o, simpletypes)
isInstance	 = lambda o: type(o) is InstanceType
isImmutable	 = lambda o: isinstance_any(o, immutabletypes)

if gnosis.pyconfig.Have_ObjectClass():	
    isNewStyleInstance = lambda o: issubclass(o.__class__,object) and \
                                not type(o) in datatypes
else:
    isNewStyleInstance = lambda o: 0
isOldStyleInstance = lambda o: isinstance(o, ClassType)
isClass			= or_(isOldStyleInstance, isNewStyleInstance)

if gnosis.pyconfig.Have_ObjectClass():
    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__)