summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/command
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-19 13:51:27 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-19 13:51:27 (GMT)
commit21a9c748aa8698c8201e30a58320d587f6bb7540 (patch)
treeddfcb60a800bc010237ee750a449c4639e5515e3 /Lib/packaging/command
parent0e3f3a70760f5ef1c0d1f7baf55046514b6bfbb6 (diff)
downloadcpython-21a9c748aa8698c8201e30a58320d587f6bb7540.zip
cpython-21a9c748aa8698c8201e30a58320d587f6bb7540.tar.gz
cpython-21a9c748aa8698c8201e30a58320d587f6bb7540.tar.bz2
packaging: use with open() instead of try/finally: close
Diffstat (limited to 'Lib/packaging/command')
-rw-r--r--Lib/packaging/command/config.py38
-rw-r--r--Lib/packaging/command/upload_docs.py15
2 files changed, 25 insertions, 28 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
diff --git a/Lib/packaging/command/upload_docs.py b/Lib/packaging/command/upload_docs.py
index 29ea6e9..47e6217 100644
--- a/Lib/packaging/command/upload_docs.py
+++ b/Lib/packaging/command/upload_docs.py
@@ -18,14 +18,13 @@ from packaging.command.cmd import Command
def zip_dir(directory):
"""Compresses recursively contents of directory into a BytesIO object"""
destination = BytesIO()
- zip_file = zipfile.ZipFile(destination, "w")
- for root, dirs, files in os.walk(directory):
- for name in files:
- full = os.path.join(root, name)
- relative = root[len(directory):].lstrip(os.path.sep)
- dest = os.path.join(relative, name)
- zip_file.write(full, dest)
- zip_file.close()
+ with zipfile.ZipFile(destination, "w") as zip_file:
+ for root, dirs, files in os.walk(directory):
+ for name in files:
+ full = os.path.join(root, name)
+ relative = root[len(directory):].lstrip(os.path.sep)
+ dest = os.path.join(relative, name)
+ zip_file.write(full, dest)
return destination