Author: Armin Rigo <[email protected]>
Branch:
Changeset: r64689:140e6c594a81
Date: 2013-05-31 21:39 +0200
http://bitbucket.org/pypy/pypy/changeset/140e6c594a81/
Log: Minor clean-up of RStringIO.truncate(). This is a no-op from the
point of view of the whole PyPy: it moves into RStringIO the
behavior that was previously done with an explicit call to seek(0,
2).
diff --git a/pypy/module/cStringIO/interp_stringio.py
b/pypy/module/cStringIO/interp_stringio.py
--- a/pypy/module/cStringIO/interp_stringio.py
+++ b/pypy/module/cStringIO/interp_stringio.py
@@ -159,7 +159,6 @@
if size < 0:
raise OperationError(space.w_IOError, space.wrap("negative size"))
self.truncate(size)
- self.seek(0, 2)
@unwrap_spec(buffer='bufferstr')
def descr_write(self, buffer):
diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py
--- a/rpython/rlib/rStringIO.py
+++ b/rpython/rlib/rStringIO.py
@@ -163,6 +163,10 @@
return ''.join(self.__bigbuffer[p:i])
def truncate(self, size):
+ """Warning, this gets us slightly strange behavior from the
+ point of view of a traditional Unix file, but consistent with
+ Python 2.7's cStringIO module: it will not enlarge the file,
+ and it will always seek to the (new) end of the file."""
assert size >= 0
if self.__bigbuffer is None or size > len(self.__bigbuffer):
self.__copy_into_bigbuffer()
@@ -174,3 +178,5 @@
del self.__bigbuffer[size:]
if len(self.__bigbuffer) == 0:
self.__bigbuffer = None
+ # it always has the effect of seeking at the new end
+ self.__pos = AT_END
diff --git a/rpython/rlib/test/test_rStringIO.py
b/rpython/rlib/test/test_rStringIO.py
--- a/rpython/rlib/test/test_rStringIO.py
+++ b/rpython/rlib/test/test_rStringIO.py
@@ -96,7 +96,15 @@
f.truncate(20)
assert f.getvalue() == ''
assert f.tell() == 0
- f.write('\x00' * 20)
+ f.write('\x00' * 25)
+ f.seek(12)
+ f.truncate(20)
+ assert f.getvalue() == '\x00' * 20
+ assert f.tell() == 20
+ f.write('more')
+ f.truncate(20)
+ assert f.getvalue() == '\x00' * 20
+ assert f.tell() == 20
f.write('hello')
f.write(' world')
f.truncate(30)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit