summaryrefslogtreecommitdiff
path: root/giscanner/scannermain.py
diff options
context:
space:
mode:
authorDieter Verfaillie <dieterv@optionexplicit.be>2015-07-05 10:54:16 +0200
committerEmmanuele Bassi <ebassi@gnome.org>2015-08-21 13:03:01 +0100
commitebe658542217c510f186dfc68956d51528d81fd6 (patch)
treec55847c5418430a9b4e509713bb487f358545820 /giscanner/scannermain.py
parent23e5dd8d6821e269feec3346c5f95c390a4ff009 (diff)
downloadgobject-introspection-ebe658542217c510f186dfc68956d51528d81fd6.tar.gz
scanner: use open() as os.fdopen as context managers
Ensures files are correctly and immediately closed. https://bugzilla.gnome.org/show_bug.cgi?id=751926
Diffstat (limited to 'giscanner/scannermain.py')
-rwxr-xr-xgiscanner/scannermain.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index fdc432d6..89ec1937 100755
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -322,8 +322,8 @@ def extract_filelist(options):
filenames = []
if not os.path.exists(options.filelist):
_error('%s: no such filelist file' % (options.filelist, ))
- filelist_file = open(options.filelist, "r")
- lines = filelist_file.readlines()
+ with open(options.filelist, "r") as filelist_file:
+ lines = filelist_file.readlines()
for line in lines:
# We don't support real C++ parsing yet, but we should be able
# to understand C API implemented in C++ files.
@@ -443,14 +443,12 @@ def write_output(data, options):
output = sys.stdout
elif options.reparse_validate_gir:
main_f, main_f_name = tempfile.mkstemp(suffix='.gir')
- main_f = os.fdopen(main_f, 'w')
- main_f.write(data)
- main_f.close()
+ with os.fdopen(main_f, 'w') as main_f:
+ main_f.write(data)
temp_f, temp_f_name = tempfile.mkstemp(suffix='.gir')
- temp_f = os.fdopen(temp_f, 'w')
- passthrough_gir(main_f_name, temp_f)
- temp_f.close()
+ with os.fdopen(temp_f, 'w') as temp_f:
+ passthrough_gir(main_f_name, temp_f)
if not utils.files_are_identical(main_f_name, temp_f_name):
_error("Failed to re-parse gir file; scanned=%r passthrough=%r" % (
main_f_name, temp_f_name))