Skip to content

Commit 6f376c4

Browse files
committed
Enable new I/O. Disable creation of old files.
Lots of stuff fails now, including -S and -m command line flags.
1 parent fa0054a commit 6f376c4

File tree

4 files changed

+11
-73
lines changed

4 files changed

+11
-73
lines changed

Lib/site.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,13 @@ def execsitecustomize():
403403

404404

405405
def installnewio():
406-
"""Install new I/O library as default.
407-
408-
This is only done if $PYTHONNEWIO is set and non-empty.
409-
"""
410-
if not os.getenv("PYTHONNEWIO"):
411-
return
406+
"""Install new I/O library as default."""
412407
import io
413408
# Trick so that open won't become a bound method when stored
414409
# as a class variable (as dumbdbm does)
415410
class open:
416411
def __new__(cls, *args, **kwds):
417412
return io.open(*args, **kwds)
418-
__builtin__.classic_open = __builtin__.open
419413
__builtin__.open = open
420414
sys.stdin = io.open(0, "r")
421415
sys.stdout = io.open(1, "w")

Objects/fileobject.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ open_the_file(PyFileObject *f, char *name, char *mode)
265265
PyObject *
266266
PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
267267
{
268+
PyErr_SetString(PyExc_SystemError,
269+
"attempt to create old file from FILE *");
270+
return NULL;
271+
#if 0
268272
PyFileObject *f = (PyFileObject *)PyFile_Type.tp_new(&PyFile_Type,
269273
NULL, NULL);
270274
if (f != NULL) {
@@ -278,6 +282,7 @@ PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
278282
Py_DECREF(o_name);
279283
}
280284
return (PyObject *) f;
285+
#endif
281286
}
282287

283288
PyObject *
@@ -1941,6 +1946,9 @@ file_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
19411946
PyObject *self;
19421947
static PyObject *not_yet_string;
19431948

1949+
PyErr_SetString(PyExc_SystemError, "attempt to create old file");
1950+
return NULL;
1951+
19441952
assert(type != NULL && type->tp_alloc != NULL);
19451953

19461954
if (not_yet_string == NULL) {

Python/bltinmodule.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,18 +1433,6 @@ PyDoc_STRVAR(oct_doc,
14331433
Return the octal representation of an integer or long integer.");
14341434

14351435

1436-
static PyObject *
1437-
builtin_open(PyObject *self, PyObject *args, PyObject *kwds)
1438-
{
1439-
return PyObject_Call((PyObject*)&PyFile_Type, args, kwds);
1440-
}
1441-
1442-
PyDoc_STRVAR(open_doc,
1443-
"open(name[, mode[, buffering]]) -> file object\n\
1444-
\n\
1445-
Open a file using the file() type, returns a file object.");
1446-
1447-
14481436
static PyObject *
14491437
builtin_ord(PyObject *self, PyObject* obj)
14501438
{
@@ -1464,7 +1452,7 @@ builtin_ord(PyObject *self, PyObject* obj)
14641452
ord = (long)*PyUnicode_AS_UNICODE(obj);
14651453
return PyInt_FromLong(ord);
14661454
}
1467-
}
1455+
}
14681456
else if (PyBytes_Check(obj)) {
14691457
/* XXX Hopefully this is temporary */
14701458
size = PyBytes_GET_SIZE(obj);
@@ -1963,7 +1951,6 @@ static PyMethodDef builtin_methods[] = {
19631951
{"min", (PyCFunction)builtin_min, METH_VARARGS | METH_KEYWORDS, min_doc},
19641952
{"next", (PyCFunction)builtin_next, METH_VARARGS, next_doc},
19651953
{"oct", builtin_oct, METH_O, oct_doc},
1966-
{"open", (PyCFunction)builtin_open, METH_VARARGS | METH_KEYWORDS, open_doc},
19671954
{"ord", builtin_ord, METH_O, ord_doc},
19681955
{"pow", builtin_pow, METH_VARARGS, pow_doc},
19691956
{"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc},

Python/sysmodule.c

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -960,13 +960,6 @@ settrace() -- set the global debug tracing function\n\
960960
)
961961
/* end of sys_doc */ ;
962962

963-
static int
964-
_check_and_flush (FILE *stream)
965-
{
966-
int prev_fail = ferror (stream);
967-
return fflush (stream) || prev_fail ? EOF : 0;
968-
}
969-
970963
/* Subversion branch and revision management */
971964
static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
972965
static const char headurl[] = "$HeadURL$";
@@ -1058,11 +1051,7 @@ PyObject *
10581051
_PySys_Init(void)
10591052
{
10601053
PyObject *m, *v, *sysdict;
1061-
PyObject *sysin, *sysout, *syserr;
10621054
char *s;
1063-
#ifdef MS_WINDOWS
1064-
char buf[128];
1065-
#endif
10661055

10671056
m = Py_InitModule3("sys", sys_methods, sys_doc);
10681057
if (m == NULL)
@@ -1081,52 +1070,12 @@ _PySys_Init(void)
10811070
}
10821071
}
10831072

1084-
/* Closing the standard FILE* if sys.std* goes aways causes problems
1085-
* for embedded Python usages. Closing them when somebody explicitly
1086-
* invokes .close() might be possible, but the FAQ promises they get
1087-
* never closed. However, we still need to get write errors when
1088-
* writing fails (e.g. because stdout is redirected), so we flush the
1089-
* streams and check for errors before the file objects are deleted.
1090-
* On OS X, fflush()ing stdin causes an error, so we exempt stdin
1091-
* from that procedure.
1092-
*/
1093-
sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
1094-
sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
1095-
syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
1096-
if (PyErr_Occurred())
1097-
return NULL;
1098-
#ifdef MS_WINDOWS
1099-
if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) {
1100-
sprintf(buf, "cp%d", GetConsoleCP());
1101-
if (!PyFile_SetEncoding(sysin, buf))
1102-
return NULL;
1103-
}
1104-
if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) {
1105-
sprintf(buf, "cp%d", GetConsoleOutputCP());
1106-
if (!PyFile_SetEncoding(sysout, buf))
1107-
return NULL;
1108-
}
1109-
if(isatty(_fileno(stderr)) && PyFile_Check(syserr)) {
1110-
sprintf(buf, "cp%d", GetConsoleOutputCP());
1111-
if (!PyFile_SetEncoding(syserr, buf))
1112-
return NULL;
1113-
}
1114-
#endif
1073+
/* stdin/stdout/stderr are now set by site.py. */
11151074

1116-
PyDict_SetItemString(sysdict, "stdin", sysin);
1117-
PyDict_SetItemString(sysdict, "stdout", sysout);
1118-
PyDict_SetItemString(sysdict, "stderr", syserr);
1119-
/* Make backup copies for cleanup */
1120-
PyDict_SetItemString(sysdict, "__stdin__", sysin);
1121-
PyDict_SetItemString(sysdict, "__stdout__", sysout);
1122-
PyDict_SetItemString(sysdict, "__stderr__", syserr);
11231075
PyDict_SetItemString(sysdict, "__displayhook__",
11241076
PyDict_GetItemString(sysdict, "displayhook"));
11251077
PyDict_SetItemString(sysdict, "__excepthook__",
11261078
PyDict_GetItemString(sysdict, "excepthook"));
1127-
Py_XDECREF(sysin);
1128-
Py_XDECREF(sysout);
1129-
Py_XDECREF(syserr);
11301079
PyDict_SetItemString(sysdict, "version",
11311080
v = PyString_FromString(Py_GetVersion()));
11321081
Py_XDECREF(v);

0 commit comments

Comments
 (0)