FileInput([files[, inplace[, backup]]], *, mode=None, openhook=None) Class FileInput is the implementation of the module; its methods filename(), lineno(), fileline(), isfirstline(), isstdin(), fileno(), nextfile() and close() correspond to the functions of the same name in the modu
| 169 | return _state.isstdin() |
| 170 | |
| 171 | class FileInput: |
| 172 | """FileInput([files[, inplace[, backup]]], *, mode=None, openhook=None) |
| 173 | |
| 174 | Class FileInput is the implementation of the module; its methods |
| 175 | filename(), lineno(), fileline(), isfirstline(), isstdin(), fileno(), |
| 176 | nextfile() and close() correspond to the functions of the same name |
| 177 | in the module. |
| 178 | In addition it has a readline() method which returns the next |
| 179 | input line, and a __getitem__() method which implements the |
| 180 | sequence behavior. The sequence must be accessed in strictly |
| 181 | sequential order; random access and readline() cannot be mixed. |
| 182 | """ |
| 183 | |
| 184 | def __init__(self, files=None, inplace=False, backup="", *, |
| 185 | mode="r", openhook=None, encoding=None, errors=None): |
| 186 | if isinstance(files, str): |
| 187 | files = (files,) |
| 188 | elif isinstance(files, os.PathLike): |
| 189 | files = (os.fspath(files), ) |
| 190 | else: |
| 191 | if files is None: |
| 192 | files = sys.argv[1:] |
| 193 | if not files: |
| 194 | files = ('-',) |
| 195 | else: |
| 196 | files = tuple(files) |
| 197 | self._files = files |
| 198 | self._inplace = inplace |
| 199 | self._backup = backup |
| 200 | self._savestdout = None |
| 201 | self._output = None |
| 202 | self._filename = None |
| 203 | self._startlineno = 0 |
| 204 | self._filelineno = 0 |
| 205 | self._file = None |
| 206 | self._isstdin = False |
| 207 | self._backupfilename = None |
| 208 | self._encoding = encoding |
| 209 | self._errors = errors |
| 210 | |
| 211 | # We can not use io.text_encoding() here because old openhook doesn't |
| 212 | # take encoding parameter. |
| 213 | if (sys.flags.warn_default_encoding and |
| 214 | "b" not in mode and encoding is None and openhook is None): |
| 215 | import warnings |
| 216 | warnings.warn("'encoding' argument not specified.", |
| 217 | EncodingWarning, 2) |
| 218 | |
| 219 | # restrict mode argument to reading modes |
| 220 | if mode not in ('r', 'rb'): |
| 221 | raise ValueError("FileInput opening mode must be 'r' or 'rb'") |
| 222 | self._mode = mode |
| 223 | self._write_mode = mode.replace('r', 'w') |
| 224 | if openhook: |
| 225 | if inplace: |
| 226 | raise ValueError("FileInput cannot use an opening hook in inplace mode") |
| 227 | if not callable(openhook): |
| 228 | raise ValueError("FileInput openhook must be callable") |
no outgoing calls
searching dependent graphs…