summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/pgen2/driver.py
diff options
context:
space:
mode:
authorGregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org>2016-09-08 00:40:07 (GMT)
committerGregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org>2016-09-08 00:40:07 (GMT)
commitdd1c638b92ae1552207451c82ed95aa2c1f07201 (patch)
tree17c9785172126ca63631dc9207380ff7ac583671 /Lib/lib2to3/pgen2/driver.py
parentd61910c598876788c9b4bf0e116370bbfc5a2f85 (diff)
downloadcpython-dd1c638b92ae1552207451c82ed95aa2c1f07201.zip
cpython-dd1c638b92ae1552207451c82ed95aa2c1f07201.tar.gz
cpython-dd1c638b92ae1552207451c82ed95aa2c1f07201.tar.bz2
lib2to3.pgen3.driver.load_grammar() now creates a stable cache file
between runs given the same Grammar.txt input regardless of the hash randomization setting.
Diffstat (limited to 'Lib/lib2to3/pgen2/driver.py')
-rw-r--r--Lib/lib2to3/pgen2/driver.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/lib2to3/pgen2/driver.py b/Lib/lib2to3/pgen2/driver.py
index 3ccc69d..a27b9cb 100644
--- a/Lib/lib2to3/pgen2/driver.py
+++ b/Lib/lib2to3/pgen2/driver.py
@@ -106,16 +106,19 @@ class Driver(object):
return self.parse_tokens(tokens, debug)
+def _generate_pickle_name(gt):
+ head, tail = os.path.splitext(gt)
+ if tail == ".txt":
+ tail = ""
+ return head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
+
+
def load_grammar(gt="Grammar.txt", gp=None,
save=True, force=False, logger=None):
"""Load the grammar (maybe from a pickle)."""
if logger is None:
logger = logging.getLogger()
- if gp is None:
- head, tail = os.path.splitext(gt)
- if tail == ".txt":
- tail = ""
- gp = head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
+ gp = _generate_pickle_name(gt) if gp is None else gp
if force or not _newer(gp, gt):
logger.info("Generating grammar tables from %s", gt)
g = pgen.generate_grammar(gt)
@@ -124,7 +127,7 @@ def load_grammar(gt="Grammar.txt", gp=None,
try:
g.dump(gp)
except OSError as e:
- logger.info("Writing failed:"+str(e))
+ logger.info("Writing failed: %s", e)
else:
g = grammar.Grammar()
g.load(gp)