diff options
author | Guido van Rossum <guido@python.org> | 2007-05-24 14:31:33 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-24 14:31:33 (GMT) |
commit | 6f376c40317e693c5eea0356fbb90d7394f21ff0 (patch) | |
tree | b787fddfb1173c1045d3c9e622b255754ab5eb49 | |
parent | fa0054aa732176a1f9b1c79cd20198f43cfed334 (diff) | |
download | cpython-6f376c40317e693c5eea0356fbb90d7394f21ff0.zip cpython-6f376c40317e693c5eea0356fbb90d7394f21ff0.tar.gz cpython-6f376c40317e693c5eea0356fbb90d7394f21ff0.tar.bz2 |
Enable new I/O. Disable creation of old files.
Lots of stuff fails now, including -S and -m command line flags.
-rw-r--r-- | Lib/site.py | 8 | ||||
-rw-r--r-- | Objects/fileobject.c | 8 | ||||
-rw-r--r-- | Python/bltinmodule.c | 15 | ||||
-rw-r--r-- | Python/sysmodule.c | 53 |
4 files changed, 11 insertions, 73 deletions
diff --git a/Lib/site.py b/Lib/site.py index 0871579..e00890e 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -403,19 +403,13 @@ def execsitecustomize(): def installnewio(): - """Install new I/O library as default. - - This is only done if $PYTHONNEWIO is set and non-empty. - """ - if not os.getenv("PYTHONNEWIO"): - return + """Install new I/O library as default.""" import io # Trick so that open won't become a bound method when stored # as a class variable (as dumbdbm does) class open: def __new__(cls, *args, **kwds): return io.open(*args, **kwds) - __builtin__.classic_open = __builtin__.open __builtin__.open = open sys.stdin = io.open(0, "r") sys.stdout = io.open(1, "w") diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 7c8e2b2..469eacd 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -265,6 +265,10 @@ cleanup: PyObject * PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *)) { + PyErr_SetString(PyExc_SystemError, + "attempt to create old file from FILE *"); + return NULL; +#if 0 PyFileObject *f = (PyFileObject *)PyFile_Type.tp_new(&PyFile_Type, NULL, NULL); if (f != NULL) { @@ -278,6 +282,7 @@ PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *)) Py_DECREF(o_name); } return (PyObject *) f; +#endif } PyObject * @@ -1941,6 +1946,9 @@ file_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyObject *self; static PyObject *not_yet_string; + PyErr_SetString(PyExc_SystemError, "attempt to create old file"); + return NULL; + assert(type != NULL && type->tp_alloc != NULL); if (not_yet_string == NULL) { diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 770023d..b292d16 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1434,18 +1434,6 @@ Return the octal representation of an integer or long integer."); static PyObject * -builtin_open(PyObject *self, PyObject *args, PyObject *kwds) -{ - return PyObject_Call((PyObject*)&PyFile_Type, args, kwds); -} - -PyDoc_STRVAR(open_doc, -"open(name[, mode[, buffering]]) -> file object\n\ -\n\ -Open a file using the file() type, returns a file object."); - - -static PyObject * builtin_ord(PyObject *self, PyObject* obj) { long ord; @@ -1464,7 +1452,7 @@ builtin_ord(PyObject *self, PyObject* obj) ord = (long)*PyUnicode_AS_UNICODE(obj); return PyInt_FromLong(ord); } - } + } else if (PyBytes_Check(obj)) { /* XXX Hopefully this is temporary */ size = PyBytes_GET_SIZE(obj); @@ -1963,7 +1951,6 @@ static PyMethodDef builtin_methods[] = { {"min", (PyCFunction)builtin_min, METH_VARARGS | METH_KEYWORDS, min_doc}, {"next", (PyCFunction)builtin_next, METH_VARARGS, next_doc}, {"oct", builtin_oct, METH_O, oct_doc}, - {"open", (PyCFunction)builtin_open, METH_VARARGS | METH_KEYWORDS, open_doc}, {"ord", builtin_ord, METH_O, ord_doc}, {"pow", builtin_pow, METH_VARARGS, pow_doc}, {"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc}, diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 247ec05..9eebc14 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -960,13 +960,6 @@ settrace() -- set the global debug tracing function\n\ ) /* end of sys_doc */ ; -static int -_check_and_flush (FILE *stream) -{ - int prev_fail = ferror (stream); - return fflush (stream) || prev_fail ? EOF : 0; -} - /* Subversion branch and revision management */ static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION; static const char headurl[] = "$HeadURL$"; @@ -1058,11 +1051,7 @@ PyObject * _PySys_Init(void) { PyObject *m, *v, *sysdict; - PyObject *sysin, *sysout, *syserr; char *s; -#ifdef MS_WINDOWS - char buf[128]; -#endif m = Py_InitModule3("sys", sys_methods, sys_doc); if (m == NULL) @@ -1081,52 +1070,12 @@ _PySys_Init(void) } } - /* Closing the standard FILE* if sys.std* goes aways causes problems - * for embedded Python usages. Closing them when somebody explicitly - * invokes .close() might be possible, but the FAQ promises they get - * never closed. However, we still need to get write errors when - * writing fails (e.g. because stdout is redirected), so we flush the - * streams and check for errors before the file objects are deleted. - * On OS X, fflush()ing stdin causes an error, so we exempt stdin - * from that procedure. - */ - sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); - sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush); - syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush); - if (PyErr_Occurred()) - return NULL; -#ifdef MS_WINDOWS - if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) { - sprintf(buf, "cp%d", GetConsoleCP()); - if (!PyFile_SetEncoding(sysin, buf)) - return NULL; - } - if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) { - sprintf(buf, "cp%d", GetConsoleOutputCP()); - if (!PyFile_SetEncoding(sysout, buf)) - return NULL; - } - if(isatty(_fileno(stderr)) && PyFile_Check(syserr)) { - sprintf(buf, "cp%d", GetConsoleOutputCP()); - if (!PyFile_SetEncoding(syserr, buf)) - return NULL; - } -#endif + /* stdin/stdout/stderr are now set by site.py. */ - PyDict_SetItemString(sysdict, "stdin", sysin); - PyDict_SetItemString(sysdict, "stdout", sysout); - PyDict_SetItemString(sysdict, "stderr", syserr); - /* Make backup copies for cleanup */ - PyDict_SetItemString(sysdict, "__stdin__", sysin); - PyDict_SetItemString(sysdict, "__stdout__", sysout); - PyDict_SetItemString(sysdict, "__stderr__", syserr); PyDict_SetItemString(sysdict, "__displayhook__", PyDict_GetItemString(sysdict, "displayhook")); PyDict_SetItemString(sysdict, "__excepthook__", PyDict_GetItemString(sysdict, "excepthook")); - Py_XDECREF(sysin); - Py_XDECREF(sysout); - Py_XDECREF(syserr); PyDict_SetItemString(sysdict, "version", v = PyString_FromString(Py_GetVersion())); Py_XDECREF(v); |