Commit 94fc39cb authored by Vinay Sajip's avatar Vinay Sajip

Fixed some resource leaks.

--HG--
branch : distribute
extra : source : 98c929e25fee11a99eb125dd9a13521321d68dd3
parent e3f7235a
......@@ -78,10 +78,14 @@ else:
globs = globals()
if locs is None:
locs = globs
exec_(compile(open(fn).read(), fn, 'exec'), globs, locs)
f = open(fn)
try:
source = f.read()
finally:
f.close()
exec_(compile(source, fn, 'exec'), globs, locs)
def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
......@@ -51,6 +51,7 @@ class IndexServer(HTTPServer):
# ignore any errors; all that's important is the request
pass
self.thread.join()
self.socket.close()
def base_url(self):
port = self.server_port
......
......@@ -89,8 +89,16 @@ class TestDevelopTest(unittest.TestCase):
self.assertEqual(content, ['easy-install.pth', 'foo.egg-link'])
# Check that we are using the right code.
path = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt').read().split()[0].strip()
init = open(os.path.join(path, 'foo', '__init__.py'), 'rt').read().strip()
f = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt')
try:
path = f.read().split()[0].strip()
finally:
f.close()
f = open(os.path.join(path, 'foo', '__init__.py'), 'rt')
try:
init = f.read().strip()
finally:
f.close()
if sys.version < "3":
self.assertEqual(init, 'print "foo"')
else:
......@@ -112,4 +120,3 @@ class TestDevelopTest(unittest.TestCase):
pass
finally:
os.chdir(old_dir)
......@@ -50,7 +50,9 @@ class TestDistInfo(unittest.TestCase):
versioned = os.path.join(self.tmpdir,
'VersionedDistribution-2.718.dist-info')
os.mkdir(versioned)
open(os.path.join(versioned, 'METADATA'), 'w+').write(DALS(
f = open(os.path.join(versioned, 'METADATA'), 'w+')
try:
f.write(DALS(
"""
Metadata-Version: 1.2
Name: VersionedDistribution
......@@ -58,11 +60,14 @@ class TestDistInfo(unittest.TestCase):
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""))
finally:
f.close()
unversioned = os.path.join(self.tmpdir,
'UnversionedDistribution.dist-info')
os.mkdir(unversioned)
open(os.path.join(unversioned, 'METADATA'), 'w+').write(DALS(
f = open(os.path.join(unversioned, 'METADATA'), 'w+')
try:
f.write(DALS(
"""
Metadata-Version: 1.2
Name: UnversionedDistribution
......@@ -71,6 +76,8 @@ class TestDistInfo(unittest.TestCase):
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""))
finally:
f.close()
def tearDown(self):
shutil.rmtree(self.tmpdir)
......@@ -233,7 +233,7 @@ class TestUserInstallTest(unittest.TestCase):
f = open(egg_file, 'w')
try:
f.write('Name: foo\n')
except:
finally:
f.close()
sys.path.append(target)
......
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