summaryrefslogtreecommitdiff
path: root/event_rpcgen.py
diff options
context:
space:
mode:
authorEnji Cooper <yaneurabeya@gmail.com>2020-03-26 17:37:09 -0700
committerEnji Cooper <yaneurabeya@gmail.com>2020-03-27 10:35:46 -0700
commitdc57672900eccf8688411459a93a516eb602024a (patch)
treea98c313b5bacefb6250666de3f820c0f77a22913 /event_rpcgen.py
parent7f115c17c0b4b7a3cdd3e07a24f933c8ab881b52 (diff)
downloadlibevent-dc57672900eccf8688411459a93a516eb602024a.tar.gz
Handle file pointers with context suite patterns
This removes the need for manually calling the file pointer's `.close` methods directly. Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
Diffstat (limited to 'event_rpcgen.py')
-rwxr-xr-xevent_rpcgen.py37
1 files changed, 17 insertions, 20 deletions
diff --git a/event_rpcgen.py b/event_rpcgen.py
index 14138836..ff8024fc 100755
--- a/event_rpcgen.py
+++ b/event_rpcgen.py
@@ -1689,32 +1689,29 @@ class CommandLine:
declare('Reading \"%s\"' % filename)
- fp = open(filename, 'r')
- entities = Parse(factory, fp)
- fp.close()
+ with open(filename, "r") as fp:
+ entities = Parse(factory, fp)
declare('... creating "%s"' % header_file)
- header_fp = open(header_file, 'w')
- header_fp.write(factory.HeaderPreamble(filename))
+ with open(header_file, "w") as header_fp:
+ header_fp.write(factory.HeaderPreamble(filename))
- # Create forward declarations: allows other structs to reference
- # each other
- for entry in entities:
- entry.PrintForwardDeclaration(header_fp)
- header_fp.write('\n')
+ # Create forward declarations: allows other structs to reference
+ # each other
+ for entry in entities:
+ entry.PrintForwardDeclaration(header_fp)
+ header_fp.write('\n')
- for entry in entities:
- entry.PrintTags(header_fp)
- entry.PrintDeclaration(header_fp)
- header_fp.write(factory.HeaderPostamble(filename))
- header_fp.close()
+ for entry in entities:
+ entry.PrintTags(header_fp)
+ entry.PrintDeclaration(header_fp)
+ header_fp.write(factory.HeaderPostamble(filename))
declare('... creating "%s"' % impl_file)
- impl_fp = open(impl_file, 'w')
- impl_fp.write(factory.BodyPreamble(filename, header_file))
- for entry in entities:
- entry.PrintCode(impl_fp)
- impl_fp.close()
+ with open(impl_file, "w") as impl_fp:
+ impl_fp.write(factory.BodyPreamble(filename, header_file))
+ for entry in entities:
+ entry.PrintCode(impl_fp)
def main(argv=None):