[pypy-svn] pypy default: Make sure a number of properties are exposed at app level.

alex_gaynor commits-noreply at bitbucket.org
Mon Jan 31 01:13:42 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r41478:40fe4da4a384
Date: 2011-01-30 19:13 -0500
http://bitbucket.org/pypy/pypy/changeset/40fe4da4a384/

Log:	Make sure a number of properties are exposed at app level.

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -949,5 +949,6 @@
     seekable = interp2app(W_TextIOWrapper.seekable_w),
     fileno = interp2app(W_TextIOWrapper.fileno_w),
     name = GetSetProperty(W_TextIOWrapper.name_get_w),
+    buffer = interp_attrproperty_w("w_buffer", cls=W_TextIOWrapper),
     closed = GetSetProperty(W_TextIOWrapper.closed_get_w),
 )

diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -1,6 +1,6 @@
 from __future__ import with_statement
 from pypy.interpreter.typedef import (
-    TypeDef, GetSetProperty, generic_new_descr)
+    TypeDef, GetSetProperty, generic_new_descr, interp_attrproperty_w)
 from pypy.interpreter.gateway import interp2app, unwrap_spec, Arguments
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
 from pypy.interpreter.error import OperationError, operationerrfmt
@@ -758,6 +758,7 @@
     read = interp2app(W_BufferedReader.read_w),
     peek = interp2app(W_BufferedReader.peek_w),
     read1 = interp2app(W_BufferedReader.read1_w),
+    raw = interp_attrproperty_w("w_raw", cls=W_BufferedReader),
 
     # from the mixin class
     __repr__ = interp2app(W_BufferedReader.repr_w),
@@ -803,6 +804,7 @@
 
     write = interp2app(W_BufferedWriter.write_w),
     flush = interp2app(W_BufferedWriter.flush_w),
+    raw = interp_attrproperty_w("w_raw", cls=W_BufferedWriter),
 
     # from the mixin class
     __repr__ = interp2app(W_BufferedWriter.repr_w),
@@ -935,6 +937,7 @@
 
     write = interp2app(W_BufferedRandom.write_w),
     flush = interp2app(W_BufferedRandom.flush_w),
+    raw = interp_attrproperty_w("w_raw", cls=W_BufferedRandom),
 
     # from the mixin class
     __repr__ = interp2app(W_BufferedRandom.repr_w),

diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -173,6 +173,30 @@
         with _io.open(self.tmpfile, "wb", 0) as f:
             assert f.write(a) == n
 
+    def test_attributes(self):
+        import _io
+
+        with _io.open(self.tmpfile, "wb", buffering=0) as f:
+            assert f.mode == "wb"
+
+        with _io.open(self.tmpfile, "U") as f:
+            assert f.name == self.tmpfile
+            assert f.buffer.name == self.tmpfile
+            assert f.buffer.raw.name == self.tmpfile
+            assert f.mode == "U"
+            assert f.buffer.mode == "rb"
+            assert f.buffer.raw.mode == "rb"
+
+        with _io.open(self.tmpfile, "w+") as f:
+            assert f.mode == "w+"
+            assert f.buffer.mode == "rb+"
+            assert f.buffer.raw.mode == "rb+"
+
+            with _io.open(f.fileno(), "wb", closefd=False) as g:
+                assert g.mode == "wb"
+                assert g.raw.mode == "wb"
+                assert g.name == f.fileno()
+                assert g.raw.name == f.fileno()
 
     def test_seek_and_tell(self):
         import _io


More information about the Pypy-commit mailing list