diff options
| author | Anthony Sottile <asottile@umich.edu> | 2017-09-17 16:15:11 -0700 |
|---|---|---|
| committer | Ashley Whetter <AWhetter@users.noreply.github.com> | 2017-09-17 16:15:11 -0700 |
| commit | 2ed15ba61572844ecd2abfa8217a85d39678424e (patch) | |
| tree | d666f0518a7f425b2450e27e7019f4c0babcb031 /pylint/utils.py | |
| parent | 172cbaa0e2b7ca8c390ebd9e872746141c966b77 (diff) | |
| download | pylint-git-2ed15ba61572844ecd2abfa8217a85d39678424e.tar.gz | |
Use codecs.getreader. (#1658)
* Use codecs.getreader.
* Test decoding_stream and _decoding_readline
Diffstat (limited to 'pylint/utils.py')
| -rw-r--r-- | pylint/utils.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pylint/utils.py b/pylint/utils.py index 94f03781d..4ad04d6cd 100644 --- a/pylint/utils.py +++ b/pylint/utils.py @@ -15,6 +15,7 @@ main pylint class """ from __future__ import print_function +import codecs import collections from inspect import cleandoc import os @@ -125,9 +126,17 @@ def safe_decode(line, encoding, *args, **kwargs): except LookupError: return line.decode(sys.getdefaultencoding(), *args, **kwargs) +def decoding_stream(stream, encoding, errors='strict'): + try: + reader_cls = codecs.getreader(encoding or sys.getdefaultencoding()) + except LookupError: + reader_cls = codecs.getreader(sys.getdefaultencoding()) + return reader_cls(stream, errors) + + def _decoding_readline(stream, encoding): '''return lambda function for tokenize with safe decode''' - return lambda: safe_decode(stream.readline(), encoding, 'replace') + return decoding_stream(stream, encoding, errors='replace').readline def tokenize_module(module): |
