Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.

Commit e2158b7

Browse files
author
ting.wang
committed
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
1 parent 867bcb0 commit e2158b7

5 files changed

Lines changed: 42 additions & 47 deletions

File tree

openstackclient/api/auth.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,21 @@ def select_auth_plugin(options):
8080
# Do the token/url check first as this must override the default
8181
# 'password' set by os-client-config
8282
# Also, url and token are not copied into o-c-c's auth dict (yet?)
83-
if options.auth.get('url', None) and options.auth.get('token', None):
83+
if options.auth.get('url') and options.auth.get('token'):
8484
# service token authentication
8585
auth_plugin_name = 'token_endpoint'
8686
elif options.auth_type in [plugin.name for plugin in PLUGIN_LIST]:
8787
# A direct plugin name was given, use it
8888
auth_plugin_name = options.auth_type
89-
elif options.auth.get('username', None):
89+
elif options.auth.get('username'):
9090
if options.identity_api_version == '3':
9191
auth_plugin_name = 'v3password'
9292
elif options.identity_api_version.startswith('2'):
9393
auth_plugin_name = 'v2password'
9494
else:
9595
# let keystoneclient figure it out itself
9696
auth_plugin_name = 'osc_password'
97-
elif options.auth.get('token', None):
97+
elif options.auth.get('token'):
9898
if options.identity_api_version == '3':
9999
auth_plugin_name = 'v3token'
100100
elif options.identity_api_version.startswith('2'):
@@ -144,33 +144,33 @@ def check_valid_auth_options(options, auth_plugin_name, required_scope=True):
144144

145145
msg = ''
146146
if auth_plugin_name.endswith('password'):
147-
if not options.auth.get('username', None):
147+
if not options.auth.get('username'):
148148
msg += _('Set a username with --os-username, OS_USERNAME,'
149149
' or auth.username\n')
150-
if not options.auth.get('auth_url', None):
150+
if not options.auth.get('auth_url'):
151151
msg += _('Set an authentication URL, with --os-auth-url,'
152152
' OS_AUTH_URL or auth.auth_url\n')
153153
if (required_scope and not
154-
options.auth.get('project_id', None) and not
155-
options.auth.get('domain_id', None) and not
156-
options.auth.get('domain_name', None) and not
157-
options.auth.get('project_name', None) and not
158-
options.auth.get('tenant_id', None) and not
159-
options.auth.get('tenant_name', None)):
154+
options.auth.get('project_id') and not
155+
options.auth.get('domain_id') and not
156+
options.auth.get('domain_name') and not
157+
options.auth.get('project_name') and not
158+
options.auth.get('tenant_id') and not
159+
options.auth.get('tenant_name')):
160160
msg += _('Set a scope, such as a project or domain, set a '
161161
'project scope with --os-project-name, OS_PROJECT_NAME '
162162
'or auth.project_name, set a domain scope with '
163163
'--os-domain-name, OS_DOMAIN_NAME or auth.domain_name')
164164
elif auth_plugin_name.endswith('token'):
165-
if not options.auth.get('token', None):
165+
if not options.auth.get('token'):
166166
msg += _('Set a token with --os-token, OS_TOKEN or auth.token\n')
167-
if not options.auth.get('auth_url', None):
167+
if not options.auth.get('auth_url'):
168168
msg += _('Set a service AUTH_URL, with --os-auth-url, '
169169
'OS_AUTH_URL or auth.auth_url\n')
170170
elif auth_plugin_name == 'token_endpoint':
171-
if not options.auth.get('token', None):
171+
if not options.auth.get('token'):
172172
msg += _('Set a token with --os-token, OS_TOKEN or auth.token\n')
173-
if not options.auth.get('url', None):
173+
if not options.auth.get('url'):
174174
msg += _('Set a service URL, with --os-url, OS_URL or auth.url\n')
175175

176176
if msg:

openstackclient/api/object_store_v1.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def container_create(
5050
data = {
5151
'account': self._find_account_id(),
5252
'container': container,
53-
'x-trans-id': response.headers.get('x-trans-id', None),
53+
'x-trans-id': response.headers.get('x-trans-id'),
5454
}
5555

5656
return data
@@ -176,21 +176,19 @@ def container_show(
176176
'account': self._find_account_id(),
177177
'container': container,
178178
'object_count': response.headers.get(
179-
'x-container-object-count',
180-
None,
179+
'x-container-object-count'
181180
),
182-
'bytes_used': response.headers.get('x-container-bytes-used', None)
181+
'bytes_used': response.headers.get('x-container-bytes-used')
183182
}
184183

185184
if 'x-container-read' in response.headers:
186-
data['read_acl'] = response.headers.get('x-container-read', None)
185+
data['read_acl'] = response.headers.get('x-container-read')
187186
if 'x-container-write' in response.headers:
188-
data['write_acl'] = response.headers.get('x-container-write', None)
187+
data['write_acl'] = response.headers.get('x-container-write')
189188
if 'x-container-sync-to' in response.headers:
190-
data['sync_to'] = response.headers.get('x-container-sync-to', None)
189+
data['sync_to'] = response.headers.get('x-container-sync-to')
191190
if 'x-container-sync-key' in response.headers:
192-
data['sync_key'] = response.headers.get('x-container-sync-key',
193-
None)
191+
data['sync_key'] = response.headers.get('x-container-sync-key')
194192

195193
properties = self._get_properties(response.headers,
196194
'x-container-meta-')
@@ -248,8 +246,8 @@ def object_create(
248246
'account': self._find_account_id(),
249247
'container': container,
250248
'object': object,
251-
'x-trans-id': response.headers.get('X-Trans-Id', None),
252-
'etag': response.headers.get('Etag', None),
249+
'x-trans-id': response.headers.get('X-Trans-Id'),
250+
'etag': response.headers.get('Etag'),
253251
}
254252

255253
return data
@@ -453,21 +451,19 @@ def object_show(
453451
'account': self._find_account_id(),
454452
'container': container,
455453
'object': object,
456-
'content-type': response.headers.get('content-type', None),
454+
'content-type': response.headers.get('content-type'),
457455
}
458456
if 'content-length' in response.headers:
459457
data['content-length'] = response.headers.get(
460-
'content-length',
461-
None,
458+
'content-length'
462459
)
463460
if 'last-modified' in response.headers:
464-
data['last-modified'] = response.headers.get('last-modified', None)
461+
data['last-modified'] = response.headers.get('last-modified')
465462
if 'etag' in response.headers:
466-
data['etag'] = response.headers.get('etag', None)
463+
data['etag'] = response.headers.get('etag')
467464
if 'x-object-manifest' in response.headers:
468465
data['x-object-manifest'] = response.headers.get(
469-
'x-object-manifest',
470-
None,
466+
'x-object-manifest'
471467
)
472468

473469
properties = self._get_properties(response.headers, 'x-object-meta-')
@@ -506,10 +502,9 @@ def account_show(self):
506502
data['properties'] = properties
507503

508504
# Map containers, bytes and objects a bit nicer
509-
data['Containers'] = response.headers.get('x-account-container-count',
510-
None)
511-
data['Objects'] = response.headers.get('x-account-object-count', None)
512-
data['Bytes'] = response.headers.get('x-account-bytes-used', None)
505+
data['Containers'] = response.headers.get('x-account-container-count')
506+
data['Objects'] = response.headers.get('x-account-object-count')
507+
data['Bytes'] = response.headers.get('x-account-bytes-used')
513508
# Add in Account info too
514509
data['Account'] = self._find_account_id()
515510
return data

openstackclient/common/clientmanager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(
9090
self._cli_options = cli_options
9191
self._api_version = api_version
9292
self._pw_callback = pw_func
93-
self._url = self._cli_options.auth.get('url', None)
93+
self._url = self._cli_options.auth.get('url')
9494
self._region_name = self._cli_options.region_name
9595
self._interface = self._cli_options.interface
9696

@@ -146,7 +146,7 @@ def setup_auth(self, required_scope=True):
146146
# Horrible hack alert...must handle prompt for null password if
147147
# password auth is requested.
148148
if (self.auth_plugin_name.endswith('password') and
149-
not self._cli_options.auth.get('password', None)):
149+
not self._cli_options.auth.get('password')):
150150
self._cli_options.auth['password'] = self._pw_callback()
151151

152152
(auth_plugin, self._auth_params) = auth.build_auth_params(
@@ -162,9 +162,9 @@ def setup_auth(self, required_scope=True):
162162
# PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
163163
if (self._api_version.get('identity') == '3' and
164164
self.auth_plugin_name.endswith('password') and
165-
not self._auth_params.get('project_domain_id', None) and
165+
not self._auth_params.get('project_domain_id') and
166166
not self.auth_plugin_name.startswith('v2') and
167-
not self._auth_params.get('project_domain_name', None)):
167+
not self._auth_params.get('project_domain_name')):
168168
self._auth_params['project_domain_id'] = default_domain
169169

170170
# NOTE(stevemar): If USER_DOMAIN_ID or USER_DOMAIN_NAME is present,
@@ -173,8 +173,8 @@ def setup_auth(self, required_scope=True):
173173
if (self._api_version.get('identity') == '3' and
174174
self.auth_plugin_name.endswith('password') and
175175
not self.auth_plugin_name.startswith('v2') and
176-
not self._auth_params.get('user_domain_id', None) and
177-
not self._auth_params.get('user_domain_name', None)):
176+
not self._auth_params.get('user_domain_id') and
177+
not self._auth_params.get('user_domain_name')):
178178
self._auth_params['user_domain_id'] = default_domain
179179

180180
# For compatibility until all clients can be updated

openstackclient/common/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def from_response(response, body):
122122
if body:
123123
if hasattr(body, 'keys'):
124124
error = body[body.keys()[0]]
125-
message = error.get('message', None)
126-
details = error.get('details', None)
125+
message = error.get('message')
126+
details = error.get('details')
127127
else:
128128
# If we didn't get back a properly formed error message we
129129
# probably couldn't communicate with Keystone at all.

openstackclient/common/logs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def configure(self, cloud_config):
169169
self.dump_trace = cloud_config.config.get('debug', self.dump_trace)
170170
self.console_logger.setLevel(log_level)
171171

172-
log_file = cloud_config.config.get('log_file', None)
172+
log_file = cloud_config.config.get('log_file')
173173
if log_file:
174174
if not self.file_logger:
175175
self.file_logger = logging.FileHandler(filename=log_file)
@@ -179,7 +179,7 @@ def configure(self, cloud_config):
179179
self.file_logger.setLevel(log_level)
180180
self.root_logger.addHandler(self.file_logger)
181181

182-
logconfig = cloud_config.config.get('logging', None)
182+
logconfig = cloud_config.config.get('logging')
183183
if logconfig:
184184
highest_level = logging.NOTSET
185185
for k in logconfig.keys():

0 commit comments

Comments
 (0)