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