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
......
...@@ -43,7 +43,7 @@ class TestDevelopTest(unittest.TestCase): ...@@ -43,7 +43,7 @@ class TestDevelopTest(unittest.TestCase):
f = open(init, 'w') f = open(init, 'w')
f.write(INIT_PY) f.write(INIT_PY)
f.close() f.close()
os.chdir(self.dir) os.chdir(self.dir)
self.old_base = site.USER_BASE self.old_base = site.USER_BASE
site.USER_BASE = tempfile.mkdtemp() site.USER_BASE = tempfile.mkdtemp()
...@@ -53,7 +53,7 @@ class TestDevelopTest(unittest.TestCase): ...@@ -53,7 +53,7 @@ class TestDevelopTest(unittest.TestCase):
def tearDown(self): def tearDown(self):
if sys.version < "2.6" or hasattr(sys, 'real_prefix'): if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
return return
os.chdir(self.old_cwd) os.chdir(self.old_cwd)
shutil.rmtree(self.dir) shutil.rmtree(self.dir)
shutil.rmtree(site.USER_BASE) shutil.rmtree(site.USER_BASE)
...@@ -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,27 +50,34 @@ class TestDistInfo(unittest.TestCase): ...@@ -50,27 +50,34 @@ 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:
Metadata-Version: 1.2 f.write(DALS(
Name: VersionedDistribution """
Requires-Dist: splort (4) Metadata-Version: 1.2
Provides-Extra: baz Name: VersionedDistribution
Requires-Dist: quux (>=1.1); extra == 'baz' Requires-Dist: splort (4)
""")) Provides-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:
Metadata-Version: 1.2 f.write(DALS(
Name: UnversionedDistribution """
Version: 0.3 Metadata-Version: 1.2
Requires-Dist: splort (==4) Name: UnversionedDistribution
Provides-Extra: baz Version: 0.3
Requires-Dist: quux (>=1.1); extra == 'baz' Requires-Dist: splort (==4)
""")) Provides-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