[pypy-svn] rev 2565 - pypy/trunk/src/pypy/interpreter

pmaupin at codespeak.net pmaupin at codespeak.net
Fri Dec 19 14:37:25 CET 2003


Author: pmaupin
Date: Fri Dec 19 14:37:25 2003
New Revision: 2565

Modified:
   pypy/trunk/src/pypy/interpreter/module.py
Log:
Check that module attributes are strings

Modified: pypy/trunk/src/pypy/interpreter/module.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/module.py	(original)
+++ pypy/trunk/src/pypy/interpreter/module.py	Fri Dec 19 14:37:25 2003
@@ -5,6 +5,11 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError
 
+def _checkattrtype(space, w_attr):
+    attr = space.unwrap(w_attr)
+    if not isinstance(attr, str):
+        raise OperationError(space.w_TypeError,
+                  space.wrap('attribute name must be string'))
 
 class Module(Wrappable):
     """A module."""
@@ -16,6 +21,7 @@
 
     def pypy_getattr(self, w_attr):
         space = self.space
+        _checkattrtype(space, w_attr)
         if space.is_true(space.eq(w_attr, space.wrap('__dict__'))):
             return self.w_dict
         try:
@@ -27,10 +33,13 @@
             raise OperationError(space.w_AttributeError, w_attr)
 
     def pypy_setattr(self, w_attr, w_value):
-        self.space.setitem(self.w_dict, w_attr, w_value)
+        space = self.space
+        _checkattrtype(space, w_attr)
+        space.setitem(self.w_dict, w_attr, w_value)
 
     def pypy_delattr(self, w_attr):
         space = self.space
+        _checkattrtype(space, w_attr)
         try:
             space.delitem(self.w_dict, w_attr)
         except OperationError, e:


More information about the Pypy-commit mailing list