def findCtypesInPyObj(obj): """ check function to help in unpickling errors correction """ import ctypes ret = False if hasattr(obj, 'findCtypes'): if obj.findCtypes(): log.warning('Found a ctypes in array/tuple') return True elif isinstance(obj, tuple) or isinstance(obj, list): for el in obj: if findCtypesInPyObj(el): log.warning('Found a ctypes in array/tuple') return True elif ctypes.is_ctypes_instance(obj): return True return False
def _attrFindCtypes(self, attr, attrname, typ, cache): import ctypes ret = False cache.add(id(attr)) if hasattr(attr, '_ctype_'): # a pyobj return attr.findCtypes(cache) elif isinstance(attr, tuple) or isinstance(attr, list): for el in attr: if self._attrFindCtypes(el, 'element', None, cache): log.warning('Found a ctypes in array/tuple') return True elif ctypes.is_ctypes_instance(attr): log.warning('Found a ctypes in self %s' % (attr)) return True else: # int, long, str ... ret = False return ret