def setup(self): iface = self.type.get_interface() try: self.py_type = import_attribute(iface.namespace, iface.name) except ImportError: # fall back to object pass
def setup(self): iface = self.type.get_interface() try: self.py_type = import_attribute(iface.namespace, iface.name) except ImportError: # fall back to object pass else: # XXX: some structs like MemVTable contain a callback for which # the name clashes with a function in the same namespace. Special # case this here and force back to "object" if iface.type.value == GIInfoType.CALLBACK and not \ getattr(self.py_type, "_is_callback", False): self.py_type = object
def _check(self, name): base_obj = import_attribute("GObject", "Object") foreign_struct = self._import_foreign() if foreign_struct: foreign_type = foreign_struct.get_type() return self.parse(""" if not $_.isinstance($obj, $struct_class): raise $_.TypeError("$DESC: %r is not a %r" % ($obj, $struct_class)) """, struct_class=foreign_type, obj=name)["obj"] else: return self.parse(""" if not $_.isinstance($obj, ($struct_class, $obj_class)): raise $_.TypeError("$DESC: %r is not a structure object" % $obj) """, obj_class=base_obj, struct_class=self._import_type(), obj=name)["obj"]
def _import_type(self): iface = self.type.get_interface() return import_attribute(iface.namespace, iface.name)