def ClassDescNodeAdapter(classdesc, _cache={}): """ Adapter to convert a ClassDesc into an INode. """ if classdesc in _cache: return _cache[classdesc] dct = dict(keep_desc=True, __multiname__=classdesc.FullName, __library__=classdesc.Library) for n, t, s in classdesc.Fields: dct[n.name] = Slot(t, s) for n, t, s in classdesc.StaticFields: dct[n.name] = Slot(t, s, static=True) for n, t, g, s in classdesc.Properties: dct[n.name] = Slot(t) for n, t, g, s in classdesc.StaticProperties: dct[n.name] = Slot(t, static=True) for n, p, r in classdesc.Methods: dct[n.name] = ClassDescFunctionNode(n.name, r) for n, p, r in classdesc.StaticMethods: dct[n.name] = ClassDescFunctionNode(n.name, r, static=True) base = classdesc.BaseType if type(base) == object or base is None or base == QName("*"): # interfaces and root objects base = object else: base = INode(get_type(base)) meta = ClassDescNodeMeta(classdesc.FullName, (base,), dct) _cache[classdesc] = meta return meta
def ClassDescNodeAdapter(classdesc, _cache={}): """ Adapter to convert a ClassDesc into an INode. """ if classdesc in _cache: return _cache[classdesc] dct = dict(keep_desc=True, __multiname__=classdesc.FullName, __library__=classdesc.Library) for n, t, s in classdesc.Fields: dct[n.name] = Slot(t, s) for n, t, s in classdesc.StaticFields: dct[n.name] = Slot(t, s, static=True) for n, t, g, s in classdesc.Properties: dct[n.name] = Slot(t) for n, t, g, s in classdesc.StaticProperties: dct[n.name] = Slot(t, static=True) for n, p, r in classdesc.Methods: dct[n.name] = ClassDescFunctionNode(n.name, r) for n, p, r in classdesc.StaticMethods: dct[n.name] = ClassDescFunctionNode(n.name, r, static=True) base = classdesc.BaseType if type(base) == object or base is None or base == QName( "*"): # interfaces and root objects base = object else: base = INode(get_type(base)) meta = ClassDescNodeMeta(classdesc.FullName, (base, ), dct) _cache[classdesc] = meta return meta
def __getattr__(self, attr): # Do some dirty magic here to make sure the Slot is # the object the function is being bound to. # Get the attribute, calling the descriptor if it exists. attribute = getattr(INode(get_type(self.type)), attr) # Get the actual function. attribute = getattr(attribute, "function", attribute) attribute = getattr(attribute, "im_func", attribute) # And finally, call the descriptor on us. if getattr(attribute, "get_bound", None): attribute = attribute.get_bound(self, False) return attribute
def bases(self): bases, context = [], self while context and IMultiname(context) != IMultiname("Object"): bases.append(context) context = INode(get_type(IMultiname(context.__basetype__))) return bases