Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4300)

Unified Diff: Modules/_io/_iomodule.c

Issue 12797: io.FileIO and io.open should support openat
Patch Set: Created 1 year, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_io.py ('k') | Modules/_io/fileio.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -95,7 +95,7 @@
*/
PyDoc_STRVAR(open_doc,
"open(file, mode='r', buffering=-1, encoding=None,\n"
-" errors=None, newline=None, closefd=True) -> file object\n"
+" errors=None, newline=None, closefd=True, opener=None) -> file object\n"
"\n"
"Open file and return a stream. Raise IOError upon failure.\n"
"\n"
@@ -190,6 +190,12 @@
"when the file is closed. This does not work when a file name is given\n"
"and must be True in that case.\n"
"\n"
+"A custom opener can be used by passing a callable as *opener*. The\n"
+"underlying file descriptor for the file object is then obtained by\n"
+"calling *opener* with (*file*, *flags*). *opener* must return an open\n"
+"file descriptor (passing os.open as *opener* results in functionality\n"
+"similar to passing None).\n"
+"\n"
"open() returns a file object whose type depends on the mode, and\n"
"through which the standard file operations such as reading and writing\n"
"are performed. When open() is used to open a file in a text mode ('w',\n"
@@ -210,8 +216,8 @@
{
char *kwlist[] = {"file", "mode", "buffering",
"encoding", "errors", "newline",
- "closefd", NULL};
- PyObject *file;
+ "closefd", "opener", NULL};
+ PyObject *file, *opener = Py_None;
char *mode = "r";
int buffering = -1, closefd = 1;
char *encoding = NULL, *errors = NULL, *newline = NULL;
@@ -228,10 +234,10 @@
_Py_IDENTIFIER(isatty);
_Py_IDENTIFIER(fileno);
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzzi:open", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzziO:open", kwlist,
&file, &mode, &buffering,
&encoding, &errors, &newline,
- &closefd)) {
+ &closefd, &opener)) {
return NULL;
}
@@ -331,7 +337,7 @@
/* Create the Raw file stream */
raw = PyObject_CallFunction((PyObject *)&PyFileIO_Type,
- "Osi", file, rawmode, closefd);
+ "OsiO", file, rawmode, closefd, opener);
if (raw == NULL)
return NULL;
« no previous file with comments | « Lib/test/test_io.py ('k') | Modules/_io/fileio.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7