summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/command/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/packaging/command/config.py')
-rw-r--r--Lib/packaging/command/config.py38
1 files changed, 18 insertions, 20 deletions
diff --git a/Lib/packaging/command/config.py b/Lib/packaging/command/config.py
index a5feb91..264c139 100644
--- a/Lib/packaging/command/config.py
+++ b/Lib/packaging/command/config.py
@@ -110,15 +110,14 @@ class config(Command):
def _gen_temp_sourcefile(self, body, headers, lang):
filename = "_configtest" + LANG_EXT[lang]
- file = open(filename, "w")
- if headers:
- for header in headers:
- file.write("#include <%s>\n" % header)
- file.write("\n")
- file.write(body)
- if body[-1] != "\n":
- file.write("\n")
- file.close()
+ with open(filename, "w") as file:
+ if headers:
+ for header in headers:
+ file.write("#include <%s>\n" % header)
+ file.write("\n")
+ file.write(body)
+ if body[-1] != "\n":
+ file.write("\n")
return filename
def _preprocess(self, body, headers, include_dirs, lang):
@@ -207,17 +206,16 @@ class config(Command):
if isinstance(pattern, str):
pattern = re.compile(pattern)
- file = open(out)
- match = False
- while True:
- line = file.readline()
- if line == '':
- break
- if pattern.search(line):
- match = True
- break
-
- file.close()
+ with open(out) as file:
+ match = False
+ while True:
+ line = file.readline()
+ if line == '':
+ break
+ if pattern.search(line):
+ match = True
+ break
+
self._clean()
return match