summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/pgen2
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2011-10-07 18:44:49 (GMT)
committerBarry Warsaw <barry@python.org>2011-10-07 18:44:49 (GMT)
commit78f89d8c38e2c71c5e6a89a32022626a1d8d8922 (patch)
tree3e7f22261a5bd71fd56a2774c25ecf7c9651055d /Lib/lib2to3/pgen2
parent7b847a46bca22797fcb3149d5e52627fc439ba18 (diff)
downloadcpython-78f89d8c38e2c71c5e6a89a32022626a1d8d8922.zip
cpython-78f89d8c38e2c71c5e6a89a32022626a1d8d8922.tar.gz
cpython-78f89d8c38e2c71c5e6a89a32022626a1d8d8922.tar.bz2
- Issue #11250: Back port fix from 3.3 branch, so that 2to3 can handle files
with line feeds. This was ported from the sandbox to the 3.3 branch, but didn't make it into 3.2. - Re-enable lib2to3's test_parser.py tests, though with an expected failure (see issue 13125).
Diffstat (limited to 'Lib/lib2to3/pgen2')
-rw-r--r--Lib/lib2to3/pgen2/driver.py11
1 files changed, 2 insertions, 9 deletions
diff --git a/Lib/lib2to3/pgen2/driver.py b/Lib/lib2to3/pgen2/driver.py
index ee77a13..e7828ff 100644
--- a/Lib/lib2to3/pgen2/driver.py
+++ b/Lib/lib2to3/pgen2/driver.py
@@ -17,6 +17,7 @@ __all__ = ["Driver", "load_grammar"]
# Python imports
import codecs
+import io
import os
import logging
import sys
@@ -101,18 +102,10 @@ class Driver(object):
def parse_string(self, text, debug=False):
"""Parse a string and return the syntax tree."""
- tokens = tokenize.generate_tokens(generate_lines(text).__next__)
+ tokens = tokenize.generate_tokens(io.StringIO(text).readline)
return self.parse_tokens(tokens, debug)
-def generate_lines(text):
- """Generator that behaves like readline without using StringIO."""
- for line in text.splitlines(True):
- yield line
- while True:
- yield ""
-
-
def load_grammar(gt="Grammar.txt", gp=None,
save=True, force=False, logger=None):
"""Load the grammar (maybe from a pickle)."""