def getattr(self, w_obj, w_name): if not self.config.objspace.std.getattributeshortcut: return DescrOperation.getattr(self, w_obj, w_name) # an optional shortcut for performance from pypy.objspace.descroperation import raiseattrerror from pypy.objspace.descroperation import object_getattribute w_type = self.type(w_obj) if not w_type.uses_object_getattribute: # slow path: look for a custom __getattribute__ on the class w_descr = w_type.lookup('__getattribute__') # if it was not actually overriden in the class, we remember this # fact for the next time. if w_descr is object_getattribute(self): w_type.uses_object_getattribute = True return self._handle_getattribute(w_descr, w_obj, w_name) # fast path: XXX this is duplicating most of the logic # from the default __getattribute__ and the getattr() method... name = self.str_w(w_name) w_descr = w_type.lookup(name) e = None if w_descr is not None: if not self.is_data_descr(w_descr): w_value = w_obj.getdictvalue_attr_is_in_class(self, w_name) if w_value is not None: return w_value try: return self.get(w_descr, w_obj) except OperationError, e: if not e.match(self, self.w_AttributeError): raise
def getattr(self, w_obj, w_name): if not self.config.objspace.std.getattributeshortcut: return DescrOperation.getattr(self, w_obj, w_name) # an optional shortcut for performance w_type = self.type(w_obj) w_descr = w_type.getattribute_if_not_from_object() if w_descr is not None: return self._handle_getattribute(w_descr, w_obj, w_name) # fast path: XXX this is duplicating most of the logic # from the default __getattribute__ and the getattr() method... name = self.str_w(w_name) w_descr = w_type.lookup(name) e = None if w_descr is not None: w_get = None is_data = self.is_data_descr(w_descr) if is_data: w_get = self.lookup(w_descr, "__get__") if w_get is None: w_value = w_obj.getdictvalue(self, name) if w_value is not None: return w_value if not is_data: w_get = self.lookup(w_descr, "__get__") if w_get is not None: # __get__ is allowed to raise an AttributeError to trigger # use of __getattr__. try: return self.get_and_call_function(w_get, w_descr, w_obj, w_type) except OperationError, e: if not e.match(self, self.w_AttributeError): raise else: return w_descr