From e2158b7ef4c307ff5be7bd2ef0ca3044f37759d4 Mon Sep 17 00:00:00 2001 From: "ting.wang" Date: Sat, 20 Feb 2016 14:28:08 +0800 Subject: Clean redundant argument to dict.get `dict.get()` returns `None` by default, if a key wasn't found. Removing `None` as second argument to avoid redundancy. Change-Id: Ia82f7469cd019509bbeccbfe54b15eeedc7bb6ea --- openstackclient/api/auth.py | 30 +++++++++++++------------- openstackclient/api/object_store_v1.py | 39 +++++++++++++++------------------- 2 files changed, 32 insertions(+), 37 deletions(-) (limited to 'openstackclient/api') diff --git a/openstackclient/api/auth.py b/openstackclient/api/auth.py index e675692e..3d6f7bcf 100644 --- a/openstackclient/api/auth.py +++ b/openstackclient/api/auth.py @@ -80,13 +80,13 @@ def select_auth_plugin(options): # Do the token/url check first as this must override the default # 'password' set by os-client-config # Also, url and token are not copied into o-c-c's auth dict (yet?) - if options.auth.get('url', None) and options.auth.get('token', None): + if options.auth.get('url') and options.auth.get('token'): # service token authentication auth_plugin_name = 'token_endpoint' elif options.auth_type in [plugin.name for plugin in PLUGIN_LIST]: # A direct plugin name was given, use it auth_plugin_name = options.auth_type - elif options.auth.get('username', None): + elif options.auth.get('username'): if options.identity_api_version == '3': auth_plugin_name = 'v3password' elif options.identity_api_version.startswith('2'): @@ -94,7 +94,7 @@ def select_auth_plugin(options): else: # let keystoneclient figure it out itself auth_plugin_name = 'osc_password' - elif options.auth.get('token', None): + elif options.auth.get('token'): if options.identity_api_version == '3': auth_plugin_name = 'v3token' elif options.identity_api_version.startswith('2'): @@ -144,33 +144,33 @@ def check_valid_auth_options(options, auth_plugin_name, required_scope=True): msg = '' if auth_plugin_name.endswith('password'): - if not options.auth.get('username', None): + if not options.auth.get('username'): msg += _('Set a username with --os-username, OS_USERNAME,' ' or auth.username\n') - if not options.auth.get('auth_url', None): + if not options.auth.get('auth_url'): msg += _('Set an authentication URL, with --os-auth-url,' ' OS_AUTH_URL or auth.auth_url\n') if (required_scope and not - options.auth.get('project_id', None) and not - options.auth.get('domain_id', None) and not - options.auth.get('domain_name', None) and not - options.auth.get('project_name', None) and not - options.auth.get('tenant_id', None) and not - options.auth.get('tenant_name', None)): + options.auth.get('project_id') and not + options.auth.get('domain_id') and not + options.auth.get('domain_name') and not + options.auth.get('project_name') and not + options.auth.get('tenant_id') and not + options.auth.get('tenant_name')): msg += _('Set a scope, such as a project or domain, set a ' 'project scope with --os-project-name, OS_PROJECT_NAME ' 'or auth.project_name, set a domain scope with ' '--os-domain-name, OS_DOMAIN_NAME or auth.domain_name') elif auth_plugin_name.endswith('token'): - if not options.auth.get('token', None): + if not options.auth.get('token'): msg += _('Set a token with --os-token, OS_TOKEN or auth.token\n') - if not options.auth.get('auth_url', None): + if not options.auth.get('auth_url'): msg += _('Set a service AUTH_URL, with --os-auth-url, ' 'OS_AUTH_URL or auth.auth_url\n') elif auth_plugin_name == 'token_endpoint': - if not options.auth.get('token', None): + if not options.auth.get('token'): msg += _('Set a token with --os-token, OS_TOKEN or auth.token\n') - if not options.auth.get('url', None): + if not options.auth.get('url'): msg += _('Set a service URL, with --os-url, OS_URL or auth.url\n') if msg: diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index d9f130bc..307c8fe2 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -50,7 +50,7 @@ class APIv1(api.BaseAPI): data = { 'account': self._find_account_id(), 'container': container, - 'x-trans-id': response.headers.get('x-trans-id', None), + 'x-trans-id': response.headers.get('x-trans-id'), } return data @@ -176,21 +176,19 @@ class APIv1(api.BaseAPI): 'account': self._find_account_id(), 'container': container, 'object_count': response.headers.get( - 'x-container-object-count', - None, + 'x-container-object-count' ), - 'bytes_used': response.headers.get('x-container-bytes-used', None) + 'bytes_used': response.headers.get('x-container-bytes-used') } if 'x-container-read' in response.headers: - data['read_acl'] = response.headers.get('x-container-read', None) + data['read_acl'] = response.headers.get('x-container-read') if 'x-container-write' in response.headers: - data['write_acl'] = response.headers.get('x-container-write', None) + data['write_acl'] = response.headers.get('x-container-write') if 'x-container-sync-to' in response.headers: - data['sync_to'] = response.headers.get('x-container-sync-to', None) + data['sync_to'] = response.headers.get('x-container-sync-to') if 'x-container-sync-key' in response.headers: - data['sync_key'] = response.headers.get('x-container-sync-key', - None) + data['sync_key'] = response.headers.get('x-container-sync-key') properties = self._get_properties(response.headers, 'x-container-meta-') @@ -248,8 +246,8 @@ class APIv1(api.BaseAPI): 'account': self._find_account_id(), 'container': container, 'object': object, - 'x-trans-id': response.headers.get('X-Trans-Id', None), - 'etag': response.headers.get('Etag', None), + 'x-trans-id': response.headers.get('X-Trans-Id'), + 'etag': response.headers.get('Etag'), } return data @@ -453,21 +451,19 @@ class APIv1(api.BaseAPI): 'account': self._find_account_id(), 'container': container, 'object': object, - 'content-type': response.headers.get('content-type', None), + 'content-type': response.headers.get('content-type'), } if 'content-length' in response.headers: data['content-length'] = response.headers.get( - 'content-length', - None, + 'content-length' ) if 'last-modified' in response.headers: - data['last-modified'] = response.headers.get('last-modified', None) + data['last-modified'] = response.headers.get('last-modified') if 'etag' in response.headers: - data['etag'] = response.headers.get('etag', None) + data['etag'] = response.headers.get('etag') if 'x-object-manifest' in response.headers: data['x-object-manifest'] = response.headers.get( - 'x-object-manifest', - None, + 'x-object-manifest' ) properties = self._get_properties(response.headers, 'x-object-meta-') @@ -506,10 +502,9 @@ class APIv1(api.BaseAPI): data['properties'] = properties # Map containers, bytes and objects a bit nicer - data['Containers'] = response.headers.get('x-account-container-count', - None) - data['Objects'] = response.headers.get('x-account-object-count', None) - data['Bytes'] = response.headers.get('x-account-bytes-used', None) + data['Containers'] = response.headers.get('x-account-container-count') + data['Objects'] = response.headers.get('x-account-object-count') + data['Bytes'] = response.headers.get('x-account-bytes-used') # Add in Account info too data['Account'] = self._find_account_id() return data -- cgit v1.2.1