| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,7 +209,6 @@ def __init__(self, files=None, inplace=False, backup="", bufsize=0, | |||
| 209 | 209 | self._startlineno = 0 | |
| 210 | 210 | self._filelineno = 0 | |
| 211 | 211 | self._file = None | |
| 212 | - self._readline = self._start_readline | ||
| 213 | 212 | self._isstdin = False | |
| 214 | 213 | self._backupfilename = None | |
| 215 | 214 | # restrict mode argument to reading modes | |
@@ -247,15 +246,15 @@ def __iter__(self): | |||
| 247 | 246 | return self | |
| 248 | 247 | ||
| 249 | 248 | def __next__(self): | |
| 250 | - line = self._readline() | ||
| 251 | - if line: | ||
| 252 | - self._filelineno += 1 | ||
| 253 | - return line | ||
| 254 | - if not self._file: | ||
| 255 | - raise StopIteration | ||
| 256 | - self.nextfile() | ||
| 257 | - # Recursive call | ||
| 258 | - return self.__next__() | ||
| 249 | + while True: | ||
| 250 | + line = self._readline() | ||
| 251 | + if line: | ||
| 252 | + self._filelineno += 1 | ||
| 253 | + return line | ||
| 254 | + if not self._file: | ||
| 255 | + raise StopIteration | ||
| 256 | + self.nextfile() | ||
| 257 | + # repeat with next file | ||
| 259 | 258 | ||
| 260 | 259 | def __getitem__(self, i): | |
| 261 | 260 | if i != self.lineno(): | |
@@ -279,7 +278,10 @@ def nextfile(self): | |||
| 279 | 278 | finally: | |
| 280 | 279 | file = self._file | |
| 281 | 280 | self._file = None | |
| 282 | - self._readline = self._start_readline | ||
| 281 | + try: | ||
| 282 | + del self._readline # restore FileInput._readline | ||
| 283 | + except AttributeError: | ||
| 284 | + pass | ||
| 283 | 285 | try: | |
| 284 | 286 | if file and not self._isstdin: | |
| 285 | 287 | file.close() | |
@@ -303,7 +305,7 @@ def readline(self): | |||
| 303 | 305 | self.nextfile() | |
| 304 | 306 | # repeat with next file | |
| 305 | 307 | ||
| 306 | - def _start_readline(self): | ||
| 308 | + def _readline(self): | ||
| 307 | 309 | if not self._files: | |
| 308 | 310 | if 'b' in self._mode: | |
| 309 | 311 | return b'' | |
@@ -358,7 +360,7 @@ def _start_readline(self): | |||
| 358 | 360 | self._file = self._openhook(self._filename, self._mode) | |
| 359 | 361 | else: | |
| 360 | 362 | self._file = open(self._filename, self._mode) | |
| 361 | - self._readline = self._file.readline | ||
| 363 | + self._readline = self._file.readline # hide FileInput._readline | ||
| 362 | 364 | return self._readline() | |
| 363 | 365 | ||
| 364 | 366 | def filename(self): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments