Commit 9d6a6e59 authored by Jason R. Coombs's avatar Jason R. Coombs

Use except/as, now supported by Python 2.6

parent a849ee95
...@@ -843,8 +843,7 @@ class WorkingSet(object): ...@@ -843,8 +843,7 @@ class WorkingSet(object):
try: try:
resolvees = shadow_set.resolve(req, env, installer) resolvees = shadow_set.resolve(req, env, installer)
except ResolutionError: except ResolutionError as v:
v = sys.exc_info()[1]
# save error info # save error info
error_info[dist] = v error_info[dist] = v
if fallback: if fallback:
...@@ -1340,8 +1339,8 @@ class MarkerEvaluation(object): ...@@ -1340,8 +1339,8 @@ class MarkerEvaluation(object):
""" """
try: try:
cls.evaluate_marker(text) cls.evaluate_marker(text)
except SyntaxError: except SyntaxError as e:
return cls.normalize_exception(sys.exc_info()[1]) return cls.normalize_exception(e)
return False return False
@staticmethod @staticmethod
...@@ -1456,8 +1455,7 @@ class MarkerEvaluation(object): ...@@ -1456,8 +1455,7 @@ class MarkerEvaluation(object):
env[new_key] = env.pop(key) env[new_key] = env.pop(key)
try: try:
result = _markerlib.interpret(text, env) result = _markerlib.interpret(text, env)
except NameError: except NameError as e:
e = sys.exc_info()[1]
raise SyntaxError(e.args[0]) raise SyntaxError(e.args[0])
return result return result
......
...@@ -698,13 +698,11 @@ Please make the appropriate changes for your system and try again. ...@@ -698,13 +698,11 @@ Please make the appropriate changes for your system and try again.
distros = WorkingSet([]).resolve( distros = WorkingSet([]).resolve(
[requirement], self.local_index, self.easy_install [requirement], self.local_index, self.easy_install
) )
except DistributionNotFound: except DistributionNotFound as e:
e = sys.exc_info()[1]
raise DistutilsError( raise DistutilsError(
"Could not find required distribution %s" % e.args "Could not find required distribution %s" % e.args
) )
except VersionConflict: except VersionConflict as e:
e = sys.exc_info()[1]
raise DistutilsError( raise DistutilsError(
"Installed distribution %s conflicts with requirement %s" "Installed distribution %s conflicts with requirement %s"
% e.args % e.args
...@@ -1044,8 +1042,7 @@ See the setuptools documentation for the "develop" command for more info. ...@@ -1044,8 +1042,7 @@ See the setuptools documentation for the "develop" command for more info.
) )
try: try:
run_setup(setup_script, args) run_setup(setup_script, args)
except SystemExit: except SystemExit as v:
v = sys.exc_info()[1]
raise DistutilsError("Setup script exited with %s" % (v.args[0],)) raise DistutilsError("Setup script exited with %s" % (v.args[0],))
def build_and_install(self, setup_script, setup_base): def build_and_install(self, setup_script, setup_base):
...@@ -1889,8 +1886,7 @@ def chmod(path, mode): ...@@ -1889,8 +1886,7 @@ def chmod(path, mode):
log.debug("changing mode of %s to %o", path, mode) log.debug("changing mode of %s to %o", path, mode)
try: try:
_chmod(path, mode) _chmod(path, mode)
except os.error: except os.error as e:
e = sys.exc_info()[1]
log.debug("chmod failed: %s", e) log.debug("chmod failed: %s", e)
......
...@@ -70,7 +70,8 @@ class sdist(orig.sdist): ...@@ -70,7 +70,8 @@ class sdist(orig.sdist):
try: try:
orig.sdist.read_template(self) orig.sdist.read_template(self)
except: except:
sys.exc_info()[2].tb_next.tb_frame.f_locals['template'].close() _, _, tb = sys.exc_info()
tb.tb_next.tb_frame.f_locals['template'].close()
raise raise
# Beginning with Python 2.7.2, 3.1.4, and 3.2.1, this leaky file handle # Beginning with Python 2.7.2, 3.1.4, and 3.2.1, this leaky file handle
......
...@@ -169,8 +169,7 @@ class upload_docs(upload): ...@@ -169,8 +169,7 @@ class upload_docs(upload):
conn.putheader('Authorization', auth) conn.putheader('Authorization', auth)
conn.endheaders() conn.endheaders()
conn.send(body) conn.send(body)
except socket.error: except socket.error as e:
e = sys.exc_info()[1]
self.announce(str(e), log.ERROR) self.announce(str(e), log.ERROR)
return return
......
...@@ -131,8 +131,7 @@ def check_entry_points(dist, attr, value): ...@@ -131,8 +131,7 @@ def check_entry_points(dist, attr, value):
"""Verify that entry_points map is parseable""" """Verify that entry_points map is parseable"""
try: try:
pkg_resources.EntryPoint.parse_map(value) pkg_resources.EntryPoint.parse_map(value)
except ValueError: except ValueError as e:
e = sys.exc_info()[1]
raise DistutilsSetupError(e) raise DistutilsSetupError(e)
def check_test_suite(dist, attr, value): def check_test_suite(dist, attr, value):
......
...@@ -50,8 +50,7 @@ def find_vcvarsall(version): ...@@ -50,8 +50,7 @@ def find_vcvarsall(version):
def query_vcvarsall(version, *args, **kwargs): def query_vcvarsall(version, *args, **kwargs):
try: try:
return unpatched['query_vcvarsall'](version, *args, **kwargs) return unpatched['query_vcvarsall'](version, *args, **kwargs)
except distutils.errors.DistutilsPlatformError: except distutils.errors.DistutilsPlatformError as exc:
exc = sys.exc_info()[1]
if exc and "vcvarsall.bat" in exc.args[0]: if exc and "vcvarsall.bat" in exc.args[0]:
message = 'Microsoft Visual C++ %0.1f is required (%s).' % (version, exc.args[0]) message = 'Microsoft Visual C++ %0.1f is required (%s).' % (version, exc.args[0])
if int(version) == 9: if int(version) == 9:
......
...@@ -699,25 +699,21 @@ class PackageIndex(Environment): ...@@ -699,25 +699,21 @@ class PackageIndex(Environment):
return local_open(url) return local_open(url)
try: try:
return open_with_auth(url, self.opener) return open_with_auth(url, self.opener)
except (ValueError, httplib.InvalidURL): except (ValueError, httplib.InvalidURL) as v:
v = sys.exc_info()[1]
msg = ' '.join([str(arg) for arg in v.args]) msg = ' '.join([str(arg) for arg in v.args])
if warning: if warning:
self.warn(warning, msg) self.warn(warning, msg)
else: else:
raise DistutilsError('%s %s' % (url, msg)) raise DistutilsError('%s %s' % (url, msg))
except urllib2.HTTPError: except urllib2.HTTPError as v:
v = sys.exc_info()[1]
return v return v
except urllib2.URLError: except urllib2.URLError as v:
v = sys.exc_info()[1]
if warning: if warning:
self.warn(warning, v.reason) self.warn(warning, v.reason)
else: else:
raise DistutilsError("Download error for %s: %s" raise DistutilsError("Download error for %s: %s"
% (url, v.reason)) % (url, v.reason))
except httplib.BadStatusLine: except httplib.BadStatusLine as v:
v = sys.exc_info()[1]
if warning: if warning:
self.warn(warning, v.line) self.warn(warning, v.line)
else: else:
...@@ -726,8 +722,7 @@ class PackageIndex(Environment): ...@@ -726,8 +722,7 @@ class PackageIndex(Environment):
'down, %s' % 'down, %s' %
(url, v.line) (url, v.line)
) )
except httplib.HTTPException: except httplib.HTTPException as v:
v = sys.exc_info()[1]
if warning: if warning:
self.warn(warning, v) self.warn(warning, v)
else: else:
......
...@@ -199,8 +199,7 @@ def run_setup(setup_script, args): ...@@ -199,8 +199,7 @@ def run_setup(setup_script, args):
ns = dict(__file__=setup_script, __name__='__main__') ns = dict(__file__=setup_script, __name__='__main__')
_execfile(setup_script, ns) _execfile(setup_script, ns)
DirectorySandbox(setup_dir).run(runner) DirectorySandbox(setup_dir).run(runner)
except SystemExit: except SystemExit as v:
v = sys.exc_info()[1]
if v.args and v.args[0]: if v.args and v.args[0]:
raise raise
# Normal exit, just return # Normal exit, just return
......
...@@ -15,8 +15,7 @@ class TestPackageIndex: ...@@ -15,8 +15,7 @@ class TestPackageIndex:
url = 'http://127.0.0.1:0/nonesuch/test_package_index' url = 'http://127.0.0.1:0/nonesuch/test_package_index'
try: try:
v = index.open_url(url) v = index.open_url(url)
except Exception: except Exception as v:
v = sys.exc_info()[1]
assert url in str(v) assert url in str(v)
else: else:
assert isinstance(v, HTTPError) assert isinstance(v, HTTPError)
...@@ -32,8 +31,7 @@ class TestPackageIndex: ...@@ -32,8 +31,7 @@ class TestPackageIndex:
url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk' url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk'
try: try:
v = index.open_url(url) v = index.open_url(url)
except Exception: except Exception as v:
v = sys.exc_info()[1]
assert url in str(v) assert url in str(v)
else: else:
assert isinstance(v, HTTPError) assert isinstance(v, HTTPError)
...@@ -50,8 +48,7 @@ class TestPackageIndex: ...@@ -50,8 +48,7 @@ class TestPackageIndex:
url = 'http://example.com' url = 'http://example.com'
try: try:
v = index.open_url(url) v = index.open_url(url)
except Exception: except Exception as v:
v = sys.exc_info()[1]
assert 'line' in str(v) assert 'line' in str(v)
else: else:
raise AssertionError('Should have raise here!') raise AssertionError('Should have raise here!')
...@@ -68,8 +65,7 @@ class TestPackageIndex: ...@@ -68,8 +65,7 @@ class TestPackageIndex:
url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk' url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk'
try: try:
index.open_url(url) index.open_url(url)
except distutils.errors.DistutilsError: except distutils.errors.DistutilsError as error:
error = sys.exc_info()[1]
msg = unicode(error) msg = unicode(error)
assert 'nonnumeric port' in msg or 'getaddrinfo failed' in msg or 'Name or service not known' in msg assert 'nonnumeric port' in msg or 'getaddrinfo failed' in msg or 'Name or service not known' in msg
return return
......
...@@ -174,8 +174,7 @@ class TestSdistTest: ...@@ -174,8 +174,7 @@ class TestSdistTest:
# The manifest should be UTF-8 encoded # The manifest should be UTF-8 encoded
try: try:
u_contents = contents.decode('UTF-8') u_contents = contents.decode('UTF-8')
except UnicodeDecodeError: except UnicodeDecodeError as e:
e = sys.exc_info()[1]
self.fail(e) self.fail(e)
# The manifest should contain the UTF-8 filename # The manifest should contain the UTF-8 filename
...@@ -217,8 +216,7 @@ class TestSdistTest: ...@@ -217,8 +216,7 @@ class TestSdistTest:
# The manifest should be UTF-8 encoded # The manifest should be UTF-8 encoded
try: try:
contents.decode('UTF-8') contents.decode('UTF-8')
except UnicodeDecodeError: except UnicodeDecodeError as e:
e = sys.exc_info()[1]
self.fail(e) self.fail(e)
# The manifest should contain the UTF-8 filename # The manifest should contain the UTF-8 filename
...@@ -258,8 +256,7 @@ class TestSdistTest: ...@@ -258,8 +256,7 @@ class TestSdistTest:
# The manifest should be UTF-8 encoded # The manifest should be UTF-8 encoded
try: try:
contents.decode('UTF-8') contents.decode('UTF-8')
except UnicodeDecodeError: except UnicodeDecodeError as e:
e = sys.exc_info()[1]
self.fail(e) self.fail(e)
# The Latin-1 filename should have been skipped # The Latin-1 filename should have been skipped
...@@ -328,8 +325,7 @@ class TestSdistTest: ...@@ -328,8 +325,7 @@ class TestSdistTest:
with quiet(): with quiet():
try: try:
cmd.read_manifest() cmd.read_manifest()
except UnicodeDecodeError: except UnicodeDecodeError as e:
e = sys.exc_info()[1]
self.fail(e) self.fail(e)
# The Latin-1 filename should have been skipped # The Latin-1 filename should have been skipped
......
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