| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -135,7 +135,7 @@ def updatecache(filename, module_globals=None): | |||
| 135 | 135 | try: | |
| 136 | 136 | with tokenize.open(fullname) as fp: | |
| 137 | 137 | lines = fp.readlines() | |
| 138 | - except OSError: | ||
| 138 | + except (OSError, UnicodeDecodeError, SyntaxError): | ||
| 139 | 139 | return [] | |
| 140 | 140 | if lines and not lines[-1].endswith('\n'): | |
| 141 | 141 | lines[-1] += '\n' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,12 +73,10 @@ class GetLineTestsBadData(TempFile): | |||
| 73 | 73 | # file_byte_string = b'Bad data goes here' | |
| 74 | 74 | ||
| 75 | 75 | def test_getline(self): | |
| 76 | - self.assertRaises((SyntaxError, UnicodeDecodeError), | ||
| 77 | - linecache.getline, self.file_name, 1) | ||
| 76 | + self.assertEqual(linecache.getline(self.file_name, 1), '') | ||
| 78 | 77 | ||
| 79 | 78 | def test_getlines(self): | |
| 80 | - self.assertRaises((SyntaxError, UnicodeDecodeError), | ||
| 81 | - linecache.getlines, self.file_name) | ||
| 79 | + self.assertEqual(linecache.getlines(self.file_name), []) | ||
| 82 | 80 | ||
| 83 | 81 | ||
| 84 | 82 | class EmptyFile(GetLineTestsGoodData, unittest.TestCase): | |
@@ -92,9 +90,11 @@ class SingleEmptyLine(GetLineTestsGoodData, unittest.TestCase): | |||
| 92 | 90 | class GoodUnicode(GetLineTestsGoodData, unittest.TestCase): | |
| 93 | 91 | file_list = ['á\n', 'b\n', 'abcdef\n', 'ááááá\n'] | |
| 94 | 92 | ||
| 93 | + class BadUnicode_NoDeclaration(GetLineTestsBadData, unittest.TestCase): | ||
| 94 | + file_byte_string = b'\n\x80abc' | ||
| 95 | 95 | ||
| 96 | - class BadUnicode(GetLineTestsBadData, unittest.TestCase): | ||
| 97 | - file_byte_string = b'\x80abc' | ||
| 96 | + class BadUnicode_WithDeclaration(GetLineTestsBadData, unittest.TestCase): | ||
| 97 | + file_byte_string = b'# coding=utf-8\n\x80abc' | ||
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | 100 | class LineCacheTests(unittest.TestCase): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Fix bug where :meth:`linecache.getline` fails on bad files with :exc:`UnicodeDecodeError` or :exc:`SyntaxError`. It now returns an empty string as per the documentation. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments