Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 19894:51cc82605d32 legacy-trunk
SF bug [#460467] file objects should be subclassable.
Preliminary support. What's here works, but needs fine-tuning.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Thu, 13 Sep 2001 05:38:56 +0000 |
| parents | 4abfc176685c |
| children | de39956b5458 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Thu Sep 13 01:29:13 2001 +0000 +++ b/Python/bltinmodule.c Thu Sep 13 05:38:56 2001 +0000 @@ -1192,31 +1192,20 @@ static PyObject * builtin_open(PyObject *self, PyObject *args) { - char *name = NULL; - char *mode = "r"; - int bufsize = -1; - PyObject *f; - - if (!PyArg_ParseTuple(args, "et|si:open", Py_FileSystemDefaultEncoding, - &name, &mode, &bufsize)) - return NULL; - f = PyFile_FromString(name, mode); - PyMem_Free(name); /* free the encoded string */ - if (f != NULL) - PyFile_SetBufSize(f, bufsize); - return f; + return PyFile_Type.tp_new(&PyFile_Type, args, NULL); } +/* XXX Keep this in synch with file_doc in fileobject.c. */ static char open_doc[] = -"open(filename[, mode[, buffering]]) -> file object\n\ -\n\ -Open a file. The mode can be 'r', 'w' or 'a' for reading (default),\n\ -writing or appending. The file will be created if it doesn't exist\n\ -when opened for writing or appending; it will be truncated when\n\ -opened for writing. Add a 'b' to the mode for binary files.\n\ -Add a '+' to the mode to allow simultaneous reading and writing.\n\ -If the buffering argument is given, 0 means unbuffered, 1 means line\n\ -buffered, and larger numbers specify the buffer size."; +"open(name[, mode[, buffering]]) -> file object\n" +"\n" +"Open a file. The mode can be 'r', 'w' or 'a' for reading (default),\n" +"writing or appending. The file will be created if it doesn't exist\n" +"when opened for writing or appending; it will be truncated when\n" +"opened for writing. Add a 'b' to the mode for binary files.\n" +"Add a '+' to the mode to allow simultaneous reading and writing.\n" +"If the buffering argument is given, 0 means unbuffered, 1 means line\n" +"buffered, and larger numbers specify the buffer size."; static PyObject * @@ -1894,6 +1883,8 @@ return NULL; if (PyDict_SetItemString(dict, "type", (PyObject *) &PyType_Type) < 0) return NULL; + if (PyDict_SetItemString(dict, "file", (PyObject *) &PyFile_Type) < 0) + return NULL; #ifdef Py_USING_UNICODE if (PyDict_SetItemString(dict, "unicode", (PyObject *) &PyUnicode_Type) < 0)
