Improve Python 3.x compatibility
Some mechancical replacement of the deprecated except x,y: construct with except x as y, which works with any Python version >= 2.6 Change-Id: Ic245049dc7b408a5c89b9e27dfd2bd7c08acc5b5
This commit is contained in:
46
bin/swift
46
bin/swift
@@ -56,7 +56,7 @@ def get_conn(options):
|
|||||||
def mkdirs(path):
|
def mkdirs(path):
|
||||||
try:
|
try:
|
||||||
makedirs(path)
|
makedirs(path)
|
||||||
except OSError, err:
|
except OSError as err:
|
||||||
if err.errno != EEXIST:
|
if err.errno != EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ def st_delete(parser, args, print_queue, error_queue):
|
|||||||
if utils.config_true_value(
|
if utils.config_true_value(
|
||||||
headers.get('x-static-large-object')):
|
headers.get('x-static-large-object')):
|
||||||
query_string = 'multipart-manifest=delete'
|
query_string = 'multipart-manifest=delete'
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
conn.delete_object(container, obj, query_string=query_string)
|
conn.delete_object(container, obj, query_string=query_string)
|
||||||
@@ -222,7 +222,7 @@ def st_delete(parser, args, print_queue, error_queue):
|
|||||||
(path, conn.attempts))
|
(path, conn.attempts))
|
||||||
else:
|
else:
|
||||||
print_queue.put(path)
|
print_queue.put(path)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Object %s not found' %
|
error_queue.put('Object %s not found' %
|
||||||
@@ -252,14 +252,14 @@ def st_delete(parser, args, print_queue, error_queue):
|
|||||||
try:
|
try:
|
||||||
conn.delete_container(container)
|
conn.delete_container(container)
|
||||||
break
|
break
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 409:
|
if err.http_status != 409:
|
||||||
raise
|
raise
|
||||||
if attempts > 10:
|
if attempts > 10:
|
||||||
raise
|
raise
|
||||||
attempts += 1
|
attempts += 1
|
||||||
sleep(1)
|
sleep(1)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Container %s not found' % repr(container))
|
error_queue.put('Container %s not found' % repr(container))
|
||||||
@@ -292,7 +292,7 @@ def st_delete(parser, args, print_queue, error_queue):
|
|||||||
sleep(0.01)
|
sleep(0.01)
|
||||||
while not object_queue.empty():
|
while not object_queue.empty():
|
||||||
sleep(0.01)
|
sleep(0.01)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Account not found')
|
error_queue.put('Account not found')
|
||||||
@@ -439,7 +439,7 @@ def st_download(parser, args, print_queue, error_queue):
|
|||||||
(path, time_str, conn.attempts))
|
(path, time_str, conn.attempts))
|
||||||
else:
|
else:
|
||||||
print_queue.put('%s [%s]' % (path, time_str))
|
print_queue.put('%s [%s]' % (path, time_str))
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Object %s not found' %
|
error_queue.put('Object %s not found' %
|
||||||
@@ -459,7 +459,7 @@ def st_download(parser, args, print_queue, error_queue):
|
|||||||
shuffle(objects)
|
shuffle(objects)
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
object_queue.put((container, obj))
|
object_queue.put((container, obj))
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Container %s not found' % repr(container))
|
error_queue.put('Container %s not found' % repr(container))
|
||||||
@@ -487,7 +487,7 @@ def st_download(parser, args, print_queue, error_queue):
|
|||||||
shuffle(containers)
|
shuffle(containers)
|
||||||
for container in containers:
|
for container in containers:
|
||||||
container_queue.put(container)
|
container_queue.put(container)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Account not found')
|
error_queue.put('Account not found')
|
||||||
@@ -560,7 +560,7 @@ def st_list(parser, args, print_queue, error_queue):
|
|||||||
for item in items:
|
for item in items:
|
||||||
print_queue.put(item.get('name', item.get('subdir')))
|
print_queue.put(item.get('name', item.get('subdir')))
|
||||||
marker = items[-1].get('name', items[-1].get('subdir'))
|
marker = items[-1].get('name', items[-1].get('subdir'))
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
if not args:
|
if not args:
|
||||||
@@ -606,7 +606,7 @@ Containers: %d
|
|||||||
'x-account-object-count', 'x-account-bytes-used'):
|
'x-account-object-count', 'x-account-bytes-used'):
|
||||||
print_queue.put(
|
print_queue.put(
|
||||||
'%10s: %s' % (key.title(), value))
|
'%10s: %s' % (key.title(), value))
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Account not found')
|
error_queue.put('Account not found')
|
||||||
@@ -645,7 +645,7 @@ Write ACL: %s
|
|||||||
'x-container-sync-key'):
|
'x-container-sync-key'):
|
||||||
print_queue.put(
|
print_queue.put(
|
||||||
'%9s: %s' % (key.title(), value))
|
'%9s: %s' % (key.title(), value))
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Container %s not found' % repr(args[0]))
|
error_queue.put('Container %s not found' % repr(args[0]))
|
||||||
@@ -679,7 +679,7 @@ Write ACL: %s
|
|||||||
'etag', 'date', 'x-object-manifest'):
|
'etag', 'date', 'x-object-manifest'):
|
||||||
print_queue.put(
|
print_queue.put(
|
||||||
'%14s: %s' % (key.title(), value))
|
'%14s: %s' % (key.title(), value))
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Object %s not found' %
|
error_queue.put('Object %s not found' %
|
||||||
@@ -728,7 +728,7 @@ def st_post(parser, args, print_queue, error_queue):
|
|||||||
headers = split_headers(options.meta, 'X-Account-Meta-', error_queue)
|
headers = split_headers(options.meta, 'X-Account-Meta-', error_queue)
|
||||||
try:
|
try:
|
||||||
conn.post_account(headers=headers)
|
conn.post_account(headers=headers)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Account not found')
|
error_queue.put('Account not found')
|
||||||
@@ -748,7 +748,7 @@ def st_post(parser, args, print_queue, error_queue):
|
|||||||
headers['X-Container-Sync-Key'] = options.sync_key
|
headers['X-Container-Sync-Key'] = options.sync_key
|
||||||
try:
|
try:
|
||||||
conn.post_container(args[0], headers=headers)
|
conn.post_container(args[0], headers=headers)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
conn.put_container(args[0], headers=headers)
|
conn.put_container(args[0], headers=headers)
|
||||||
@@ -758,7 +758,7 @@ def st_post(parser, args, print_queue, error_queue):
|
|||||||
headers.update(split_headers(options.header, '', error_queue))
|
headers.update(split_headers(options.header, '', error_queue))
|
||||||
try:
|
try:
|
||||||
conn.post_object(args[0], args[1], headers=headers)
|
conn.post_object(args[0], args[1], headers=headers)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Object %s not found' %
|
error_queue.put('Object %s not found' %
|
||||||
@@ -863,7 +863,7 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
et == 'd41d8cd98f00b204e9800998ecf8427e' and \
|
et == 'd41d8cd98f00b204e9800998ecf8427e' and \
|
||||||
mt == put_headers['x-object-meta-mtime']:
|
mt == put_headers['x-object-meta-mtime']:
|
||||||
return
|
return
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
conn.put_object(container, obj, '', content_length=0,
|
conn.put_object(container, obj, '', content_length=0,
|
||||||
@@ -896,7 +896,7 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
if isinstance(seg_path, unicode):
|
if isinstance(seg_path, unicode):
|
||||||
seg_path = seg_path.encode('utf-8')
|
seg_path = seg_path.encode('utf-8')
|
||||||
old_slo_manifest_paths.append(seg_path)
|
old_slo_manifest_paths.append(seg_path)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
# Merge the command line header options to the put_headers
|
# Merge the command line header options to the put_headers
|
||||||
@@ -1020,7 +1020,7 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
'%s [after %d attempts]' % (obj, conn.attempts))
|
'%s [after %d attempts]' % (obj, conn.attempts))
|
||||||
else:
|
else:
|
||||||
print_queue.put(obj)
|
print_queue.put(obj)
|
||||||
except OSError, err:
|
except OSError as err:
|
||||||
if err.errno != ENOENT:
|
if err.errno != ENOENT:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Local file %s not found' % repr(path))
|
error_queue.put('Local file %s not found' % repr(path))
|
||||||
@@ -1054,7 +1054,7 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
if options.segment_container:
|
if options.segment_container:
|
||||||
seg_container = options.segment_container
|
seg_container = options.segment_container
|
||||||
conn.put_container(seg_container)
|
conn.put_container(seg_container)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
msg = ' '.join(str(x) for x in (err.http_status, err.http_reason))
|
msg = ' '.join(str(x) for x in (err.http_status, err.http_reason))
|
||||||
if err.http_response_content:
|
if err.http_response_content:
|
||||||
if msg:
|
if msg:
|
||||||
@@ -1062,7 +1062,7 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
msg += err.http_response_content[:60]
|
msg += err.http_response_content[:60]
|
||||||
error_queue.put(
|
error_queue.put(
|
||||||
'Error trying to create container %r: %s' % (args[0], msg))
|
'Error trying to create container %r: %s' % (args[0], msg))
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_queue.put(
|
error_queue.put(
|
||||||
'Error trying to create container %r: %s' % (args[0], err))
|
'Error trying to create container %r: %s' % (args[0], err))
|
||||||
try:
|
try:
|
||||||
@@ -1078,7 +1078,7 @@ def st_upload(parser, args, print_queue, error_queue):
|
|||||||
while thread.isAlive():
|
while thread.isAlive():
|
||||||
thread.join(0.01)
|
thread.join(0.01)
|
||||||
put_errors_from_threads(object_threads, error_queue)
|
put_errors_from_threads(object_threads, error_queue)
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
error_queue.put('Account not found')
|
error_queue.put('Account not found')
|
||||||
@@ -1329,7 +1329,7 @@ Examples:
|
|||||||
try:
|
try:
|
||||||
globals()['st_%s' % args[0]](parser, argv[1:], print_queue,
|
globals()['st_%s' % args[0]](parser, argv[1:], print_queue,
|
||||||
error_queue)
|
error_queue)
|
||||||
except (ClientException, HTTPException, socket.error), err:
|
except (ClientException, HTTPException, socket.error) as err:
|
||||||
error_queue.put(str(err))
|
error_queue.put(str(err))
|
||||||
while not print_queue.empty():
|
while not print_queue.empty():
|
||||||
sleep(0.01)
|
sleep(0.01)
|
||||||
|
@@ -262,7 +262,7 @@ variables to be set or overridden with -A, -U, or -K.''')
|
|||||||
except exceptions.Unauthorized:
|
except exceptions.Unauthorized:
|
||||||
raise ClientException('Unauthorised. Check username, password'
|
raise ClientException('Unauthorised. Check username, password'
|
||||||
' and tenant name/id')
|
' and tenant name/id')
|
||||||
except exceptions.AuthorizationFailure, err:
|
except exceptions.AuthorizationFailure as err:
|
||||||
raise ClientException('Authorization Failure. %s' % err)
|
raise ClientException('Authorization Failure. %s' % err)
|
||||||
service_type = os_options.get('service_type') or 'object-store'
|
service_type = os_options.get('service_type') or 'object-store'
|
||||||
endpoint_type = os_options.get('endpoint_type') or 'publicURL'
|
endpoint_type = os_options.get('endpoint_type') or 'publicURL'
|
||||||
@@ -1030,7 +1030,7 @@ class Connection(object):
|
|||||||
if self.attempts > self.retries:
|
if self.attempts > self.retries:
|
||||||
raise
|
raise
|
||||||
self.http_conn = None
|
self.http_conn = None
|
||||||
except ClientException, err:
|
except ClientException as err:
|
||||||
if self.attempts > self.retries:
|
if self.attempts > self.retries:
|
||||||
raise
|
raise
|
||||||
if err.http_status == 401:
|
if err.http_status == 401:
|
||||||
|
@@ -625,7 +625,7 @@ class TestConnection(MockHttpTest):
|
|||||||
except AssertionError:
|
except AssertionError:
|
||||||
msg = '%s did not read resp on server error' % method.__name__
|
msg = '%s did not read resp on server error' % method.__name__
|
||||||
self.fail(msg)
|
self.fail(msg)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise e.__class__("%s - %s" % (method.__name__, e))
|
raise e.__class__("%s - %s" % (method.__name__, e))
|
||||||
|
|
||||||
def test_reauth(self):
|
def test_reauth(self):
|
||||||
@@ -727,7 +727,7 @@ class TestConnection(MockHttpTest):
|
|||||||
exc = None
|
exc = None
|
||||||
try:
|
try:
|
||||||
conn.put_object('c', 'o', contents)
|
conn.put_object('c', 'o', contents)
|
||||||
except socket.error, err:
|
except socket.error as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(contents.seeks, [0])
|
self.assertEquals(contents.seeks, [0])
|
||||||
self.assertEquals(str(exc), 'oops')
|
self.assertEquals(str(exc), 'oops')
|
||||||
@@ -736,7 +736,7 @@ class TestConnection(MockHttpTest):
|
|||||||
exc = None
|
exc = None
|
||||||
try:
|
try:
|
||||||
conn.put_object('c', 'o', contents)
|
conn.put_object('c', 'o', contents)
|
||||||
except socket.error, err:
|
except socket.error as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(contents.seeks, [123])
|
self.assertEquals(contents.seeks, [123])
|
||||||
self.assertEquals(str(exc), 'oops')
|
self.assertEquals(str(exc), 'oops')
|
||||||
@@ -746,7 +746,7 @@ class TestConnection(MockHttpTest):
|
|||||||
exc = None
|
exc = None
|
||||||
try:
|
try:
|
||||||
conn.put_object('c', 'o', contents)
|
conn.put_object('c', 'o', contents)
|
||||||
except c.ClientException, err:
|
except c.ClientException as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEquals(contents.seeks, [])
|
self.assertEquals(contents.seeks, [])
|
||||||
self.assertEquals(str(exc), "put_object('c', 'o', ...) failure "
|
self.assertEquals(str(exc), "put_object('c', 'o', ...) failure "
|
||||||
|
Reference in New Issue
Block a user