Author: Antonio Cuni <anto.c...@gmail.com> Branch: py3k Changeset: r53001:9470a3e579f1 Date: 2012-02-28 22:57 +0100 http://bitbucket.org/pypy/pypy/changeset/9470a3e579f1/
Log: kill the cStringIO module and its tests diff --git a/lib_pypy/cStringIO.py b/lib_pypy/cStringIO.py deleted file mode 100644 --- a/lib_pypy/cStringIO.py +++ /dev/null @@ -1,16 +0,0 @@ -# -# StringIO-based cStringIO implementation. -# - -# Note that PyPy contains also a built-in module 'cStringIO' which will hide -# this one if compiled in. - -from StringIO import * -from StringIO import __doc__ - -class StringIO(StringIO): - def reset(self): - """ - reset() -- Reset the file position to the beginning - """ - self.seek(0, 0) diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -46,7 +46,7 @@ translation_modules = default_modules.copy() translation_modules.update(dict.fromkeys( ["fcntl", "rctime", "select", "signal", "_rawffi", "zlib", - "struct", "_md5", "cStringIO", "array", "_ffi", + "struct", "_md5", "array", "_ffi", # the following are needed for pyrepl (and hence for the # interactive prompt/pdb) "termios", "_minimal_curses", @@ -54,7 +54,7 @@ working_oo_modules = default_modules.copy() working_oo_modules.update(dict.fromkeys( - ["_md5", "_sha", "cStringIO", "itertools"] + ["_md5", "_sha", "itertools"] )) # XXX this should move somewhere else, maybe to platform ("is this posixish" diff --git a/pypy/module/cStringIO/__init__.py b/pypy/module/cStringIO/__init__.py deleted file mode 100644 --- a/pypy/module/cStringIO/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ - -# Package initialisation -from pypy.interpreter.mixedmodule import MixedModule - -class Module(MixedModule): - appleveldefs = { - } - - interpleveldefs = { - 'StringIO': 'interp_stringio.StringIO', - 'InputType': 'interp_stringio.W_InputType', - 'OutputType': 'interp_stringio.W_OutputType', - } diff --git a/pypy/module/cStringIO/interp_stringio.py b/pypy/module/cStringIO/interp_stringio.py deleted file mode 100644 --- a/pypy/module/cStringIO/interp_stringio.py +++ /dev/null @@ -1,254 +0,0 @@ -from pypy.interpreter.error import OperationError -from pypy.interpreter.baseobjspace import Wrappable -from pypy.interpreter.typedef import TypeDef, GetSetProperty -from pypy.interpreter.gateway import interp2app, unwrap_spec -from pypy.rlib.rStringIO import RStringIO - - -class W_InputOutputType(Wrappable): - softspace = 0 # part of the file object API - - def descr___iter__(self): - self.check_closed() - return self - - def descr_close(self): - self.close() - - def check_closed(self): - if self.is_closed(): - space = self.space - raise OperationError(space.w_ValueError, - space.wrap("I/O operation on closed file")) - - def descr_flush(self): - self.check_closed() - - def descr_getvalue(self): - self.check_closed() - return self.space.wrap(self.getvalue()) - - def descr_isatty(self): - self.check_closed() - return self.space.w_False - - def descr___next__(self): - space = self.space - self.check_closed() - line = self.readline() - if len(line) == 0: - raise OperationError(space.w_StopIteration, space.w_None) - return space.wrap(line) - - @unwrap_spec(n=int) - def descr_read(self, n=-1): - self.check_closed() - return self.space.wrap(self.read(n)) - - @unwrap_spec(size=int) - def descr_readline(self, size=-1): - self.check_closed() - return self.space.wrap(self.readline(size)) - - @unwrap_spec(size=int) - def descr_readlines(self, size=0): - self.check_closed() - lines_w = [] - while True: - line = self.readline() - if len(line) == 0: - break - lines_w.append(self.space.wrap(line)) - if size > 0: - size -= len(line) - if size <= 0: - break - return self.space.newlist(lines_w) - - def descr_reset(self): - self.check_closed() - self.seek(0) - - @unwrap_spec(position=int, mode=int) - def descr_seek(self, position, mode=0): - self.check_closed() - self.seek(position, mode) - - def descr_tell(self): - self.check_closed() - return self.space.wrap(self.tell()) - - # abstract methods - def close(self): assert False, "abstract" - def is_closed(self): assert False, "abstract" - def getvalue(self): assert False, "abstract" - def read(self, n=-1): assert False, "abstract" - def readline(self, size=-1): assert False, "abstract" - def seek(self, position, mode=0): assert False, "abstract" - def tell(self): assert False, "abstract" - -# ____________________________________________________________ - -class W_InputType(W_InputOutputType): - def __init__(self, space, string): - self.space = space - self.string = string - self.pos = 0 - - def close(self): - self.string = None - - def is_closed(self): - return self.string is None - - def getvalue(self): - return self.string - - def read(self, n=-1): - p = self.pos - count = len(self.string) - p - if n >= 0: - count = min(n, count) - if count <= 0: - return '' - self.pos = p + count - if count == len(self.string): - return self.string - else: - return self.string[p:p+count] - - def readline(self, size=-1): - p = self.pos - end = len(self.string) - if size >= 0 and size < end - p: - end = p + size - lastp = self.string.find('\n', p, end) - if lastp < 0: - endp = end - else: - endp = lastp + 1 - self.pos = endp - return self.string[p:endp] - - def seek(self, position, mode=0): - if mode == 1: - position += self.pos - elif mode == 2: - position += len(self.string) - if position < 0: - position = 0 - self.pos = position - - def tell(self): - return self.pos - -# ____________________________________________________________ - -class W_OutputType(RStringIO, W_InputOutputType): - def __init__(self, space): - RStringIO.__init__(self) - self.space = space - - def readline(self, size=-1): - p = self.tell() - bigbuffer = self.copy_into_bigbuffer() - end = len(bigbuffer) - if size >= 0 and size < end - p: - end = p + size - assert p >= 0 - i = p - while i < end: - finished = bigbuffer[i] == '\n' - i += 1 - if finished: - break - self.seek(i) - return ''.join(bigbuffer[p:i]) - - def descr_truncate(self, w_size=None): # note: a wrapped size! - self.check_closed() - space = self.space - if w_size is None or space.is_w(w_size, space.w_None): - size = self.tell() - else: - size = space.int_w(w_size) - if size < 0: - raise OperationError(space.w_IOError, space.wrap("negative size")) - self.truncate(size) - - @unwrap_spec(buffer='bufferstr') - def descr_write(self, buffer): - self.check_closed() - self.write(buffer) - - def descr_writelines(self, w_lines): - self.check_closed() - space = self.space - w_iterator = space.iter(w_lines) - while True: - try: - w_line = space.next(w_iterator) - except OperationError, e: - if not e.match(space, space.w_StopIteration): - raise - break # done - self.write(space.str_w(w_line)) - -# ____________________________________________________________ - -def descr_closed(self, space): - return space.wrap(self.is_closed()) - -def descr_softspace(self, space): - return space.wrap(self.softspace) - -def descr_setsoftspace(self, space, w_newvalue): - self.softspace = space.int_w(w_newvalue) - -common_descrs = { - '__iter__': interp2app(W_InputOutputType.descr___iter__), - '__next__': interp2app(W_InputOutputType.descr___next__), - 'close': interp2app(W_InputOutputType.descr_close), - 'flush': interp2app(W_InputOutputType.descr_flush), - 'getvalue': interp2app(W_InputOutputType.descr_getvalue), - 'isatty': interp2app(W_InputOutputType.descr_isatty), - 'read': interp2app(W_InputOutputType.descr_read), - 'readline': interp2app(W_InputOutputType.descr_readline), - 'readlines': interp2app(W_InputOutputType.descr_readlines), - 'reset': interp2app(W_InputOutputType.descr_reset), - 'seek': interp2app(W_InputOutputType.descr_seek), - 'tell': interp2app(W_InputOutputType.descr_tell), -} - -W_InputType.typedef = TypeDef( - "cStringIO.StringI", - __doc__ = "Simple type for treating strings as input file streams", - closed = GetSetProperty(descr_closed, cls=W_InputType), - softspace = GetSetProperty(descr_softspace, - descr_setsoftspace, - cls=W_InputType), - **common_descrs - # XXX CPython has the truncate() method here too, which is a bit strange - ) - -W_OutputType.typedef = TypeDef( - "cStringIO.StringO", - __doc__ = "Simple type for output to strings.", - truncate = interp2app(W_OutputType.descr_truncate), - write = interp2app(W_OutputType.descr_write), - writelines = interp2app(W_OutputType.descr_writelines), - closed = GetSetProperty(descr_closed, cls=W_OutputType), - softspace = GetSetProperty(descr_softspace, - descr_setsoftspace, - cls=W_OutputType), - **common_descrs - ) - -# ____________________________________________________________ - -def StringIO(space, w_string=None): - if space.is_w(w_string, space.w_None): - return space.wrap(W_OutputType(space)) - else: - string = space.bufferstr_w(w_string) - return space.wrap(W_InputType(space, string)) diff --git a/pypy/module/cStringIO/test/__init__.py b/pypy/module/cStringIO/test/__init__.py deleted file mode 100644 diff --git a/pypy/module/cStringIO/test/test_interp_stringio.py b/pypy/module/cStringIO/test/test_interp_stringio.py deleted file mode 100644 --- a/pypy/module/cStringIO/test/test_interp_stringio.py +++ /dev/null @@ -1,207 +0,0 @@ - -from pypy.conftest import gettestobjspace - -import os, sys, py - - -class AppTestcStringIO: - def setup_class(cls): - space = gettestobjspace(usemodules=('cStringIO',)) - cls.space = space - cls.w_write_many_expected_result = space.wrap(''.join( - [chr(i) for j in range(10) for i in range(253)])) - cls.w_StringIO = space.appexec([], """(): - import cStringIO - return cStringIO.StringIO - """) - - def test_simple(self): - f = self.StringIO() - f.write('hello') - f.write(' world') - assert f.getvalue() == 'hello world' - - def test_write_many(self): - f = self.StringIO() - for j in range(10): - for i in range(253): - f.write(chr(i)) - expected = ''.join([chr(i) for j in range(10) for i in range(253)]) - assert f.getvalue() == expected - - def test_seek(self): - f = self.StringIO() - f.write('0123') - f.write('456') - f.write('789') - f.seek(4) - f.write('AB') - assert f.getvalue() == '0123AB6789' - f.seek(-2, 2) - f.write('CDE') - assert f.getvalue() == '0123AB67CDE' - f.seek(2, 0) - f.seek(5, 1) - f.write('F') - assert f.getvalue() == '0123AB6FCDE' - - def test_write_beyond_end(self): - f = self.StringIO() - f.seek(20, 1) - assert f.tell() == 20 - f.write('X') - assert f.getvalue() == '\x00' * 20 + 'X' - - def test_tell(self): - f = self.StringIO() - f.write('0123') - f.write('456') - assert f.tell() == 7 - f.seek(2) - for i in range(3, 20): - f.write('X') - assert f.tell() == i - assert f.getvalue() == '01XXXXXXXXXXXXXXXXX' - - def test_read(self): - f = self.StringIO() - assert f.read() == '' - f.write('0123') - f.write('456') - assert f.read() == '' - assert f.read(5) == '' - assert f.tell() == 7 - f.seek(1) - assert f.read() == '123456' - assert f.tell() == 7 - f.seek(1) - assert f.read(12) == '123456' - assert f.tell() == 7 - f.seek(1) - assert f.read(2) == '12' - assert f.read(1) == '3' - assert f.tell() == 4 - f.seek(0) - assert f.read() == '0123456' - assert f.tell() == 7 - f.seek(0) - assert f.read(7) == '0123456' - assert f.tell() == 7 - f.seek(15) - assert f.read(2) == '' - assert f.tell() == 15 - - def test_reset(self): - f = self.StringIO() - f.write('foobar') - f.reset() - res = f.read() - assert res == 'foobar' - - def test_close(self): - f = self.StringIO() - assert not f.closed - f.close() - raises(ValueError, f.write, 'hello') - raises(ValueError, f.getvalue) - raises(ValueError, f.read, 0) - raises(ValueError, f.seek, 0) - assert f.closed - f.close() - assert f.closed - - def test_readline(self): - f = self.StringIO() - f.write('foo\nbar\nbaz') - f.seek(0) - assert f.readline() == 'foo\n' - assert f.readline(2) == 'ba' - assert f.readline() == 'r\n' - assert f.readline() == 'baz' - assert f.readline() == '' - f.seek(0) - assert iter(f) is f - assert list(f) == ['foo\n', 'bar\n', 'baz'] - f.write('\n') - f.seek(0) - assert iter(f) is f - assert list(f) == ['foo\n', 'bar\n', 'baz\n'] - f.seek(0) - assert f.readlines() == ['foo\n', 'bar\n', 'baz\n'] - f.seek(0) - assert f.readlines(2) == ['foo\n'] - - def test_misc(self): - f = self.StringIO() - f.flush() - assert f.isatty() is False - - def test_truncate(self): - f = self.StringIO() - f.truncate(20) - assert f.getvalue() == '' - assert f.tell() == 0 - f.write('\x00' * 20) - f.write('hello') - f.write(' world') - f.truncate(30) - assert f.getvalue() == '\x00' * 20 + 'hello worl' - f.truncate(25) - assert f.getvalue() == '\x00' * 20 + 'hello' - f.write('baz') - f.write('egg') - f.truncate(3) - assert f.tell() == 3 - assert f.getvalue() == '\x00' * 3 - raises(IOError, f.truncate, -1) - - def test_writelines(self): - f = self.StringIO() - f.writelines(['foo', 'bar', 'baz']) - assert f.getvalue() == 'foobarbaz' - - def test_stringi(self): - f = self.StringIO('hello world\nspam\n') - assert not hasattr(f, 'write') # it's a StringI - f.seek(3) - assert f.tell() == 3 - f.seek(50, 1) - assert f.tell() == 53 - f.seek(-3, 2) - assert f.tell() == 14 - assert f.read() == 'am\n' - f.seek(0) - assert f.readline() == 'hello world\n' - assert f.readline(4) == 'spam' - assert f.readline(400) == '\n' - f.reset() - assert f.readlines() == ['hello world\n', 'spam\n'] - f.seek(0, 0) - assert f.readlines(5) == ['hello world\n'] - f.seek(0) - assert list(f) == ['hello world\n', 'spam\n'] - - f.flush() - assert f.getvalue() == 'hello world\nspam\n' - assert f.isatty() is False - - assert not f.closed - f.close() - assert f.closed - raises(ValueError, f.flush) - raises(ValueError, f.getvalue) - raises(ValueError, f.isatty) - raises(ValueError, f.read) - raises(ValueError, f.readline) - raises(ValueError, f.readlines) - raises(ValueError, f.reset) - raises(ValueError, f.tell) - raises(ValueError, f.seek, 5) - assert f.closed - f.close() - assert f.closed - - def test_types(self): - import cStringIO - assert type(cStringIO.StringIO()) is cStringIO.OutputType - assert type(cStringIO.StringIO('')) is cStringIO.InputType diff --git a/pypy/module/cStringIO/test/test_ztranslation.py b/pypy/module/cStringIO/test/test_ztranslation.py deleted file mode 100644 --- a/pypy/module/cStringIO/test/test_ztranslation.py +++ /dev/null @@ -1,4 +0,0 @@ -from pypy.objspace.fake.checkmodule import checkmodule - -def test_checkmodule(): - checkmodule('cStringIO') diff --git a/pypy/module/test_lib_pypy/test_cstringio.py b/pypy/module/test_lib_pypy/test_cstringio.py deleted file mode 100644 --- a/pypy/module/test_lib_pypy/test_cstringio.py +++ /dev/null @@ -1,30 +0,0 @@ - -""" -Tests for the PyPy cStringIO implementation. -""" - -from pypy.conftest import gettestobjspace - -class AppTestcStringIO: - def setup_class(cls): - cls.space = gettestobjspace() - cls.w_io = cls.space.appexec([], "(): import cStringIO; return cStringIO") - cls.w_bytes = cls.space.wrap('some bytes') - - - def test_reset(self): - """ - Test that the reset method of cStringIO objects sets the position - marker to the beginning of the stream. - """ - io = self.io.StringIO() - io.write(self.bytes) - assert io.read() == '' - io.reset() - assert io.read() == self.bytes - - io = self.io.StringIO(self.bytes) - assert io.read() == self.bytes - assert io.read() == '' - io.reset() - assert io.read() == self.bytes _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit