[pypy-svn] r9252 - in pypy/branch/dist-interpapp/pypy: interpreter objspace objspace/std

pedronis at codespeak.net pedronis at codespeak.net
Wed Feb 16 18:14:44 CET 2005


Author: pedronis
Date: Wed Feb 16 18:14:44 2005
New Revision: 9252

Modified:
   pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py
   pypy/branch/dist-interpapp/pypy/objspace/descroperation.py
   pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py
Log:
introduced getdictvalue on W_Root (w_obj.getdictvalue(space, attr)  and on descroperation derived
spaces descrspace.getdictvalue(w_obj, attr). Use in default __getattribute__ and in type lookup.



Modified: pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py	Wed Feb 16 18:14:44 2005
@@ -13,6 +13,18 @@
     in a 'normal' object space like StdObjSpace."""
     def getdict(self):
         return None
+
+    def getdictvalue(self, space, attr):
+        w_dict = self.getdict()
+        if w_dict is not None:
+            try:
+                return space.getitem(w_dict, space.wrap(attr))
+            except OperationError, e:
+                if not e.match(space, space.w_KeyError):
+                    raise
+        return None
+
+    
     def getclass(self, space):
         return space.gettypeobject(self.typedef)
 

Modified: pypy/branch/dist-interpapp/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/dist-interpapp/pypy/objspace/descroperation.py	Wed Feb 16 18:14:44 2005
@@ -12,15 +12,12 @@
         if w_descr is not None:
             if space.is_data_descr(w_descr):
                 return space.get(w_descr, w_obj)
-        w_dict = space.getdict(w_obj)
-        if w_dict is not None:  
-            try:
-                return space.getitem(w_dict, w_name)
-            except OperationError, e:
-                if not e.match(space, space.w_KeyError):
-                    raise
+        w_value = space.getdictvalue(w_obj, name)
+        if w_value is not None:
+            return w_value
         if w_descr is not None:
             return space.get(w_descr, w_obj)
+
         raise OperationError(space.w_AttributeError, w_name)
 
     def descr__setattr__(space, w_obj, w_name, w_value):
@@ -57,6 +54,9 @@
     def getdict(space, w_obj):
         return w_obj.getdict()
 
+    def getdictvalue(space, w_obj, attr):
+        return w_obj.getdictvalue(space, attr)
+
     def is_data_descr(space, w_obj):
         return space.lookup(w_obj, '__set__') is not None
 

Modified: pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py	(original)
+++ pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py	Wed Feb 16 18:14:44 2005
@@ -106,21 +106,19 @@
             if isinstance(w_new, Function):
                 w_self.dict_w['__new__'] = StaticMethod(w_new)
 
+    def getdictvalue(w_self, space, attr):
+        try:
+            return w_self.dict_w[attr]
+        except KeyError:
+            return None
+
     def lookup(w_self, key):
         # note that this doesn't call __get__ on the result at all
         space = w_self.space
         for w_class in w_self.mro_w:
-            try:
-                if isinstance(w_class, W_TypeObject):
-                    return w_class.dict_w[key]
-                else:
-                    try:
-                        return space.getitem(space.getdict(w_class),space.wrap(key))
-                    except OperationError,e:
-                        if not e.match(space, space.w_KeyError):
-                            raise
-            except KeyError:
-                pass
+            w_value = space.getdictvalue(w_class, key)
+            if w_value is not None:
+                return w_value
         return None
 
     def lookup_where(w_self, key):
@@ -128,17 +126,9 @@
         # attribute was found
         space = w_self.space
         for w_class in w_self.mro_w:
-            try:
-                if isinstance(w_class, W_TypeObject):
-                    return w_class, w_class.dict_w[key]
-                else:
-                    try:
-                        return w_class, space.getitem(space.getdict(w_class),space.wrap(key))
-                    except OperationError,e:
-                        if not e.match(space, space.w_KeyError):
-                            raise                
-            except KeyError:
-                pass
+            w_value = space.getdictvalue(w_class, key)
+            if w_value is not None:
+                return w_class, w_value
         return None, None
 
     def check_user_subclass(w_self, w_subtype):



More information about the Pypy-commit mailing list