[Python-checkins] r69812 - in python/branches/io-c: Lib/io.py Modules/Setup.dist Modules/_iomodule.h Modules/_stringio.c Modules/io.c
antoine.pitrou
python-checkins at python.org
Fri Feb 20 20:50:17 CET 2009
Author: antoine.pitrou
Date: Fri Feb 20 20:50:16 2009
New Revision: 69812
Log:
_StringIO now belongs to the _io modules, rather to its own _stringio module
Modified:
python/branches/io-c/Lib/io.py
python/branches/io-c/Modules/Setup.dist
python/branches/io-c/Modules/_iomodule.h
python/branches/io-c/Modules/_stringio.c
python/branches/io-c/Modules/io.c
Modified: python/branches/io-c/Lib/io.py
==============================================================================
--- python/branches/io-c/Lib/io.py (original)
+++ python/branches/io-c/Lib/io.py Fri Feb 20 20:50:16 2009
@@ -1872,18 +1872,16 @@
return self.buffer.getvalue().decode(self._encoding, self._errors)
try:
- import _stringio
-
# This subclass is a reimplementation of the TextIOWrapper
# interface without any of its text decoding facilities. All the
# stored data is manipulated with the efficient
- # _stringio._StringIO extension type. Also, the newline decoding
+ # _io._StringIO extension type. Also, the newline decoding
# mechanism of IncrementalNewlineDecoder is reimplemented here for
# efficiency. Doing otherwise, would require us to implement a
# fake decoder which would add an additional and unnecessary layer
# on top of the _StringIO methods.
- class StringIO(_stringio._StringIO, TextIOBase):
+ class StringIO(_io._StringIO, TextIOBase):
"""Text I/O implementation using an in-memory buffer.
The initial_value argument sets the value of object. The newline
@@ -1972,12 +1970,12 @@
def seekable(self):
return True
- _read = _stringio._StringIO.read
- _write = _stringio._StringIO.write
- _tell = _stringio._StringIO.tell
- _seek = _stringio._StringIO.seek
- _truncate = _stringio._StringIO.truncate
- _getvalue = _stringio._StringIO.getvalue
+ _read = _io._StringIO.read
+ _write = _io._StringIO.write
+ _tell = _io._StringIO.tell
+ _seek = _io._StringIO.seek
+ _truncate = _io._StringIO.truncate
+ _getvalue = _io._StringIO.getvalue
def getvalue(self) -> str:
"""Retrieve the entire contents of the object."""
Modified: python/branches/io-c/Modules/Setup.dist
==============================================================================
--- python/branches/io-c/Modules/Setup.dist (original)
+++ python/branches/io-c/Modules/Setup.dist Fri Feb 20 20:50:16 2009
@@ -114,8 +114,7 @@
_weakref _weakref.c # weak references
# Standard I/O baseline
-_io io.c _iobase.c _fileio.c _bytesio.c _bufferedio.c _textio.c
-_stringio _stringio.c
+_io io.c _iobase.c _fileio.c _bytesio.c _bufferedio.c _textio.c _stringio.c
# The zipimport module is always imported at startup. Having it as a
# builtin module avoids some bootstrapping problems and reduces overhead.
Modified: python/branches/io-c/Modules/_iomodule.h
==============================================================================
--- python/branches/io-c/Modules/_iomodule.h (original)
+++ python/branches/io-c/Modules/_iomodule.h Fri Feb 20 20:50:16 2009
@@ -11,6 +11,7 @@
/* Concrete classes */
extern PyTypeObject PyFileIO_Type;
extern PyTypeObject PyBytesIO_Type;
+extern PyTypeObject PyStringIO_Type;
extern PyTypeObject PyBufferedReader_Type;
extern PyTypeObject PyBufferedWriter_Type;
extern PyTypeObject PyBufferedRWPair_Type;
Modified: python/branches/io-c/Modules/_stringio.c
==============================================================================
--- python/branches/io-c/Modules/_stringio.c (original)
+++ python/branches/io-c/Modules/_stringio.c Fri Feb 20 20:50:16 2009
@@ -1,8 +1,6 @@
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
-
-/* This module is a stripped down version of _bytesio.c with a Py_UNICODE
- buffer. Most of the functionality is provided by subclassing _StringIO. */
-
+#include "_iomodule.h"
typedef struct {
PyObject_HEAD
@@ -313,9 +311,9 @@
{NULL, NULL} /* sentinel */
};
-static PyTypeObject StringIO_Type = {
+PyTypeObject PyStringIO_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "_stringio._StringIO", /*tp_name*/
+ "_StringIO", /*tp_name*/
sizeof(StringIOObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)stringio_dealloc, /*tp_dealloc*/
@@ -353,31 +351,3 @@
0, /*tp_alloc*/
stringio_new, /*tp_new*/
};
-
-static struct PyModuleDef _stringiomodule = {
- PyModuleDef_HEAD_INIT,
- "_stringio",
- NULL,
- -1,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-PyMODINIT_FUNC
-PyInit__stringio(void)
-{
- PyObject *m;
-
- if (PyType_Ready(&StringIO_Type) < 0)
- return NULL;
- m = PyModule_Create(&_stringiomodule);
- if (m == NULL)
- return NULL;
- Py_INCREF(&StringIO_Type);
- if (PyModule_AddObject(m, "_StringIO", (PyObject *)&StringIO_Type) < 0)
- return NULL;
- return m;
-}
Modified: python/branches/io-c/Modules/io.c
==============================================================================
--- python/branches/io-c/Modules/io.c (original)
+++ python/branches/io-c/Modules/io.c Fri Feb 20 20:50:16 2009
@@ -636,26 +636,39 @@
state->unsupported_operation);
/* BlockingIOError */
- base = (PyTypeObject *)PyExc_IOError;
- _PyExc_BlockingIOError.tp_base = base;
+ _PyExc_BlockingIOError.tp_base = (PyTypeObject *) PyExc_IOError;
if (PyType_Ready(&_PyExc_BlockingIOError) < 0)
goto fail;
Py_INCREF(&_PyExc_BlockingIOError);
PyModule_AddObject(m, "BlockingIOError",
(PyObject *)&_PyExc_BlockingIOError);
+ /* IOBase */
if (PyType_Ready(&PyIOBase_Type) < 0)
goto fail;
Py_INCREF(&PyIOBase_Type);
PyModule_AddObject(m, "IOBase",
(PyObject *)&PyIOBase_Type);
+ /* RawIOBase */
if (PyType_Ready(&PyRawIOBase_Type) < 0)
goto fail;
Py_INCREF(&PyRawIOBase_Type);
PyModule_AddObject(m, "RawIOBase",
(PyObject *)&PyRawIOBase_Type);
+ /* BufferedIOBase */
+ if (PyType_Ready(&PyBufferedIOBase_Type) < 0)
+ goto fail;
+ Py_INCREF(&PyBufferedIOBase_Type);
+ PyModule_AddObject(m, "BufferedIOBase", (PyObject *) &PyBufferedIOBase_Type);
+
+ /* TextIOBase */
+ if (PyType_Ready(&PyTextIOBase_Type) < 0)
+ goto fail;
+ Py_INCREF(&PyTextIOBase_Type);
+ PyModule_AddObject(m, "TextIOBase", (PyObject *) &PyTextIOBase_Type);
+
/* FileIO */
PyFileIO_Type.tp_base = &PyRawIOBase_Type;
if (PyType_Ready(&PyFileIO_Type) < 0)
@@ -663,12 +676,6 @@
Py_INCREF(&PyFileIO_Type);
PyModule_AddObject(m, "FileIO", (PyObject *) &PyFileIO_Type);
- /* BufferedIOBase */
- if (PyType_Ready(&PyBufferedIOBase_Type) < 0)
- goto fail;
- Py_INCREF(&PyBufferedIOBase_Type);
- PyModule_AddObject(m, "BufferedIOBase", (PyObject *) &PyBufferedIOBase_Type);
-
/* BytesIO */
PyBytesIO_Type.tp_base = &PyBufferedIOBase_Type;
if (PyType_Ready(&PyBytesIO_Type) < 0)
@@ -676,6 +683,13 @@
Py_INCREF(&PyBytesIO_Type);
PyModule_AddObject(m, "BytesIO", (PyObject *) &PyBytesIO_Type);
+ /* StringIO */
+ /* PyStringIO_Type.tp_base = &PyTextIOBase_Type; */
+ if (PyType_Ready(&PyStringIO_Type) < 0)
+ goto fail;
+ Py_INCREF(&PyStringIO_Type);
+ PyModule_AddObject(m, "_StringIO", (PyObject *) &PyStringIO_Type);
+
/* BufferedReader */
PyBufferedReader_Type.tp_base = &PyBufferedIOBase_Type;
if (PyType_Ready(&PyBufferedReader_Type) < 0)
@@ -704,12 +718,6 @@
Py_INCREF(&PyBufferedRandom_Type);
PyModule_AddObject(m, "BufferedRandom", (PyObject *) &PyBufferedRandom_Type);
- /* BufferedIOBase */
- if (PyType_Ready(&PyTextIOBase_Type) < 0)
- goto fail;
- Py_INCREF(&PyTextIOBase_Type);
- PyModule_AddObject(m, "TextIOBase", (PyObject *) &PyTextIOBase_Type);
-
/* TextIOWrapper */
PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type;
if (PyType_Ready(&PyTextIOWrapper_Type) < 0)
@@ -717,7 +725,7 @@
Py_INCREF(&PyTextIOWrapper_Type);
PyModule_AddObject(m, "TextIOWrapper", (PyObject *) &PyTextIOWrapper_Type);
- /* TextIOWrapper */
+ /* IncrementalNewlineDecoder */
if (PyType_Ready(&PyIncrementalNewlineDecoder_Type) < 0)
goto fail;
Py_INCREF(&PyIncrementalNewlineDecoder_Type);
More information about the Python-checkins
mailing list