diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-13 05:38:56 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-13 05:38:56 (GMT) |
commit | 59c9a645e2f44b0b546225678d704787d9eae35d (patch) | |
tree | 56179a5250e747d330a93b4f5fe66eeb65859329 /Python | |
parent | 93a696f49171c0593b23817bbf56ab44269a9587 (diff) | |
download | cpython-59c9a645e2f44b0b546225678d704787d9eae35d.zip cpython-59c9a645e2f44b0b546225678d704787d9eae35d.tar.gz cpython-59c9a645e2f44b0b546225678d704787d9eae35d.tar.bz2 |
SF bug [#460467] file objects should be subclassable.
Preliminary support. What's here works, but needs fine-tuning.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 2d8c024..ea9ae63 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1192,31 +1192,20 @@ Return the octal representation of an integer or long integer."; 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 @@ _PyBuiltin_Init(void) 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) |