| OLD | NEW |
| 1 """Helper class to quickly write a loop over all standard input files. | 1 """Helper class to quickly write a loop over all standard input files. |
| 2 | 2 |
| 3 Typical use is: | 3 Typical use is: |
| 4 | 4 |
| 5 import fileinput | 5 import fileinput |
| 6 for line in fileinput.input(): | 6 for line in fileinput.input(): |
| 7 process(line) | 7 process(line) |
| 8 | 8 |
| 9 This iterates over the lines of all files listed in sys.argv[1:], | 9 This iterates over the lines of all files listed in sys.argv[1:], |
| 10 defaulting to sys.stdin if the list is empty. If a filename is '-' it | 10 defaulting to sys.stdin if the list is empty. If a filename is '-' it |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 self._filelineno = 0 | 217 self._filelineno = 0 |
| 218 self._file = None | 218 self._file = None |
| 219 self._isstdin = False | 219 self._isstdin = False |
| 220 self._backupfilename = None | 220 self._backupfilename = None |
| 221 self._buffer = [] | 221 self._buffer = [] |
| 222 self._bufindex = 0 | 222 self._bufindex = 0 |
| 223 # restrict mode argument to reading modes | 223 # restrict mode argument to reading modes |
| 224 if mode not in ('r', 'rU', 'U', 'rb'): | 224 if mode not in ('r', 'rU', 'U', 'rb'): |
| 225 raise ValueError("FileInput opening mode must be one of " | 225 raise ValueError("FileInput opening mode must be one of " |
| 226 "'r', 'rU', 'U' and 'rb'") | 226 "'r', 'rU', 'U' and 'rb'") |
| 227 if 'U' in mode: |
| 228 warnings.warn("Use of 'U' mode is deprecated", |
| 229 DeprecationWarning) |
| 227 self._mode = mode | 230 self._mode = mode |
| 228 if openhook: | 231 if openhook: |
| 229 if inplace: | 232 if inplace: |
| 230 raise ValueError("FileInput cannot use an opening hook in inplac
e mode") | 233 raise ValueError("FileInput cannot use an opening hook in inplac
e mode") |
| 231 if not callable(openhook): | 234 if not callable(openhook): |
| 232 raise ValueError("FileInput openhook must be callable") | 235 raise ValueError("FileInput openhook must be callable") |
| 233 self._openhook = openhook | 236 self._openhook = openhook |
| 234 | 237 |
| 235 def __del__(self): | 238 def __del__(self): |
| 236 self.close() | 239 self.close() |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 if o == '-b': backup = a | 416 if o == '-b': backup = a |
| 414 for line in input(args, inplace=inplace, backup=backup): | 417 for line in input(args, inplace=inplace, backup=backup): |
| 415 if line[-1:] == '\n': line = line[:-1] | 418 if line[-1:] == '\n': line = line[:-1] |
| 416 if line[-1:] == '\r': line = line[:-1] | 419 if line[-1:] == '\r': line = line[:-1] |
| 417 print("%d: %s[%d]%s %s" % (lineno(), filename(), filelineno(), | 420 print("%d: %s[%d]%s %s" % (lineno(), filename(), filelineno(), |
| 418 isfirstline() and "*" or "", line)) | 421 isfirstline() and "*" or "", line)) |
| 419 print("%d: %s[%d]" % (lineno(), filename(), filelineno())) | 422 print("%d: %s[%d]" % (lineno(), filename(), filelineno())) |
| 420 | 423 |
| 421 if __name__ == '__main__': | 424 if __name__ == '__main__': |
| 422 _test() | 425 _test() |
| OLD | NEW |