| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -315,7 +315,10 @@ def readline(self): | |||
| 315 | 315 | return line | |
| 316 | 316 | if not self._file: | |
| 317 | 317 | if not self._files: | |
| 318 | - return "" | ||
| 318 | + if 'b' in self._mode: | ||
| 319 | + return b'' | ||
| 320 | + else: | ||
| 321 | + return '' | ||
| 319 | 322 | self._filename = self._files[0] | |
| 320 | 323 | self._files = self._files[1:] | |
| 321 | 324 | self._filelineno = 0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -288,6 +288,21 @@ def test_readline(self): | |||
| 288 | 288 | with self.assertRaises(UnicodeDecodeError): | |
| 289 | 289 | # Read to the end of file. | |
| 290 | 290 | list(fi) | |
| 291 | + self.assertEqual(fi.readline(), '') | ||
| 292 | + self.assertEqual(fi.readline(), '') | ||
| 293 | + | ||
| 294 | + def test_readline_binary_mode(self): | ||
| 295 | + with open(TESTFN, 'wb') as f: | ||
| 296 | + f.write(b'A\nB\r\nC\rD') | ||
| 297 | + self.addCleanup(safe_unlink, TESTFN) | ||
| 298 | + | ||
| 299 | + with FileInput(files=TESTFN, mode='rb') as fi: | ||
| 300 | + self.assertEqual(fi.readline(), b'A\n') | ||
| 301 | + self.assertEqual(fi.readline(), b'B\r\n') | ||
| 302 | + self.assertEqual(fi.readline(), b'C\rD') | ||
| 303 | + # Read to the end of file. | ||
| 304 | + self.assertEqual(fi.readline(), b'') | ||
| 305 | + self.assertEqual(fi.readline(), b'') | ||
| 291 | 306 | ||
| 292 | 307 | def test_context_manager(self): | |
| 293 | 308 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,6 +48,10 @@ Core and Builtins | |||
| 48 | 48 | Library | |
| 49 | 49 | ------- | |
| 50 | 50 | ||
| 51 | + - Issue #25510: fileinput.FileInput.readline() now returns b'' instead of '' | ||
| 52 | + at the end if the FileInput was opened with binary mode. | ||
| 53 | + Patch by Ryosuke Ito. | ||
| 54 | + | ||
| 51 | 55 | - Issue #25503: Fixed inspect.getdoc() for inherited docstrings of properties. | |
| 52 | 56 | Original patch by John Mark Vandenberg. | |
| 53 | 57 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments