| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 An implementation of the new I/O lib as defined by PEP 3116 - "New I/O" | 2 An implementation of the new I/O lib as defined by PEP 3116 - "New I/O" |
| 3 | 3 |
| 4 Classes defined here: UnsupportedOperation, BlockingIOError. | 4 Classes defined here: UnsupportedOperation, BlockingIOError. |
| 5 Functions defined here: open(). | 5 Functions defined here: open(). |
| 6 | 6 |
| 7 Mostly written by Amaury Forgeot d'Arc | 7 Mostly written by Amaury Forgeot d'Arc |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 #define PY_SSIZE_T_CLEAN | 10 #define PY_SSIZE_T_CLEAN |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 " I/O classes. open() uses the file's blksize (as obtained by os.stat) if\n" | 88 " I/O classes. open() uses the file's blksize (as obtained by os.stat) if\n" |
| 89 " possible.\n" | 89 " possible.\n" |
| 90 ); | 90 ); |
| 91 | 91 |
| 92 | 92 |
| 93 /* | 93 /* |
| 94 * The main open() function | 94 * The main open() function |
| 95 */ | 95 */ |
| 96 PyDoc_STRVAR(open_doc, | 96 PyDoc_STRVAR(open_doc, |
| 97 "open(file, mode='r', buffering=-1, encoding=None,\n" | 97 "open(file, mode='r', buffering=-1, encoding=None,\n" |
| 98 " errors=None, newline=None, closefd=True) -> file object\n" | 98 " errors=None, newline=None, closefd=True, opener=None) -> file object\n" |
| 99 "\n" | 99 "\n" |
| 100 "Open file and return a stream. Raise IOError upon failure.\n" | 100 "Open file and return a stream. Raise IOError upon failure.\n" |
| 101 "\n" | 101 "\n" |
| 102 "file is either a text or byte string giving the name (and the path\n" | 102 "file is either a text or byte string giving the name (and the path\n" |
| 103 "if the file isn't in the current working directory) of the file to\n" | 103 "if the file isn't in the current working directory) of the file to\n" |
| 104 "be opened or an integer file descriptor of the file to be\n" | 104 "be opened or an integer file descriptor of the file to be\n" |
| 105 "wrapped. (If a file descriptor is given, it is closed when the\n" | 105 "wrapped. (If a file descriptor is given, it is closed when the\n" |
| 106 "returned I/O object is closed, unless closefd is set to False.)\n" | 106 "returned I/O object is closed, unless closefd is set to False.)\n" |
| 107 "\n" | 107 "\n" |
| 108 "mode is an optional string that specifies the mode in which the file\n" | 108 "mode is an optional string that specifies the mode in which the file\n" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 "\n" | 182 "\n" |
| 183 "* On output, if newline is None, any '\\n' characters written are\n" | 183 "* On output, if newline is None, any '\\n' characters written are\n" |
| 184 " translated to the system default line separator, os.linesep. If\n" | 184 " translated to the system default line separator, os.linesep. If\n" |
| 185 " newline is '', no translation takes place. If newline is any of the\n" | 185 " newline is '', no translation takes place. If newline is any of the\n" |
| 186 " other legal values, any '\\n' characters written are translated to\n" | 186 " other legal values, any '\\n' characters written are translated to\n" |
| 187 " the given string.\n" | 187 " the given string.\n" |
| 188 "\n" | 188 "\n" |
| 189 "If closefd is False, the underlying file descriptor will be kept open\n" | 189 "If closefd is False, the underlying file descriptor will be kept open\n" |
| 190 "when the file is closed. This does not work when a file name is given\n" | 190 "when the file is closed. This does not work when a file name is given\n" |
| 191 "and must be True in that case.\n" | 191 "and must be True in that case.\n" |
| 192 "\n" |
| 193 "A custom opener can be used by passing a callable as *opener*. The\n" |
| 194 "underlying file descriptor for the file object is then obtained by\n" |
| 195 "calling *opener* with (*file*, *flags*). *opener* must return an open\n" |
| 196 "file descriptor (passing os.open as *opener* results in functionality\n" |
| 197 "similar to passing None).\n" |
| 192 "\n" | 198 "\n" |
| 193 "open() returns a file object whose type depends on the mode, and\n" | 199 "open() returns a file object whose type depends on the mode, and\n" |
| 194 "through which the standard file operations such as reading and writing\n" | 200 "through which the standard file operations such as reading and writing\n" |
| 195 "are performed. When open() is used to open a file in a text mode ('w',\n" | 201 "are performed. When open() is used to open a file in a text mode ('w',\n" |
| 196 "'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open\n" | 202 "'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open\n" |
| 197 "a file in a binary mode, the returned class varies: in read binary\n" | 203 "a file in a binary mode, the returned class varies: in read binary\n" |
| 198 "mode, it returns a BufferedReader; in write binary and append binary\n" | 204 "mode, it returns a BufferedReader; in write binary and append binary\n" |
| 199 "modes, it returns a BufferedWriter, and in read/write mode, it returns\n" | 205 "modes, it returns a BufferedWriter, and in read/write mode, it returns\n" |
| 200 "a BufferedRandom.\n" | 206 "a BufferedRandom.\n" |
| 201 "\n" | 207 "\n" |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 state->initialized = 1; | 729 state->initialized = 1; |
| 724 | 730 |
| 725 return m; | 731 return m; |
| 726 | 732 |
| 727 fail: | 733 fail: |
| 728 Py_XDECREF(state->os_module); | 734 Py_XDECREF(state->os_module); |
| 729 Py_XDECREF(state->unsupported_operation); | 735 Py_XDECREF(state->unsupported_operation); |
| 730 Py_DECREF(m); | 736 Py_DECREF(m); |
| 731 return NULL; | 737 return NULL; |
| 732 } | 738 } |
| LEFT | RIGHT |