summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-08-09 23:38:57 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-08-09 23:38:57 (GMT)
commit4ec450d3c7fa320fbdd5abf8843137b52a8a6614 (patch)
tree7f6ab4628f082aa64de5677f0708c8441a5b91b6 /Parser
parent6f7500424c098ea0a463986de9369f6c9711ec3c (diff)
downloadcpython-4ec450d3c7fa320fbdd5abf8843137b52a8a6614.zip
cpython-4ec450d3c7fa320fbdd5abf8843137b52a8a6614.tar.gz
cpython-4ec450d3c7fa320fbdd5abf8843137b52a8a6614.tar.bz2
make this work on 2.4
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index b4c31c3..ce8425a 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -1,10 +1,10 @@
#! /usr/bin/env python
"""Generate C code from an ASDL description."""
-from __future__ import with_statement
# TO DO
# handle fields that have a type but no name
+import errno
import os
import sys
import StringIO
@@ -1170,11 +1170,23 @@ def main(srcfile):
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
f.write("int PyAST_Check(PyObject* obj);\n")
s = f.getvalue()
- with open(p, "r") as fp:
- write = fp.read() != s
+ write = True
+ try:
+ fp = open(p, "r")
+ except IOError as e:
+ if e.errno != errno.ENOENT:
+ raise
+ else:
+ try:
+ write = fp.read() != s
+ finally:
+ fp.close()
if write:
- with open(p, "w") as fp:
- f.write(s)
+ fp = open(p, "w")
+ try:
+ fp.write(s)
+ finally:
+ fp.close()
if SRC_DIR:
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")