[pypy-svn] r79178 - in pypy/branch/fast-forward/pypy/module/_io: . test

afa at codespeak.net afa at codespeak.net
Wed Nov 17 11:32:07 CET 2010


Author: afa
Date: Wed Nov 17 11:32:05 2010
New Revision: 79178

Modified:
   pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py
   pypy/branch/fast-forward/pypy/module/_io/test/test_io.py
Log:
Add a __dict__ to all IO classes


Modified: pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py	Wed Nov 17 11:32:05 2010
@@ -1,6 +1,6 @@
 from pypy.interpreter.baseobjspace import ObjSpace, Wrappable, W_Root
 from pypy.interpreter.typedef import (
-    TypeDef, GetSetProperty, generic_new_descr)
+    TypeDef, GetSetProperty, generic_new_descr, descr_get_dict, descr_set_dict)
 from pypy.interpreter.gateway import interp2app, Arguments, unwrap_spec
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.rlib.rstring import StringBuilder
@@ -41,8 +41,12 @@
         # `__IOBase_closed` and call flush() by itself, but it is redundant
         # with whatever behaviour a non-trivial derived class will implement.
         self.space = space
+        self.w_dict = space.newdict()
         self.__IOBase_closed = False
 
+    def getdict(self):
+        return self.w_dict
+
     def _closed(self, space):
         # This gets the derived attribute, which is *not* __IOBase_closed
         # in most cases!
@@ -241,6 +245,7 @@
     _checkWritable = interp2app(check_writable_w),
     _checkSeekable = interp2app(check_seekable_w),
     closed = GetSetProperty(W_IOBase.closed_get_w),
+    __dict__ = GetSetProperty(descr_get_dict, descr_set_dict, cls=W_IOBase),
 
     readline = interp2app(W_IOBase.readline_w),
     readlines = interp2app(W_IOBase.readlines_w),

Modified: pypy/branch/fast-forward/pypy/module/_io/test/test_io.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/test/test_io.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_io/test/test_io.py	Wed Nov 17 11:32:05 2010
@@ -52,6 +52,24 @@
             assert e.strerror == "test blocking"
             assert e.characters_written == 123
 
+    def test_dict(self):
+        import _io
+        f = _io.BytesIO()
+        f.x = 42
+        assert f.x == 42
+        #
+        def write(data):
+            try:
+                data = data.tobytes().upper()
+            except AttributeError:
+                data = data.upper()
+            return _io.BytesIO.write(f, data)
+        f.write = write
+        bufio = _io.BufferedWriter(f)
+        bufio.write("abc")
+        bufio.flush()
+        assert f.getvalue() == "ABC"
+
     def test_destructor(self):
         import io
         io.IOBase()



More information about the Pypy-commit mailing list