diff options
author | Phil Frost <indigo@bitglue.com> | 2014-11-28 10:44:14 -0500 |
---|---|---|
committer | Phil Frost <indigo@bitglue.com> | 2014-11-28 10:58:17 -0500 |
commit | 7f840f38e91045c3a255eaa8d61e1853d768ffac (patch) | |
tree | f86ffbdf100ffc04eae5a7adf9855f679e538544 | |
parent | 8f47ab1887399f6df0a9173efa8ffb87447140bb (diff) | |
download | pyflakes-7f840f38e91045c3a255eaa8d61e1853d768ffac.tar.gz |
Use universal newlines only on python 2.6
Resolves lp:1397266
-rw-r--r-- | pyflakes/api.py | 11 | ||||
-rw-r--r-- | pyflakes/test/test_api.py | 7 |
2 files changed, 17 insertions, 1 deletions
diff --git a/pyflakes/api.py b/pyflakes/api.py index 3f3899a..379fc20 100644 --- a/pyflakes/api.py +++ b/pyflakes/api.py @@ -73,7 +73,16 @@ def checkPath(filename, reporter=None): if reporter is None: reporter = modReporter._makeDefaultReporter() try: - with open(filename, 'r') as f: + # in Python 2.6, compile() will choke on \r\n line endings. In later + # versions of python it's smarter, and we want binary mode to give + # compile() the best opportunity to do the right thing WRT text + # encodings. + if sys.version_info < (2, 7): + mode = 'rU' + else: + mode = 'rb' + + with open(filename, mode) as f: codestr = f.read() if sys.version_info < (2, 7): codestr += '\n' # Work around for Python <= 2.6 diff --git a/pyflakes/test/test_api.py b/pyflakes/test/test_api.py index f82ac62..ad61983 100644 --- a/pyflakes/test/test_api.py +++ b/pyflakes/test/test_api.py @@ -449,6 +449,13 @@ x = "%s" sourcePath = self.makeTempFile(source) self.assertHasErrors(sourcePath, []) + def test_CRLFLineEndings(self): + """ + Source files with Windows CR LF line endings are parsed successfully. + """ + sourcePath = self.makeTempFile("x = 42\r\n") + self.assertHasErrors(sourcePath, []) + def test_misencodedFileUTF8(self): """ If a source file contains bytes which cannot be decoded, this is |