This commit is contained in:
Laurent Mazuel 2018-03-01 08:46:38 -08:00
Родитель b79de4259d
Коммит 3e9de0f609
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 8A1A37C887DC49D8
4 изменённых файлов: 35 добавлений и 21 удалений

Просмотреть файл

@ -40,13 +40,13 @@ class Authentication(object):
"""Create requests session with any required auth headers
applied.
:rtype: requests.Session.
:rtype: requests.Session
"""
return requests.Session()
class BasicAuthentication(Authentication):
"""Implmentation of Basic Authentication.
"""Implementation of Basic Authentication.
:param str username: Authentication username.
:param str password: Authentication password.
@ -61,7 +61,7 @@ class BasicAuthentication(Authentication):
"""Create requests session with any required auth headers
applied.
:rtype: requests.Session.
:rtype: requests.Session
"""
session = super(BasicAuthentication, self).signed_session()
session.auth = HTTPBasicAuth(self.username, self.password)
@ -72,7 +72,7 @@ class BasicTokenAuthentication(Authentication):
"""Simple Token Authentication.
Does not adhere to OAuth, simply adds provided token as a header.
:param dict token: Authentication token, must have 'access_token' key.
:param dict[str,str] token: Authentication token, must have 'access_token' key.
"""
def __init__(self, token):
@ -91,7 +91,7 @@ class BasicTokenAuthentication(Authentication):
"""Create requests session with any required auth headers
applied.
:rtype: requests.Session.
:rtype: requests.Session
"""
session = super(BasicTokenAuthentication, self).signed_session()
header = "{} {}".format(self.scheme, self.token['access_token'])
@ -104,7 +104,7 @@ class OAuthTokenAuthentication(BasicTokenAuthentication):
Requires that supplied token contains an expires_in field.
:param str client_id: Account Client ID.
:param dict token: OAuth2 token.
:param dict[str,str] token: OAuth2 token.
"""
def __init__(self, client_id, token):
@ -116,7 +116,7 @@ class OAuthTokenAuthentication(BasicTokenAuthentication):
def construct_auth(self):
"""Format token header.
:rtype: str.
:rtype: str
"""
return "{} {}".format(self.scheme, self.token)
@ -124,25 +124,24 @@ class OAuthTokenAuthentication(BasicTokenAuthentication):
"""Return updated session if token has expired, attempts to
refresh using refresh token.
:rtype: requests.Session.
:rtype: requests.Session
"""
return self.signed_session()
def signed_session(self):
"""Create requests session with any required auth headers
applied.
"""Create requests session with any required auth headers applied.
:rtype: requests.Session.
:rtype: requests.Session
"""
return oauth.OAuth2Session(self.id, token=self.token)
class ApiKeyCredentials(Authentication):
"""Represent the ApiKey feature of Swagger.
Dict should be dict[str, str] to be accepted by requests.
Dict should be dict[str,str] to be accepted by requests.
:param dict[str, str] in_headers: Headers part of the ApiKey
:param dict[str, str] in_query: ApiKey in the query as parameters.
:param dict[str,str] in_headers: Headers part of the ApiKey
:param dict[str,str] in_query: ApiKey in the query as parameters
"""
def __init__(self, in_headers=None, in_query=None):
if in_headers is None:
@ -159,7 +158,7 @@ class ApiKeyCredentials(Authentication):
def signed_session(self):
"""Create requests session with ApiKey.
:rtype: requests.Session.
:rtype: requests.Session
"""
session = super(ApiKeyCredentials, self).signed_session()
session.headers.update(self.in_headers)

Просмотреть файл

@ -49,10 +49,10 @@ def default_session_configuration_callback(session, global_config, local_config,
:param requests.Session session: The session.
:param Configuration global_config: The global configuration.
:param dict local_config: The on-the-fly configuration passed on the call.
:param dict kwargs: The current computed values for session.request method.
:param dict[str,str] local_config: The on-the-fly configuration passed on the call.
:param dict[str,str] kwargs: The current computed values for session.request method.
:return: Must return kwargs, to be passed to session.request. If None is return, initial kwargs will be used.
:rtype: dict
:rtype: dict[str,str]
"""
return kwargs
@ -102,9 +102,14 @@ class Configuration(object):
@property
def user_agent(self):
"""The current user agent value."""
return self._user_agent
def add_user_agent(self, value):
"""Add value to current user agent with a space.
:param str value: value to add to user agent.
"""
self._user_agent = "{} {}".format(self._user_agent, value)
def _clear_config(self):
@ -117,7 +122,6 @@ class Configuration(object):
:param str filepath: Path to file where settings will be saved.
:raises: ValueError if supplied filepath cannot be written to.
:rtype: None
"""
sections = [
"Connection",
@ -159,7 +163,6 @@ class Configuration(object):
:param str filepath: Path to existing config file.
:raises: ValueError if supplied config file is invalid.
:rtype: None
"""
try:
self._config.read(filepath)

Просмотреть файл

@ -65,6 +65,10 @@ class Paged(Iterator):
@property
def raw(self):
"""Get current page as ClientRawResponse.
:rtype: ClientRawResponse
"""
raw = ClientRawResponse(self.current_page, self._response)
if self._raw_headers:
raw.add_headers(self._raw_headers)
@ -89,6 +93,14 @@ class Paged(Iterator):
self._current_page_iter_index = 0
def advance_page(self):
"""Force moving the cursor to the next azure call.
This method is for advanced usage, iterator protocol is prefered.
:raises: StopIteration if no further page
:return: The current page list
:rtype: list
"""
if self.next_link is None:
raise StopIteration("End of paging")
self._current_page_iter_index = 0

Просмотреть файл

@ -24,5 +24,5 @@
#
# --------------------------------------------------------------------------
#: version of this package. Use msrest.__version__ instead
msrest_version = "0.4.26"