[Python-checkins] r68554 - in sandbox/trunk/io-c: _textio.c test_io.py
antoine.pitrou
python-checkins at python.org
Mon Jan 12 21:51:33 CET 2009
Author: antoine.pitrou
Date: Mon Jan 12 21:51:32 2009
New Revision: 68554
Log:
Add a writable _CHUNK_SIZE attribute to TextIOWrapper so that we can run more of test_io.py
Modified:
sandbox/trunk/io-c/_textio.c
sandbox/trunk/io-c/test_io.py
Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c (original)
+++ sandbox/trunk/io-c/_textio.c Mon Jan 12 21:51:32 2009
@@ -695,6 +695,13 @@
return NULL; \
}
+#define CHECK_INITIALIZED_INT(self) \
+ if (self->ok <= 0) { \
+ PyErr_SetString(PyExc_ValueError, \
+ "I/O operation on uninitialized object"); \
+ return -1; \
+ }
+
Py_LOCAL_INLINE(const Py_UNICODE *)
findchar(const Py_UNICODE *s, Py_ssize_t size, Py_UNICODE ch)
@@ -1857,6 +1864,31 @@
return res;
}
+static PyObject *
+TextIOWrapper_chunk_size_get(PyTextIOWrapperObject *self, void *context)
+{
+ CHECK_INITIALIZED(self);
+ return PyLong_FromSsize_t(self->chunk_size);
+}
+
+static int
+TextIOWrapper_chunk_size_set(PyTextIOWrapperObject *self,
+ PyObject *arg, void *context)
+{
+ Py_ssize_t n;
+ CHECK_INITIALIZED_INT(self);
+ n = PyNumber_AsSsize_t(arg, PyExc_TypeError);
+ if (n == -1 && PyErr_Occurred())
+ return -1;
+ if (n <= 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "a strictly positive integer is required");
+ return -1;
+ }
+ self->chunk_size = n;
+ return 0;
+}
+
static PyMethodDef TextIOWrapper_methods[] = {
{"write", (PyCFunction)TextIOWrapper_write, METH_VARARGS},
{"read", (PyCFunction)TextIOWrapper_read, METH_VARARGS},
@@ -1892,6 +1924,8 @@
/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
*/
{"newlines", (getter)TextIOWrapper_newlines_get, NULL, NULL},
+ {"_CHUNK_SIZE", (getter)TextIOWrapper_chunk_size_get,
+ (setter)TextIOWrapper_chunk_size_set, NULL},
{0}
};
Modified: sandbox/trunk/io-c/test_io.py
==============================================================================
--- sandbox/trunk/io-c/test_io.py (original)
+++ sandbox/trunk/io-c/test_io.py Mon Jan 12 21:51:32 2009
@@ -15,6 +15,12 @@
import io # The module under test
+def _default_chunk_size():
+ """Get the default TextIOWrapper chunk size"""
+ with open(__file__, "r", encoding="latin1") as f:
+ return f._CHUNK_SIZE
+
+
class MockRawIO(io.RawIOBase):
def __init__(self, read_stack=()):
@@ -1332,7 +1338,7 @@
f.close()
def testSeeking(self):
- chunk_size = io.TextIOWrapper._CHUNK_SIZE
+ chunk_size = _default_chunk_size()
prefix_size = chunk_size - 2
u_prefix = "a" * prefix_size
prefix = bytes(u_prefix.encode("utf-8"))
@@ -1394,7 +1400,7 @@
testSeekAndTellWithData(input)
# Position each test case so that it crosses a chunk boundary.
- CHUNK_SIZE = io.TextIOWrapper._CHUNK_SIZE
+ CHUNK_SIZE = _default_chunk_size()
for input, _, _ in StatefulIncrementalDecoderTest.test_cases:
offset = CHUNK_SIZE - len(input)//2
prefix = b'.'*offset
More information about the Python-checkins
mailing list