def _obj(self, value): if value == ffi.NULL: value = None if value is not None and ffi.typeof(value) is not ffi.typeof(self._ffitype): raise TypeError('obj must be of type "%s"' % cls._ffitype) if self.__obj is not None: del self._obj_instance_map[(self.__obj, self._ffitype)] self.__obj = value if value is not None: self._obj_instance_map[(value, self._ffitype)] = self
def _obj(self, value): if value == ffi.NULL: value = None if value is not None and ffi.typeof(value) is not ffi.typeof( self._ffitype): raise TypeError('obj must be of type "%s"' % cls._ffitype) if self.__obj is not None: del self._obj_instance_map[(self.__obj, self._ffitype)] self.__obj = value if value is not None: self._obj_instance_map[(value, self._ffitype)] = self
def _from_obj(cls, obj): """Get a Python instance for the cdata obj Arguments: obj (cffi.cdata): The struct to wrap Returns: A tuple (instance, created) where instance is a python object wrapping `obj`. `created` is `False` if an existing instance was found and returned. It is `True` if a new python instance was created. """ if ffi.typeof(obj) is not ffi.typeof(cls._ffitype): raise TypeError('obj must be of type "%s"' % cls._ffitype) instance = cls._obj_instance_map.get((obj, cls._ffitype), None) if instance is not None: return instance, False # TODO: This makes me feel terrible and hate everything :( instance = cls.__new__(cls) instance._obj = obj return instance, True