[pypy-svn] r79284 - in pypy/branch/fast-forward/pypy/module/_io: . test
afa at codespeak.net
afa at codespeak.net
Fri Nov 19 19:27:41 CET 2010
Author: afa
Date: Fri Nov 19 19:27:40 2010
New Revision: 79284
Modified:
pypy/branch/fast-forward/pypy/module/_io/interp_textio.py
pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py
Log:
Add detach(), flush(), close()
Modified: pypy/branch/fast-forward/pypy/module/_io/interp_textio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/interp_textio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/interp_textio.py Fri Nov 19 19:27:40 2010
@@ -207,11 +207,21 @@
def readline_w(self, space, w_limit=None):
self._unsupportedoperation(space, "readline")
+ @unwrap_spec('self', ObjSpace, W_Root)
+ def write_w(self, space, w_data):
+ self._unsupportedoperation(space, "write")
+
+ @unwrap_spec('self', ObjSpace)
+ def detach_w(self, space):
+ self._unsupportedoperation(space, "detach")
+
W_TextIOBase.typedef = TypeDef(
'_TextIOBase', W_IOBase.typedef,
__new__ = generic_new_descr(W_TextIOBase),
read = interp2app(W_TextIOBase.read_w),
+ readline = interp2app(W_TextIOBase.readline_w),
+ detach = interp2app(W_TextIOBase.detach_w),
encoding = interp_attrproperty_w("w_encoding", W_TextIOBase)
)
@@ -310,6 +320,25 @@
self._check_init(space)
return space.call_method(self.w_buffer, "seekable")
+ @unwrap_spec('self', ObjSpace)
+ def fileno_w(self, space):
+ self._check_init(space)
+ return space.call_method(self.w_buffer, "fileno")
+
+ @unwrap_spec('self', ObjSpace)
+ def flush_w(self, space):
+ self._check_closed(space)
+ # XXX self.telling = self.seekable
+ # XXX self._writeflush(space)
+ space.call_method(self.w_buffer, "flush")
+
+ @unwrap_spec('self', ObjSpace)
+ def close_w(self, space):
+ self._check_init(space)
+ if not self._closed(space):
+ return space.call_method(self, "flush")
+ return space.call_method(self.w_buffer, "close")
+
# _____________________________________________________________
def _set_decoded_chars(self, chars):
@@ -402,6 +431,15 @@
w_bytes = space.call_method(self.w_buffer, "readline")
return space.call_method(self.w_decoder, "decode", w_bytes)
+ @unwrap_spec('self', ObjSpace)
+ def detach_w(self, space):
+ self._check_init(space)
+ space.call_method(self, "flush")
+ w_buffer = self.w_buffer
+ self.w_buffer = None
+ self.state = STATE_DETACHED
+ return w_buffer
+
W_TextIOWrapper.typedef = TypeDef(
'TextIOWrapper', W_TextIOBase.typedef,
__new__ = generic_new_descr(W_TextIOWrapper),
@@ -409,9 +447,13 @@
read = interp2app(W_TextIOWrapper.read_w),
readline = interp2app(W_TextIOWrapper.readline_w),
+ detach = interp2app(W_TextIOWrapper.detach_w),
+ flush = interp2app(W_TextIOWrapper.flush_w),
+ close = interp2app(W_TextIOWrapper.close_w),
line_buffering = interp_attrproperty("line_buffering", W_TextIOWrapper),
readable = interp2app(W_TextIOWrapper.readable_w),
writable = interp2app(W_TextIOWrapper.writable_w),
seekable = interp2app(W_TextIOWrapper.seekable_w),
+ fileno = interp2app(W_TextIOWrapper.fileno_w),
)
Modified: pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py Fri Nov 19 19:27:40 2010
@@ -37,6 +37,18 @@
txt = _io.TextIOWrapper(UnReadable())
raises(IOError, txt.read)
+ def test_detach(self):
+ import _io
+ b = _io.BytesIO()
+ f = _io.TextIOWrapper(b)
+ assert f.detach() is b
+ raises(ValueError, f.fileno)
+ raises(ValueError, f.close)
+ raises(ValueError, f.detach)
+ raises(ValueError, f.flush)
+ assert not b.closed
+ b.close()
+
def test_newlinetranslate(self):
import _io
r = _io.BytesIO(b"abc\r\ndef\rg")
More information about the Pypy-commit
mailing list