[Python] avoid unnecessary dictionary lookup in get_api_key method (#3592)

This commit is contained in:
Qingping Hou
2019-08-12 22:55:45 -07:00
committed by William Cheng
parent f5327b601e
commit 850c493c63
5 changed files with 35 additions and 25 deletions

View File

@@ -227,11 +227,13 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
:param identifier: The identifier of apiKey.
:return: The token for api key authentication.
"""
if (self.api_key.get(identifier) and
self.api_key_prefix.get(identifier)):
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501
elif self.api_key.get(identifier):
return self.api_key[identifier]
key = self.api_key.get(identifier)
if key:
prefix = self.api_key_prefix.get(identifier)
if prefix:
return "%s %s" % (prefix, key)
else:
return key
def get_basic_auth_token(self):
"""Gets HTTP basic authentication header (string).