Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ec450d

Browse files
committed
make this work on 2.4
1 parent 6f75004 commit 4ec450d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

Parser/asdl_c.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#! /usr/bin/env python
22
"""Generate C code from an ASDL description."""
3-
from __future__ import with_statement
43

54
# TO DO
65
# handle fields that have a type but no name
76

7+
import errno
88
import os
99
import sys
1010
import StringIO
@@ -1170,11 +1170,23 @@ def main(srcfile):
11701170
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
11711171
f.write("int PyAST_Check(PyObject* obj);\n")
11721172
s = f.getvalue()
1173-
with open(p, "r") as fp:
1174-
write = fp.read() != s
1173+
write = True
1174+
try:
1175+
fp = open(p, "r")
1176+
except IOError as e:
1177+
if e.errno != errno.ENOENT:
1178+
raise
1179+
else:
1180+
try:
1181+
write = fp.read() != s
1182+
finally:
1183+
fp.close()
11751184
if write:
1176-
with open(p, "w") as fp:
1177-
f.write(s)
1185+
fp = open(p, "w")
1186+
try:
1187+
fp.write(s)
1188+
finally:
1189+
fp.close()
11781190

11791191
if SRC_DIR:
11801192
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")

0 commit comments

Comments
 (0)