summaryrefslogtreecommitdiff
path: root/Modules/_io/_iomodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/_iomodule.c')
-rw-r--r--Modules/_io/_iomodule.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 4a7e758cda..be0464c4fa 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -126,8 +126,7 @@ PyDoc_STRVAR(open_doc,
"'b' binary mode\n"
"'t' text mode (default)\n"
"'+' open a disk file for updating (reading and writing)\n"
-"'U' universal newline mode (for backwards compatibility; unneeded\n"
-" for new code)\n"
+"'U' universal newline mode (deprecated)\n"
"========= ===============================================================\n"
"\n"
"The default mode is 'rt' (open for reading text). For binary random\n"
@@ -143,6 +142,10 @@ PyDoc_STRVAR(open_doc,
"returned as strings, the bytes having been first decoded using a\n"
"platform-dependent encoding or using the specified encoding if given.\n"
"\n"
+"'U' mode is deprecated and will raise an exception in future versions\n"
+"of Python. It has no effect in Python 3. Use newline to control\n"
+"universal newlines mode.\n"
+"\n"
"buffering is an optional integer used to set the buffering policy.\n"
"Pass 0 to switch buffering off (only allowed in binary mode), 1 to select\n"
"line buffering (only usable in text mode), and an integer > 1 to indicate\n"
@@ -310,6 +313,9 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
"can't use U and writing mode at once");
return NULL;
}
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "'U' mode is deprecated", 1) < 0)
+ return NULL;
reading = 1;
}
@@ -533,6 +539,45 @@ _PyIO_ConvertSsize_t(PyObject *obj, void *result) {
}
+_PyIO_State *
+_PyIO_get_module_state(void)
+{
+ PyObject *mod = PyState_FindModule(&_PyIO_Module);
+ _PyIO_State *state;
+ if (mod == NULL || (state = IO_MOD_STATE(mod)) == NULL) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "could not find io module state "
+ "(interpreter shutdown?)");
+ return NULL;
+ }
+ return state;
+}
+
+PyObject *
+_PyIO_get_locale_module(_PyIO_State *state)
+{
+ PyObject *mod;
+ if (state->locale_module != NULL) {
+ assert(PyWeakref_CheckRef(state->locale_module));
+ mod = PyWeakref_GET_OBJECT(state->locale_module);
+ if (mod != Py_None) {
+ Py_INCREF(mod);
+ return mod;
+ }
+ Py_CLEAR(state->locale_module);
+ }
+ mod = PyImport_ImportModule("_bootlocale");
+ if (mod == NULL)
+ return NULL;
+ state->locale_module = PyWeakref_NewRef(mod, NULL);
+ if (state->locale_module == NULL) {
+ Py_DECREF(mod);
+ return NULL;
+ }
+ return mod;
+}
+
+
static int
iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
_PyIO_State *state = IO_MOD_STATE(mod);