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