mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-04 20:26:53 +00:00
Fix inconsistent newlines read from a file in python3
This commit is contained in:
parent
7801a17adc
commit
a42bfdf6d2
2 changed files with 29 additions and 6 deletions
|
|
@ -1,6 +1,5 @@
|
|||
"""Module containing our file processor that tokenizes a file for checks."""
|
||||
import contextlib
|
||||
import io
|
||||
import logging
|
||||
import sys
|
||||
import tokenize
|
||||
|
|
@ -308,11 +307,9 @@ class FileProcessor(object):
|
|||
def _readlines_py3(self):
|
||||
# type: () -> List[str]
|
||||
try:
|
||||
with open(self.filename, "rb") as fd:
|
||||
(coding, lines) = tokenize.detect_encoding(fd.readline)
|
||||
textfd = io.TextIOWrapper(fd, coding, line_buffering=True)
|
||||
return [l.decode(coding) for l in lines] + textfd.readlines()
|
||||
except (LookupError, SyntaxError, UnicodeError):
|
||||
with tokenize.open(self.filename) as fd:
|
||||
return fd.readlines()
|
||||
except (SyntaxError, UnicodeError):
|
||||
# If we can't detect the codec with tokenize.detect_encoding, or
|
||||
# the detected encoding is incorrect, just fallback to latin-1.
|
||||
with open(self.filename, encoding="latin-1") as fd:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue