Syntax enhancements

Did some syntax improvement by:
-Removing extraneous parentheses.
-Collapsing "if" statements.
-Used set literal notation.
-Fixed pep8 issue

Change-Id: I321536058a76bf69af1d6b38d37f81a07a2f7108
Closes-Bug: #1397027
This commit is contained in:
Ricardo Ferreira 2015-03-10 23:18:09 +00:00
parent 7a29e9de10
commit f2ee58b00c
20 changed files with 29 additions and 31 deletions

View File

@ -80,7 +80,7 @@ class TestInsertQueue(base.V1FunctionalTestBase):
"v1")
self.header = helpers.create_zaqar_headers(self.cfg)
self.headers_response_empty = set(['location'])
self.headers_response_empty = {'location'}
self.client.set_base_url(self.base_url)
self.header = helpers.create_zaqar_headers(self.cfg)
@ -420,7 +420,7 @@ class TestQueueNonExisting(base.V1FunctionalTestBase):
self.client.set_base_url(self.queue_url)
self.header = helpers.create_zaqar_headers(self.cfg)
self.headers_response_empty = set(['location'])
self.headers_response_empty = {'location'}
self.header = helpers.create_zaqar_headers(self.cfg)
def test_get_queue(self):

View File

@ -80,7 +80,7 @@ class TestInsertQueue(base.V1_1FunctionalTestBase):
"v1.1")
self.header = helpers.create_zaqar_headers(self.cfg)
self.headers_response_empty = set(['location'])
self.headers_response_empty = {'location'}
self.client.set_base_url(self.base_url)
self.client.headers = self.header
@ -331,7 +331,7 @@ class TestQueueNonExisting(base.V1_1FunctionalTestBase):
self.client.set_base_url(self.queue_url)
self.header = helpers.create_zaqar_headers(self.cfg)
self.headers_response_empty = set(['location'])
self.headers_response_empty = {'location'}
self.header = helpers.create_zaqar_headers(self.cfg)
def test_get_stats(self):

View File

@ -122,7 +122,7 @@ def crunch(stats):
total_succeeded += entry['total_succeeded']
total_elapsed += entry['total_elapsed']
return (total_requests, total_succeeded, total_elapsed)
return total_requests, total_succeeded, total_elapsed
def run(upstream_queue):

View File

@ -53,7 +53,7 @@ _GENERAL_OPTIONS = (
'catalogue/control plane data is kept.'),
deprecated_opts=[cfg.DeprecatedOpt('sharding')]),
cfg.BoolOpt('unreliable', default=None,
help=('Disable all reliability constrains.')),
help='Disable all reliability constrains.'),
)
_DRIVER_OPTIONS = (

View File

@ -52,7 +52,7 @@ class MemoryBackend(backends.BaseCache):
try:
timeout, value = self._cache[key]
except KeyError:
return (0, default)
return 0, default
if timeout and now >= timeout:
@ -72,9 +72,9 @@ class MemoryBackend(backends.BaseCache):
except (KeyError, ValueError):
pass
return (0, default)
return 0, default
return (timeout, value)
return timeout, value
def _get(self, key, default=None):
with lockutils.lock(key):

View File

@ -236,9 +236,8 @@ def _sanitize_default(name, value):
return value.replace(BASEDIR, '')
elif value == _get_my_ip():
return '10.0.0.1'
elif value in (hostname, fqdn):
if 'host' in name:
return 'zaqar'
elif value in (hostname, fqdn) and 'host' in name:
return 'zaqar'
elif value.endswith(hostname):
return value.replace(hostname, 'zaqar')
elif value.endswith(fqdn):

View File

@ -63,7 +63,7 @@ def read_cached_file(filename, force_reload=False):
cache_info['data'] = fap.read()
cache_info['mtime'] = mtime
reloaded = True
return (reloaded, cache_info['data'])
return reloaded, cache_info['data']
def delete_cached_file(filename):

View File

@ -96,7 +96,7 @@ class ClaimController(storage.Claim):
except StopIteration:
raise errors.ClaimDoesNotExist(cid, queue, project)
return (claim_meta, msgs)
return claim_meta, msgs
# NOTE(kgriffs): If we get an autoreconnect or any other connection error,
# the worst that can happen is you get an orphaned claim, but it will
@ -154,7 +154,7 @@ class ClaimController(storage.Claim):
ids = [msg['_id'] for msg in msgs]
if len(ids) == 0:
return (None, messages)
return None, messages
now = timeutils.utcnow_ts()
@ -196,7 +196,7 @@ class ClaimController(storage.Claim):
# with the claim ID successfully.
claim, messages = self.get(queue, oid, project=project)
return (str(oid), messages)
return str(oid), messages
@utils.raises_conn_error
@utils.retries_on_autoreconnect

View File

@ -59,7 +59,7 @@ def cached_gen(iterable):
cached_items.append(item)
yield item
return (generator(iterable), cached_items)
return generator(iterable), cached_items
def calculate_backoff(attempt, max_attempts, max_sleep, max_jitter=0):

View File

@ -96,7 +96,7 @@ def descope_message_ids_set(msgset_key):
tokens = msgset_key.split('.')
return (tokens[1] or None, tokens[0] or None)
return tokens[1] or None, tokens[0] or None
# NOTE(prashanthr_): Aliasing the scope_message_ids_set function
# to be used in the pools and claims controller as similar

View File

@ -124,7 +124,7 @@ class ClaimController(storage.Claim):
tables.Messages.c.cid == cid)))
trans.execute(update)
return (utils.cid_encode(int(cid)), list(self.__get(cid, trans)))
return utils.cid_encode(int(cid)), list(self.__get(cid, trans))
def update(self, queue, claim_id, metadata, project=None):
if project is None:

View File

@ -97,8 +97,7 @@ class FunctionalTestBase(testing.TestBase):
auth_token = helpers.get_keystone_token(self.cfg, self.client)
self.headers["X-Auth-Token"] = auth_token
self.headers_response_with_body = set(['location',
'content-type'])
self.headers_response_with_body = {'location', 'content-type'}
self.client.set_headers(self.headers)

View File

@ -405,8 +405,8 @@ class MessageControllerTest(ControllerBaseTest):
# Test Message Get
message_out = self.controller.get(queue_name, message_id,
project=self.project)
self.assertEqual(set(message_out), set(('id', 'body', 'ttl', 'age',
'claim_id')))
self.assertEqual(set(message_out),
{'id', 'body', 'ttl', 'age', 'claim_id'})
self.assertEqual(message_out['id'], message_id)
self.assertEqual(message_out['body'], message['body'])
self.assertEqual(message_out['ttl'], message['ttl'])
@ -462,7 +462,7 @@ class MessageControllerTest(ControllerBaseTest):
for idx, message in enumerate(messages_out):
self.assertEqual(set(message),
set(('id', 'body', 'ttl', 'age', 'claim_id')))
{'id', 'body', 'ttl', 'age', 'claim_id'})
self.assertEqual(message['body'], idx)
self.controller.bulk_delete(self.queue_name, ids,

View File

@ -38,7 +38,7 @@ class KeystoneAuth(object):
options = []
keystone_opts = opts.list_auth_token_opts()
for n in keystone_opts:
if (n[0] == cls.OPT_GROUP_NAME):
if n[0] == cls.OPT_GROUP_NAME:
options = n[1]
break

View File

@ -236,7 +236,7 @@ class CollectionResource(object):
class ItemResource(object):
__slots__ = ('_message_controller')
__slots__ = '_message_controller'
def __init__(self, message_controller):
self._message_controller = message_controller

View File

@ -27,7 +27,7 @@ LOG = logging.getLogger(__name__)
class Resource(object):
__slots__ = ('_queue_ctrl')
__slots__ = '_queue_ctrl'
def __init__(self, queue_controller):
self._queue_ctrl = queue_controller

View File

@ -297,7 +297,7 @@ class CollectionResource(object):
class ItemResource(object):
__slots__ = ('_message_controller')
__slots__ = '_message_controller'
def __init__(self, message_controller):
self._message_controller = message_controller

View File

@ -27,7 +27,7 @@ LOG = logging.getLogger(__name__)
class Resource(object):
__slots__ = ('_queue_ctrl')
__slots__ = '_queue_ctrl'
def __init__(self, queue_controller):
self._queue_ctrl = queue_controller

View File

@ -297,7 +297,7 @@ class CollectionResource(object):
class ItemResource(object):
__slots__ = ('_message_controller')
__slots__ = '_message_controller'
def __init__(self, message_controller):
self._message_controller = message_controller

View File

@ -27,7 +27,7 @@ LOG = logging.getLogger(__name__)
class Resource(object):
__slots__ = ('_queue_ctrl')
__slots__ = '_queue_ctrl'
def __init__(self, queue_controller):
self._queue_ctrl = queue_controller