diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
commit | 46ba6c8563922f043cad6423202ee0119614c807 (patch) | |
tree | 4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/sre_constants.py | |
parent | ae2d667ae83548029fed7244619fadd7f625cb24 (diff) | |
download | cpython-46ba6c8563922f043cad6423202ee0119614c807.zip cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.gz cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.bz2 |
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/sre_constants.py')
-rw-r--r-- | Lib/sre_constants.py | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/Lib/sre_constants.py b/Lib/sre_constants.py index 8b6bbfa..fc684ae 100644 --- a/Lib/sre_constants.py +++ b/Lib/sre_constants.py @@ -182,8 +182,8 @@ if __name__ == "__main__": items = sorted(d) for item in items: f.write("#define %s_%s %d\n" % (prefix, item, item)) - f = open("sre_constants.h", "w") - f.write("""\ + with open("sre_constants.h", "w") as f: + f.write("""\ /* * Secret Labs' Regular Expression Engine * @@ -199,25 +199,24 @@ if __name__ == "__main__": """) - f.write("#define SRE_MAGIC %d\n" % MAGIC) + f.write("#define SRE_MAGIC %d\n" % MAGIC) - dump(f, OPCODES, "SRE_OP") - dump(f, ATCODES, "SRE") - dump(f, CHCODES, "SRE") + dump(f, OPCODES, "SRE_OP") + dump(f, ATCODES, "SRE") + dump(f, CHCODES, "SRE") - f.write("#define SRE_FLAG_TEMPLATE %d\n" % SRE_FLAG_TEMPLATE) - f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE) - f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE) - f.write("#define SRE_FLAG_MULTILINE %d\n" % SRE_FLAG_MULTILINE) - f.write("#define SRE_FLAG_DOTALL %d\n" % SRE_FLAG_DOTALL) - f.write("#define SRE_FLAG_UNICODE %d\n" % SRE_FLAG_UNICODE) - f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE) - f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG) - f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII) + f.write("#define SRE_FLAG_TEMPLATE %d\n" % SRE_FLAG_TEMPLATE) + f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE) + f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE) + f.write("#define SRE_FLAG_MULTILINE %d\n" % SRE_FLAG_MULTILINE) + f.write("#define SRE_FLAG_DOTALL %d\n" % SRE_FLAG_DOTALL) + f.write("#define SRE_FLAG_UNICODE %d\n" % SRE_FLAG_UNICODE) + f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE) + f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG) + f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII) - f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX) - f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL) - f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET) + f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX) + f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL) + f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET) - f.close() print("done") |