diff options
author | Phil Frost <indigo@bitglue.com> | 2014-12-01 10:30:49 -0500 |
---|---|---|
committer | Phil Frost <indigo@bitglue.com> | 2014-12-01 10:30:49 -0500 |
commit | 8dd58c955cda639ae9155fd42b3c69eca47f5a6c (patch) | |
tree | f86ffbdf100ffc04eae5a7adf9855f679e538544 | |
parent | 9a0b6508b93620edb2a8648e3f7c91925439e169 (diff) | |
parent | 7f840f38e91045c3a255eaa8d61e1853d768ffac (diff) | |
download | pyflakes-8dd58c955cda639ae9155fd42b3c69eca47f5a6c.tar.gz |
Merge pull request #10 from bitglue/windows
Resolves lp:1397266 (CR LF line endings fail on Python 2.6)
-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 e8647f9..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, 'rb') 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 |