Commit f9f94d71 authored by Jason R. Coombs's avatar Jason R. Coombs

Use context manager

--HG--
extra : amend_source : 5e98bee2918d9eeb073c8c896a849c5f68da6634
parent 032cd636
......@@ -632,7 +632,7 @@ class PackageIndex(Environment):
shutil.copy2(filename, dst)
filename=dst
file = open(os.path.join(tmpdir, 'setup.py'), 'w')
with open(os.path.join(tmpdir, 'setup.py'), 'w') as file:
file.write(
"from setuptools import setup\n"
"setup(name=%r, version=%r, py_modules=[%r])\n"
......@@ -641,7 +641,6 @@ class PackageIndex(Environment):
os.path.splitext(basename)[0]
)
)
file.close()
return filename
elif match:
......@@ -660,7 +659,7 @@ class PackageIndex(Environment):
def _download_to(self, url, filename):
self.info("Downloading %s", url)
# Download the file
fp, tfp, info = None, None, None
fp, info = None, None
try:
checker = HashChecker.from_url(url)
fp = self.open_url(strip_fragment(url))
......@@ -677,7 +676,7 @@ class PackageIndex(Environment):
sizes = get_all_headers(headers, 'Content-Length')
size = max(map(int, sizes))
self.reporthook(url, filename, blocknum, bs, size)
tfp = open(filename,'wb')
with open(filename,'wb') as tfp:
while True:
block = fp.read(bs)
if block:
......@@ -691,7 +690,6 @@ class PackageIndex(Environment):
return headers
finally:
if fp: fp.close()
if tfp: tfp.close()
def reporthook(self, url, filename, blocknum, blksize, size):
pass # no-op
......@@ -1040,9 +1038,8 @@ def local_open(url):
files = []
for f in os.listdir(filename):
if f=='index.html':
fp = open(os.path.join(filename,f),'r')
with open(os.path.join(filename,f),'r') as fp:
body = fp.read()
fp.close()
break
elif os.path.isdir(os.path.join(filename,f)):
f+='/'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment