Skip to content
Browse files

except Exceptions as variables

  • Loading branch information...
1 parent c9cca87 commit 63530ee3c20ac94e8664be420c39bc1d1929ca7f @gholms gholms committed with garnaat
View
2 boto/connection.py
@@ -771,7 +771,7 @@ def _mexe(self, request, sender=None, override_num_retries=None,
connection = self.get_http_connection(request.host,
scheme == 'https')
continue
- except self.http_exceptions, e:
+ except self.http_exceptions as e:
for unretryable in self.http_unretryable_exceptions:
if isinstance(e, unretryable):
boto.log.debug(
View
2 boto/ec2/connection.py
@@ -1852,7 +1852,7 @@ def get_key_pair(self, keyname):
"""
try:
return self.get_all_key_pairs(keynames=[keyname])[0]
- except self.ResponseError, e:
+ except self.ResponseError as e:
if e.code == 'InvalidKeyPair.NotFound':
return None
else:
View
2 boto/exception.py
@@ -85,7 +85,7 @@ def __init__(self, status, reason, body=None, *args):
try:
h = handler.XmlHandler(self, self)
xml.sax.parseString(self.body, h)
- except (TypeError, xml.sax.SAXParseException), pe:
+ except (TypeError, xml.sax.SAXParseException) as pe:
# Remove unparsable message body so we don't include garbage
# in exception. But first, save self.body in self.error_message
# because occasionally we get error messages from Eucalyptus
View
12 boto/gs/resumable_upload_handler.py
@@ -95,7 +95,7 @@ def _load_tracker_uri_from_file(self):
f = open(self.tracker_file_name, 'r')
uri = f.readline().strip()
self._set_tracker_uri(uri)
- except IOError, e:
+ except IOError as e:
# Ignore non-existent file (happens first time an upload
# is attempted on a file), but warn user for other errors.
if e.errno != errno.ENOENT:
@@ -103,7 +103,7 @@ def _load_tracker_uri_from_file(self):
print('Couldn\'t read URI tracker file (%s): %s. Restarting '
'upload from scratch.' %
(self.tracker_file_name, e.strerror))
- except InvalidUriError, e:
+ except InvalidUriError as e:
# Warn user, but proceed (will restart because
# self.tracker_uri == None).
print('Invalid tracker URI (%s) found in URI tracker file '
@@ -123,7 +123,7 @@ def _save_tracker_uri_to_file(self):
try:
f = open(self.tracker_file_name, 'w')
f.write(self.tracker_uri)
- except IOError, e:
+ except IOError as e:
raise ResumableUploadException(
'Couldn\'t write URI tracker file (%s): %s.\nThis can happen'
'if you\'re using an incorrectly configured upload tool\n'
@@ -394,7 +394,7 @@ def _attempt_resumable_upload(self, key, fp, file_length, headers, cb,
key=key
if conn.debug >= 1:
print 'Resuming transfer.'
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
if conn.debug >= 1:
print 'Unable to resume transfer (%s).' % e.message
self._start_new_resumable_upload(key, headers)
@@ -534,7 +534,7 @@ def send_file(self, key, fp, headers, cb=None, num_cb=10):
if debug >= 1:
print 'Resumable upload complete.'
return
- except self.RETRYABLE_EXCEPTIONS, e:
+ except self.RETRYABLE_EXCEPTIONS as e:
if debug >= 1:
print('Caught exception (%s)' % e.__repr__())
if isinstance(e, IOError) and e.errno == errno.EPIPE:
@@ -544,7 +544,7 @@ def send_file(self, key, fp, headers, cb=None, num_cb=10):
# the upload (which will cause a new connection to be
# opened the next time an HTTP request is sent).
key.bucket.connection.connection.close()
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
if (e.disposition ==
ResumableTransferDisposition.ABORT_CUR_PROCESS):
if debug >= 1:
View
3 boto/manage/cmdshell.py
@@ -54,7 +54,8 @@ def connect(self):
username=self.uname,
pkey=self._pkey)
return
- except socket.error, (value,message):
+ except socket.error as err:
+ (value, message) = err.args
if value == 61 or value == 111:
print 'SSH Connection refused, will retry in 5 seconds'
time.sleep(5)
View
2 boto/pyami/bootstrap.py
@@ -82,7 +82,7 @@ def load_boto(self):
try:
self.run('git pull', cwd=location)
num_remaining_attempts = 0
- except Exception, e:
+ except Exception as e:
boto.log.info('git pull attempt failed with the following exception. Trying again in a bit. %s', e)
time.sleep(2)
if update.find(':') >= 0:
View
2 boto/pyami/installers/ubuntu/ebs.py
@@ -128,7 +128,7 @@ def attach(self):
try:
ec2.attach_volume(self.volume_id, self.instance_id, self.device)
attempt_attach = False
- except EC2ResponseError, e:
+ except EC2ResponseError as e:
if e.error_code != 'IncorrectState':
# if there's an EC2ResonseError with the code set to IncorrectState, delay a bit for ec2
# to realize the instance is running, then try again. Otherwise, raise the error:
View
2 boto/pyami/startup.py
@@ -44,7 +44,7 @@ def run_scripts(self):
s.main()
else:
boto.log.warning('Trouble parsing script: %s' % script)
- except Exception, e:
+ except Exception as e:
boto.log.exception('Problem Running Script: %s. Startup process halting.' % script)
raise e
View
8 boto/roboto/awsqueryrequest.py
@@ -452,16 +452,16 @@ def do_cli(self):
try:
response = self.main()
self.cli_formatter(response)
- except RequiredParamError, e:
+ except RequiredParamError as e:
print e
sys.exit(1)
- except self.ServiceClass.ResponseError, err:
+ except self.ServiceClass.ResponseError as err:
print 'Error(%s): %s' % (err.error_code, err.error_message)
sys.exit(1)
- except boto.roboto.awsqueryservice.NoCredentialsError, err:
+ except boto.roboto.awsqueryservice.NoCredentialsError as err:
print 'Unable to find credentials.'
sys.exit(1)
- except Exception, e:
+ except Exception as e:
print e
sys.exit(1)
View
8 boto/s3/resumable_download_handler.py
@@ -130,7 +130,7 @@ def _load_tracker_file_etag(self):
else:
print('Couldn\'t read etag in tracker file (%s). Restarting '
'download from scratch.' % self.tracker_file_name)
- except IOError, e:
+ except IOError as e:
# Ignore non-existent file (happens first time a download
# is attempted on an object), but warn user for other errors.
if e.errno != errno.ENOENT:
@@ -151,7 +151,7 @@ def _save_tracker_info(self, key):
try:
f = open(self.tracker_file_name, 'w')
f.write('%s\n' % self.etag_value_for_current_download)
- except IOError, e:
+ except IOError as e:
raise ResumableDownloadException(
'Couldn\'t write tracker file (%s): %s.\nThis can happen'
'if you\'re using an incorrectly configured download tool\n'
@@ -273,7 +273,7 @@ def get_file(self, key, fp, headers, cb=None, num_cb=10, torrent=False,
if debug >= 1:
print 'Resumable download complete.'
return
- except self.RETRYABLE_EXCEPTIONS, e:
+ except self.RETRYABLE_EXCEPTIONS as e:
if debug >= 1:
print('Caught exception (%s)' % e.__repr__())
if isinstance(e, IOError) and e.errno == errno.EPIPE:
@@ -283,7 +283,7 @@ def get_file(self, key, fp, headers, cb=None, num_cb=10, torrent=False,
# the download.
key.get_file(fp, headers, cb, num_cb, torrent, version_id,
override_num_retries=0)
- except ResumableDownloadException, e:
+ except ResumableDownloadException as e:
if (e.disposition ==
ResumableTransferDisposition.ABORT_CUR_PROCESS):
if debug >= 1:
View
2 boto/sdb/connection.py
@@ -612,6 +612,6 @@ def select(self, domain_or_name, query='', next_token=None,
try:
return self.get_list('Select', params, [('Item', self.item_cls)],
parent=domain)
- except SDBResponseError, e:
+ except SDBResponseError as e:
e.body = "Query: %s\n%s" % (query, e.body)
raise e
View
2 boto/sdb/db/manager/pgmanager.py
@@ -246,7 +246,7 @@ def commit(self):
try:
self.connection.commit()
- except psycopg2.ProgrammingError, err:
+ except psycopg2.ProgrammingError as err:
self.connection.rollback()
raise err
View
6 boto/sdb/db/manager/sdbmanager.py
@@ -276,7 +276,7 @@ def decode_datetime(self, value):
else:
value = value.split("-")
return date(int(value[0]), int(value[1]), int(value[2]))
- except Exception, e:
+ except Exception as e:
return None
def encode_date(self, value):
@@ -356,7 +356,7 @@ def decode_blob(self, value):
bucket = s3.get_bucket(match.group(1), validate=False)
try:
key = bucket.get_key(match.group(2))
- except S3ResponseError, e:
+ except S3ResponseError as e:
if e.reason != "Forbidden":
raise
return None
@@ -478,7 +478,7 @@ def load_object(self, obj):
value = prop.make_value_from_datastore(value)
try:
setattr(obj, prop.name, value)
- except Exception, e:
+ except Exception as e:
boto.log.exception(e)
obj._loaded = True
View
2 boto/sdb/db/model.py
@@ -163,7 +163,7 @@ def __init__(self, id=None, **kw):
# so if it fails we just revert to it's default value
try:
setattr(self, key, kw[key])
- except Exception, e:
+ except Exception as e:
boto.log.exception(e)
def __repr__(self):
View
4 boto/sdb/db/sequence.py
@@ -169,7 +169,7 @@ def set(self, val):
try:
self.db.put_attributes(self.id, new_val, expected_value=expected_value)
self.timestamp = new_val['timestamp']
- except SDBResponseError, e:
+ except SDBResponseError as e:
if e.status == 409:
raise ValueError("Sequence out of sync")
else:
@@ -208,7 +208,7 @@ def _connect(self):
self.domain_name = boto.config.get("DB", "sequence_db", boto.config.get("DB", "db_name", "default"))
try:
self._db = sdb.get_domain(self.domain_name)
- except SDBResponseError, e:
+ except SDBResponseError as e:
if e.status == 400:
self._db = sdb.create_domain(self.domain_name)
else:
View
2 boto/utils.py
@@ -176,7 +176,7 @@ def retry_url(url, retry_on_404=True, num_retries=10):
req = urllib2.Request(url)
resp = urllib2.urlopen(req)
return resp.read()
- except urllib2.HTTPError, e:
+ except urllib2.HTTPError as e:
# in 2.6 you use getcode(), in 2.5 and earlier you use code
if hasattr(e, 'getcode'):
code = e.getcode()
View
2 docs/source/conf.py
@@ -26,7 +26,7 @@
try:
release = os.environ.get('SVN_REVISION', 'HEAD')
print release
-except Exception, e:
+except Exception as e:
print e
html_title = "boto v%s" % version
View
2 tests/dynamodb/test_layer1.py
@@ -136,7 +136,7 @@ def test_layer1_basic(self):
expected = {'Views': {'Value': {'N': '1'}}}
try:
result = c.delete_item(table_name, key=key1, expected=expected)
- except c.ResponseError, e:
+ except c.ResponseError as e:
assert e.error_code == 'ConditionalCheckFailedException'
# Now update the existing object
View
6 tests/dynamodb/test_layer2.py
@@ -132,7 +132,7 @@ def test_layer2_basic(self):
# make sure the put() succeeds
try:
item1.put()
- except c.layer1.ResponseError, e:
+ except c.layer1.ResponseError as e:
raise Exception("Item put failed: %s" % e)
# Try to get an item that does not exist.
@@ -168,7 +168,7 @@ def test_layer2_basic(self):
expected = {'Views': 1}
try:
item1.delete(expected_value=expected)
- except c.layer1.ResponseError, e:
+ except c.layer1.ResponseError as e:
assert e.error_code == 'ConditionalCheckFailedException'
else:
raise Exception("Expected Value condition failed")
@@ -177,7 +177,7 @@ def test_layer2_basic(self):
expected = {'FooBar': True}
try:
item1.delete(expected_value=expected)
- except c.layer1.ResponseError, e:
+ except c.layer1.ResponseError as e:
pass
# Now update the existing object
View
2 tests/mturk/selenium_support.py
@@ -17,7 +17,7 @@ def has_selenium():
# a little trick to see if the server is responding
try:
sel.do_command('shutdown', '')
- except Exception, e:
+ except Exception as e:
if not 'Server Exception' in str(e):
raise
result = True
View
10 tests/s3/test_resumable_downloads.py
@@ -69,7 +69,7 @@ def get_suite_description(self):
def resilient_close(key):
try:
key.close()
- except StorageResponseError, e:
+ except StorageResponseError as e:
pass
@classmethod
@@ -217,7 +217,7 @@ def test_failed_download_with_persistent_tracker(self):
self.dst_fp, cb=harnass.call,
res_download_handler=res_download_handler)
self.fail('Did not get expected ResumableDownloadException')
- except ResumableDownloadException, e:
+ except ResumableDownloadException as e:
# We'll get a ResumableDownloadException at this point because
# of CallbackTestHarnass (above). Check that the tracker file was
# created correctly.
@@ -275,7 +275,7 @@ def test_non_retryable_exception_handling(self):
self.dst_fp, cb=harnass.call,
res_download_handler=res_download_handler)
self.fail('Did not get expected OSError')
- except OSError, e:
+ except OSError as e:
# Ensure the error was re-raised.
self.assertEqual(e.errno, 13)
@@ -328,7 +328,7 @@ def test_multiple_in_process_failures_then_succeed_with_tracker_file(self):
self.dst_fp, cb=harnass.call,
res_download_handler=res_download_handler)
self.fail('Did not get expected ResumableDownloadException')
- except ResumableDownloadException, e:
+ except ResumableDownloadException as e:
self.assertEqual(e.disposition,
ResumableTransferDisposition.ABORT_CUR_PROCESS)
# Ensure a tracker file survived.
@@ -433,7 +433,7 @@ def test_download_with_unwritable_tracker_file(self):
os.chmod(self.tmp_dir, 0)
res_download_handler = ResumableDownloadHandler(
tracker_file_name=self.tracker_file_name)
- except ResumableDownloadException, e:
+ except ResumableDownloadException as e:
self.assertEqual(e.disposition, ResumableTransferDisposition.ABORT)
self.assertNotEqual(
e.message.find('Couldn\'t write URI tracker file'), -1)
View
20 tests/s3/test_resumable_uploads.py
@@ -240,7 +240,7 @@ def test_failed_upload_with_persistent_tracker(self):
self.small_src_file, cb=harnass.call,
res_upload_handler=res_upload_handler)
self.fail('Did not get expected ResumableUploadException')
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
# We'll get a ResumableUploadException at this point because
# of CallbackTestHarnass (above). Check that the tracker file was
# created correctly.
@@ -299,7 +299,7 @@ def test_non_retryable_exception_handling(self):
self.small_src_file, cb=harnass.call,
res_upload_handler=res_upload_handler)
self.fail('Did not get expected OSError')
- except OSError, e:
+ except OSError as e:
# Ensure the error was re-raised.
self.assertEqual(e.errno, 13)
@@ -353,7 +353,7 @@ def test_multiple_in_process_failures_then_succeed_with_tracker_file(self):
self.larger_src_file, cb=harnass.call,
res_upload_handler=res_upload_handler)
self.fail('Did not get expected ResumableUploadException')
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
self.assertEqual(e.disposition,
ResumableTransferDisposition.ABORT_CUR_PROCESS)
# Ensure a tracker file survived.
@@ -449,7 +449,7 @@ def test_upload_with_file_size_change_between_starts(self):
self.larger_src_file, cb=harnass.call,
res_upload_handler=res_upload_handler)
self.fail('Did not get expected ResumableUploadException')
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
# First abort (from harnass-forced failure) should be
# ABORT_CUR_PROCESS.
self.assertEqual(e.disposition, ResumableTransferDisposition.ABORT_CUR_PROCESS)
@@ -465,7 +465,7 @@ def test_upload_with_file_size_change_between_starts(self):
self.dst_key.set_contents_from_file(
self.largest_src_file, res_upload_handler=res_upload_handler)
self.fail('Did not get expected ResumableUploadException')
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
# This abort should be a hard abort (file size changing during
# transfer).
self.assertEqual(e.disposition, ResumableTransferDisposition.ABORT)
@@ -487,7 +487,7 @@ def test_upload_with_file_size_change_during_upload(self):
test_file, cb=harnass.call,
res_upload_handler=res_upload_handler)
self.fail('Did not get expected ResumableUploadException')
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
self.assertEqual(e.disposition, ResumableTransferDisposition.ABORT)
self.assertNotEqual(
e.message.find('File changed during upload'), -1)
@@ -511,7 +511,7 @@ def test_upload_with_file_content_change_during_upload(self):
test_file, cb=harnass.call,
res_upload_handler=res_upload_handler)
self.fail('Did not get expected ResumableUploadException')
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
self.assertEqual(e.disposition, ResumableTransferDisposition.ABORT)
# Ensure the file size didn't change.
test_file.seek(0, os.SEEK_END)
@@ -522,7 +522,7 @@ def test_upload_with_file_content_change_during_upload(self):
try:
self.dst_key_uri.get_key()
self.fail('Did not get expected InvalidUriError')
- except InvalidUriError, e:
+ except InvalidUriError as e:
pass
def test_upload_with_content_length_header_set(self):
@@ -538,7 +538,7 @@ def test_upload_with_content_length_header_set(self):
self.small_src_file, res_upload_handler=res_upload_handler,
headers={'Content-Length' : self.small_src_file_size})
self.fail('Did not get expected ResumableUploadException')
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
self.assertEqual(e.disposition, ResumableTransferDisposition.ABORT)
self.assertNotEqual(
e.message.find('Attempt to specify Content-Length header'), -1)
@@ -585,7 +585,7 @@ def test_upload_with_unwritable_tracker_file(self):
os.chmod(self.tmp_dir, 0)
res_upload_handler = ResumableUploadHandler(
tracker_file_name=self.tracker_file_name)
- except ResumableUploadException, e:
+ except ResumableUploadException as e:
self.assertEqual(e.disposition, ResumableTransferDisposition.ABORT)
self.assertNotEqual(
e.message.find('Couldn\'t write URI tracker file'), -1)

0 comments on commit 63530ee

Please sign in to comment.
Something went wrong with that request. Please try again.