Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 61467) +++ Python/bltinmodule.c (working copy) @@ -777,7 +777,39 @@ The globals and locals are dictionaries, defaulting to the current\n\ globals and locals. If only globals is given, locals defaults to it."); +static PyObject * +builtin_file(PyObject *self, PyObject *args, PyObject *kwds) { + if (Py_Py3kWarningFlag && + PyErr_WarnEx(PyExc_DeprecationWarning, + "In 3.x, file has been removed.", 2) < 0) + return NULL; + return PyObject_Call((PyObject*)&PyFile_Type, args, kwds); +} +PyDoc_VAR(file_doc) = +PyDoc_STR( +"file(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. The preferred way\n" +"to open a file is with the builtin open() function.\n" +) +PyDoc_STR( +"Add a 'U' to mode to open the file for input with universal newline\n" +"support. Any line ending in the input file will be seen as a '\\n'\n" +"in Python. Also, a file so opened gains the attribute 'newlines';\n" +"the value for this attribute is one of None (no newline read yet),\n" +"'\\r', '\\n', '\\r\\n' or a tuple containing all the newline types seen.\n" +"\n" +"'U' cannot be combined with 'w' or '+' mode.\n" +); + + static PyObject * builtin_getattr(PyObject *self, PyObject *args) { @@ -2396,6 +2428,7 @@ {"eval", builtin_eval, METH_VARARGS, eval_doc}, {"execfile", builtin_execfile, METH_VARARGS, execfile_doc}, {"filter", builtin_filter, METH_VARARGS, filter_doc}, + {"file", (PyCFunction)builtin_file, METH_VARARGS, file_doc}, {"format", builtin_format, METH_VARARGS, format_doc}, {"getattr", builtin_getattr, METH_VARARGS, getattr_doc}, {"globals", (PyCFunction)builtin_globals, METH_NOARGS, globals_doc}, @@ -2482,7 +2515,6 @@ #endif SETBUILTIN("dict", &PyDict_Type); SETBUILTIN("enumerate", &PyEnum_Type); - SETBUILTIN("file", &PyFile_Type); SETBUILTIN("float", &PyFloat_Type); SETBUILTIN("frozenset", &PyFrozenSet_Type); SETBUILTIN("property", &PyProperty_Type); Index: Objects/fileobject.c =================================================================== --- Objects/fileobject.c (revision 61467) +++ Objects/fileobject.c (working copy) @@ -2055,29 +2055,6 @@ return ret; } -PyDoc_VAR(file_doc) = -PyDoc_STR( -"file(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. The preferred way\n" -"to open a file is with the builtin open() function.\n" -) -PyDoc_STR( -"Add a 'U' to mode to open the file for input with universal newline\n" -"support. Any line ending in the input file will be seen as a '\\n'\n" -"in Python. Also, a file so opened gains the attribute 'newlines';\n" -"the value for this attribute is one of None (no newline read yet),\n" -"'\\r', '\\n', '\\r\\n' or a tuple containing all the newline types seen.\n" -"\n" -"'U' cannot be combined with 'w' or '+' mode.\n" -); - PyTypeObject PyFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "file", @@ -2100,7 +2077,7 @@ PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ - file_doc, /* tp_doc */ + 0, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */