def _unpack(self, name): iface = self.type.get_interface() foreign_struct = None if iface.is_foreign: foreign_struct = foreign.get_foreign(iface.namespace, iface.name) if foreign_struct: return self.parse(""" if $obj: $new_foreign = $foreign.from_pointer($obj) else: $new_foreign = $obj """, obj=name, foreign=foreign_struct)["new_foreign"] return self.parse(""" if $value: $obj = $_.object.__new__($type) $obj._obj = $value else: $obj = None """, value=name, type=self._import_type())["obj"]
def _import_foreign(self): """Gives a ForeignStruct implementation or None""" struct_info = self.type.get_interface() assert isinstance(struct_info, GIStructInfo) if not struct_info.is_foreign: return return foreign.get_foreign(struct_info.namespace, struct_info.name)
def test_get_foreign(self): foreign = get_foreign("cairo", "Context") self.assertTrue(foreign)