make this work on 2.4

This commit is contained in:
Benjamin Peterson 2011-08-09 18:38:57 -05:00
parent 6f7500424c
commit 4ec450d3c7
1 changed files with 17 additions and 5 deletions

View File

@ -1,10 +1,10 @@
#! /usr/bin/env python #! /usr/bin/env python
"""Generate C code from an ASDL description.""" """Generate C code from an ASDL description."""
from __future__ import with_statement
# TO DO # TO DO
# handle fields that have a type but no name # handle fields that have a type but no name
import errno
import os import os
import sys import sys
import StringIO import StringIO
@ -1170,11 +1170,23 @@ def main(srcfile):
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
f.write("int PyAST_Check(PyObject* obj);\n") f.write("int PyAST_Check(PyObject* obj);\n")
s = f.getvalue() s = f.getvalue()
with open(p, "r") as fp: write = True
write = fp.read() != s 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: if write:
with open(p, "w") as fp: fp = open(p, "w")
f.write(s) try:
fp.write(s)
finally:
fp.close()
if SRC_DIR: if SRC_DIR:
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c") p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")