| OLD | NEW |
| 1 # pylint: disable=W0511 | 1 # pylint: disable=W0511 |
| 2 # This program is free software; you can redistribute it and/or modify it under | 2 # This program is free software; you can redistribute it and/or modify it under |
| 3 # the terms of the GNU General Public License as published by the Free Software | 3 # the terms of the GNU General Public License as published by the Free Software |
| 4 # Foundation; either version 2 of the License, or (at your option) any later | 4 # Foundation; either version 2 of the License, or (at your option) any later |
| 5 # version. | 5 # version. |
| 6 # | 6 # |
| 7 # This program is distributed in the hope that it will be useful, but WITHOUT | 7 # This program is distributed in the hope that it will be useful, but WITHOUT |
| 8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 10 # | 10 # |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 try: | 75 try: |
| 76 return six.text_type(line, file_encoding) | 76 return six.text_type(line, file_encoding) |
| 77 except UnicodeDecodeError as ex: | 77 except UnicodeDecodeError as ex: |
| 78 self.add_message('invalid-encoded-data', line=lineno, | 78 self.add_message('invalid-encoded-data', line=lineno, |
| 79 args=(file_encoding, ex.args[2])) | 79 args=(file_encoding, ex.args[2])) |
| 80 | 80 |
| 81 def process_module(self, module): | 81 def process_module(self, module): |
| 82 """inspect the source file to find encoding problem or fixmes like | 82 """inspect the source file to find encoding problem or fixmes like |
| 83 notes | 83 notes |
| 84 """ | 84 """ |
| 85 stream = module.file_stream | |
| 86 stream.seek(0) # XXX may be removed with astroid > 0.23 | |
| 87 if self.config.notes: | 85 if self.config.notes: |
| 88 notes = re.compile( | 86 notes = re.compile( |
| 89 r'.*?#\s*(%s)(:*\s*.+)' % "|".join(self.config.notes)) | 87 r'.*?#\s*(%s)(:*\s*.+)' % "|".join(self.config.notes)) |
| 90 else: | 88 else: |
| 91 notes = None | 89 notes = None |
| 92 if module.file_encoding: | 90 if module.file_encoding: |
| 93 encoding = module.file_encoding | 91 encoding = module.file_encoding |
| 94 else: | 92 else: |
| 95 encoding = 'ascii' | 93 encoding = 'ascii' |
| 96 | 94 |
| 97 for lineno, line in enumerate(stream): | 95 with module.stream() as stream: |
| 98 line = self._check_encoding(lineno + 1, line, encoding) | 96 for lineno, line in enumerate(stream): |
| 99 if line is not None and notes: | 97 line = self._check_encoding(lineno + 1, line, encoding) |
| 100 self._check_note(notes, lineno + 1, line) | 98 if line is not None and notes: |
| 99 self._check_note(notes, lineno + 1, line) |
| 101 | 100 |
| 102 | 101 |
| 103 def register(linter): | 102 def register(linter): |
| 104 """required method to auto register this checker""" | 103 """required method to auto register this checker""" |
| 105 linter.register_checker(EncodingChecker(linter)) | 104 linter.register_checker(EncodingChecker(linter)) |
| OLD | NEW |