From 59e939589e54c3c5ae6bc795aeb4239ef2f247a4 Mon Sep 17 00:00:00 2001 From: wanghao Date: Tue, 27 Jun 2017 15:18:48 +0800 Subject: [PATCH] Remove unused None from dict.get() Since the default value is None when can't get a key from a dict, So there is no need to use dict.get('key', None). Clear them from Zaqar code tree. Change-Id: I96d3438e13893bbe994f2f93cb8945a04e4d3ff9 --- zaqar/api/v2/endpoints.py | 2 +- zaqar/common/transport/wsgi/helpers.py | 2 +- zaqar/notification/notifier.py | 4 ++-- zaqar/storage/mongodb/subscriptions.py | 2 +- zaqar/storage/pooling.py | 2 +- zaqar/storage/redis/subscriptions.py | 6 +++--- zaqar/transport/validation.py | 10 +++++----- zaqar/transport/wsgi/v2_0/messages.py | 5 ++--- zaqar/transport/wsgi/v2_0/queues.py | 4 ++-- zaqar/transport/wsgi/v2_0/subscriptions.py | 2 +- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/zaqar/api/v2/endpoints.py b/zaqar/api/v2/endpoints.py index dfca3a327..145c8da5a 100644 --- a/zaqar/api/v2/endpoints.py +++ b/zaqar/api/v2/endpoints.py @@ -442,7 +442,7 @@ class Endpoints(object): queue_max_msg_size = queue_meta.get('_max_messages_post_size', None) - queue_default_ttl = queue_meta.get('_default_message_ttl', None) + queue_default_ttl = queue_meta.get('_default_message_ttl') # TODO(flwang): To avoid any unexpected regression issue, we just # leave the _message_post_spec attribute of class as it's. It diff --git a/zaqar/common/transport/wsgi/helpers.py b/zaqar/common/transport/wsgi/helpers.py index fad390d03..e93bf0b36 100644 --- a/zaqar/common/transport/wsgi/helpers.py +++ b/zaqar/common/transport/wsgi/helpers.py @@ -241,7 +241,7 @@ def inject_context(req, resp, params): """ client_id = req.get_header('Client-ID') - project_id = params.get('project_id', None) + project_id = params.get('project_id') request_id = req.headers.get('X-Openstack-Request-ID'), auth_token = req.headers.get('X-AUTH-TOKEN') user = req.headers.get('X-USER-ID') diff --git a/zaqar/notification/notifier.py b/zaqar/notification/notifier.py index 559520dfe..7cd9d6511 100644 --- a/zaqar/notification/notifier.py +++ b/zaqar/notification/notifier.py @@ -111,12 +111,12 @@ class NotifierDriver(object): messages = {} endpoint_dict = auth.get_public_endpoint() if endpoint_dict: - wsgi_endpoint = endpoint_dict.get('zaqar', None) + wsgi_endpoint = endpoint_dict.get('zaqar') if wsgi_endpoint: wsgi_subscribe_url = urllib_parse.urljoin( wsgi_endpoint, url) messages['WSGISubscribeURL'] = wsgi_subscribe_url - websocket_endpoint = endpoint_dict.get('zaqar-websocket', None) + websocket_endpoint = endpoint_dict.get('zaqar-websocket') if websocket_endpoint: websocket_subscribe_url = urllib_parse.urljoin( websocket_endpoint, url) diff --git a/zaqar/storage/mongodb/subscriptions.py b/zaqar/storage/mongodb/subscriptions.py index 12bd5c44c..26e0c625c 100644 --- a/zaqar/storage/mongodb/subscriptions.py +++ b/zaqar/storage/mongodb/subscriptions.py @@ -134,7 +134,7 @@ class SubscriptionController(base.Subscription): assert fields, ('`subscriber`, `ttl`, ' 'or `options` not found in kwargs') - new_ttl = fields.get('t', None) + new_ttl = fields.get('t') if new_ttl is not None: now = timeutils.utcnow_ts() now_dt = datetime.datetime.utcfromtimestamp(now) diff --git a/zaqar/storage/pooling.py b/zaqar/storage/pooling.py index 79addabc9..ea3bcdd97 100644 --- a/zaqar/storage/pooling.py +++ b/zaqar/storage/pooling.py @@ -207,7 +207,7 @@ class QueueController(storage.Queue): def _create(self, name, metadata=None, project=None): flavor = None if isinstance(metadata, dict): - flavor = metadata.get('_flavor', None) + flavor = metadata.get('_flavor') self._pool_catalog.register(name, project=project, flavor=flavor) diff --git a/zaqar/storage/redis/subscriptions.py b/zaqar/storage/redis/subscriptions.py index 56248ce31..9220e52fd 100644 --- a/zaqar/storage/redis/subscriptions.py +++ b/zaqar/storage/redis/subscriptions.py @@ -196,7 +196,7 @@ class SubscriptionController(base.Subscription): subscription_to_update = self.get(queue, subscription_id, project=project) - new_subscriber = fields.get('u', None) + new_subscriber = fields.get('u') # Let's do some checks to prevent subscription duplication. if new_subscriber: @@ -210,11 +210,11 @@ class SubscriptionController(base.Subscription): # NOTE(Eva-i): if there are new options, we need to pack them before # sending to the database. - new_options = fields.get('o', None) + new_options = fields.get('o') if new_options is not None: fields['o'] = self._packer(new_options) - new_ttl = fields.get('t', None) + new_ttl = fields.get('t') if new_ttl is not None: now = timeutils.utcnow_ts() expires = now + new_ttl diff --git a/zaqar/transport/validation.py b/zaqar/transport/validation.py index 9d003c498..3ef57e64b 100644 --- a/zaqar/transport/validation.py +++ b/zaqar/transport/validation.py @@ -300,7 +300,7 @@ class Validator(object): if not queue_metadata: return - queue_default_ttl = queue_metadata.get('_default_message_ttl', None) + queue_default_ttl = queue_metadata.get('_default_message_ttl') if queue_default_ttl and not isinstance(queue_default_ttl, int): msg = _(u'_default_message_ttl must be integer.') raise ValidationFailed(msg) @@ -525,7 +525,7 @@ class Validator(object): msg = _('Subscriptions must be a dict.') raise ValidationFailed(msg) - subscriber = subscription.get('subscriber', None) + subscriber = subscription.get('subscriber') subscriber_type = None if subscriber: @@ -537,12 +537,12 @@ class Validator(object): u'supported in the list {0}.') raise ValidationFailed(msg, self._limits_conf.subscriber_types) - options = subscription.get('options', None) + options = subscription.get('options') if options and not isinstance(options, dict): msg = _(u'Options must be a dict.') raise ValidationFailed(msg) - ttl = subscription.get('ttl', None) + ttl = subscription.get('ttl') if ttl: if not isinstance(ttl, int): msg = _(u'TTL must be an integer.') @@ -568,7 +568,7 @@ class Validator(object): raise ValidationFailed(msg, datetime.datetime.max) def subscription_confirming(self, confirmed): - confirmed = confirmed.get('confirmed', None) + confirmed = confirmed.get('confirmed') if not isinstance(confirmed, bool): msg = _(u"The 'confirmed' should be boolean.") raise ValidationFailed(msg) diff --git a/zaqar/transport/wsgi/v2_0/messages.py b/zaqar/transport/wsgi/v2_0/messages.py index d341bde58..ca45e74b8 100644 --- a/zaqar/transport/wsgi/v2_0/messages.py +++ b/zaqar/transport/wsgi/v2_0/messages.py @@ -172,9 +172,8 @@ class CollectionResource(object): # set. queue_meta = {} - queue_max_msg_size = queue_meta.get('_max_messages_post_size', - None) - queue_default_ttl = queue_meta.get('_default_message_ttl', None) + queue_max_msg_size = queue_meta.get('_max_messages_post_size') + queue_default_ttl = queue_meta.get('_default_message_ttl') # TODO(flwang): To avoid any unexpected regression issue, we just # leave the _message_post_spec attribute of class as it's. It diff --git a/zaqar/transport/wsgi/v2_0/queues.py b/zaqar/transport/wsgi/v2_0/queues.py index b5db7d601..6608ae497 100644 --- a/zaqar/transport/wsgi/v2_0/queues.py +++ b/zaqar/transport/wsgi/v2_0/queues.py @@ -56,7 +56,7 @@ class ItemResource(object): resp_dict = self._queue_controller.get(queue_name, project=project_id) for meta, value in _get_reserved_metadata(self._validate).items(): - if not resp_dict.get(meta, None): + if not resp_dict.get(meta): resp_dict[meta] = value except storage_errors.DoesNotExist as ex: LOG.debug(ex) @@ -209,7 +209,7 @@ class ItemResource(object): description = _(u'Queue could not be updated.') raise wsgi_errors.HTTPServiceUnavailable(description) for meta, value in _get_reserved_metadata(self._validate).items(): - if not metadata.get(meta, None): + if not metadata.get(meta): metadata[meta] = value resp.body = utils.to_json(metadata) diff --git a/zaqar/transport/wsgi/v2_0/subscriptions.py b/zaqar/transport/wsgi/v2_0/subscriptions.py index 1a9691547..a0a7f1463 100644 --- a/zaqar/transport/wsgi/v2_0/subscriptions.py +++ b/zaqar/transport/wsgi/v2_0/subscriptions.py @@ -267,7 +267,7 @@ class ConfirmResource(object): try: self._validate.subscription_confirming(document) - confirmed = document.get('confirmed', None) + confirmed = document.get('confirmed') self._subscription_controller.confirm(queue_name, subscription_id, project=project_id, confirmed=confirmed)