Example #1
0
    def __init__(self, url, token=None, auth=None, retries=None, session_class=None):
        if auth is None:
            auth = Auth()

        if token is not None:
            warn(
                "setting token at service level will be removed in future",
                DeprecationWarning,
            )
            auth._token = token

        self.auth = auth
        self.base_url = url

        if retries is None:
            self._adapter = Service.ADAPTER
        else:
            self._adapter = ThreadLocalWrapper(lambda: HTTPAdapter(max_retries=retries))

        if session_class is None:
            self._session_class = WrappedSession
        else:
            self._session_class = session_class

        # Sessions can't be shared across threads or processes because the underlying
        # SSL connection pool can't be shared. We create them thread-local to avoid
        # intractable exceptions when users naively share clients e.g. when using
        # multiprocessing.
        self._session = ThreadLocalWrapper(self.build_session)
    def __init__(self,
                 url,
                 token=None,
                 auth=None,
                 retries=None,
                 session_class=None):
        if auth is None:
            auth = Auth()

        if token is not None:
            warn(
                "setting token at service level will be removed in future",
                FutureWarning,
            )
            auth._token = token

        self.auth = auth
        self.base_url = url

        if retries is None:
            self._adapter = self.ADAPTER
        else:
            self.RETRY_CONFIG = retries
            self._init_adapter()

        if session_class is not None:
            # Overwrite the default session class
            if not issubclass(session_class, Session):
                raise TypeError(
                    "The session class must be a subclass of {}.".format(
                        Session))

            self._session_class = session_class

        self._init_session()
Example #3
0
    def test_token_expired(self, _get_token):
        auth = Auth(token_info_path=None,
                    client_secret="client_secret",
                    client_id="ZOBAi4UROl5gKZIpxxlwOEfx8KpqXf2c")
        token = b".".join(
            (base64.b64encode(to_bytes(p))
             for p in ["header", json.dumps(dict(exp=0)), "sig"]))
        auth._token = token

        self.assertEqual(auth.token, token)
        _get_token.assert_called_once()
Example #4
0
    def __init__(self, url, token=None, auth=None):
        if auth is None:
            auth = Auth()

        if token is not None:
            warn("setting token at service level will be removed in future", DeprecationWarning)
            auth._token = token

        self.auth = auth

        self.base_url = url

        self._session = self.build_session()
Example #5
0
    def test_token_in_leeway_autherror(self, _get_token):
        auth = Auth(token_info_path=None,
                    client_secret="client_secret",
                    client_id="ZOBAi4UROl5gKZIpxxlwOEfx8KpqXf2c")
        exp = (datetime.datetime.utcnow() -
               datetime.datetime(1970, 1, 1)).total_seconds() + auth.leeway / 2
        token = b".".join(
            (base64.b64encode(to_bytes(p))
             for p in ["header", json.dumps(dict(exp=exp)), "sig"]))
        auth._token = token

        self.assertEqual(auth.token, token)
        _get_token.assert_called_once()
    def test_token(self, _get_token):
        auth = Auth(
            token_info_path=None,
            client_secret="client_secret",
            client_id="ZOBAi4UROl5gKZIpxxlwOEfx8KpqXf2c",
        )
        token = b".".join(
            (base64.b64encode(to_bytes(p))
             for p in ["header",
                       json.dumps(dict(exp=9999999999)), "sig"]))
        auth._token = token

        assert auth.token == token
        _get_token.assert_not_called()
    def __init__(self, url, token=None, auth=None):
        if auth is None:
            auth = Auth()

        if token is not None:
            warn("setting token at service level will be removed in future",
                 DeprecationWarning)
            auth._token = token

        self.auth = auth

        self.base_url = url

        # Sessions can't be shared across threads or processes because the underlying
        # SSL connection pool can't be shared. We create them thread-local to avoid
        # intractable exceptions when users naively share clients e.g. when using
        # multiprocessing.
        self._session = ThreadLocalWrapper(self.build_session)