Construct keyword parameters for Session.request() and
        Session.resolve_redirects().
356782
def get_request_kwargs(self):
        """"""
        kwargs = dict(stream=True, timeout=self.aggregate.config["timeout"])
        if self.proxy:
            kwargs["proxies"] = {self.proxytype: self.proxy}
        if self.scheme == u"https" and self.aggregate.config["sslverify"]:
            kwargs['verify'] = self.aggregate.config["sslverify"]
        else:
            kwargs['verify'] = False
        return kwargs
1245400
def process_request(self, request_info=None, **kwargs):
        

        if isinstance(request_info, AuthorizationErrorResponse):
            return request_info

        _cid = request_info["client_id"]
        cinfo = self.endpoint_context.cdb[_cid]
        try:
            cookie = kwargs['cookie']
        except KeyError:
            cookie = ''
        else:
            del kwargs['cookie']

        if proposed_user(request_info):
            kwargs['req_user'] = proposed_user(request_info)
        else:
            try:
                _login_hint = request_info['login_hint']
            except KeyError:
                pass
            else:
                if self.endpoint_context.login_hint_lookup:
                    kwargs['req_user'] = self.endpoint_context.login_hint_lookup[
                        _login_hint]

        info = self.setup_auth(request_info, request_info["redirect_uri"],
                               cinfo, cookie, **kwargs)

        if 'error' in info:
            return info

        try:
            _function = info['function']
        except KeyError:  # already authenticated
            logger.debug("- authenticated -")
            logger.debug("AREQ keys: %s" % request_info.keys())

            res = self.authz_part2(info['user'], info['authn_event'],
                                   request_info, cookie=cookie)

            return res
        else:
            try:
                # Run the authentication function
                return {
                    'http_response': _function(**info['args']),
                    'return_uri': request_info["redirect_uri"]
                }
            except Exception as err:
                logger.exception(err)
                return {'http_response': 'Internal error: {}'.format(err)}
715837
def _process_request(self, request):
        """"""

        request.horizon = {'dashboard': None,
                           'panel': None,
                           'async_messages': []}
        if not hasattr(request, "user") or not request.user.is_authenticated:
            # proceed no further if the current request is already known
            # not to be authenticated
            # it is CRITICAL to perform this check as early as possible
            # to avoid creating too many sessions
            return None

        # Since we know the user is present and authenticated, lets refresh the
        # session expiry if configured to do so.
        if getattr(settings, "SESSION_REFRESH", True):
            timeout = getattr(settings, "SESSION_TIMEOUT", 3600)
            token_life = request.user.token.expires - datetime.datetime.now(
                pytz.utc)
            session_time = min(timeout, int(token_life.total_seconds()))
            request.session.set_expiry(session_time)

        if request.is_ajax():
            # if the request is Ajax we do not want to proceed, as clients can
            #  1) create pages with constant polling, which can create race
            #     conditions when a page navigation occurs
            #  2) might leave a user seemingly left logged in forever
            #  3) thrashes db backed session engines with tons of changes
            return None
        # If we use cookie-based sessions, check that the cookie size does not
        # reach the max size accepted by common web browsers.
        if (
            settings.SESSION_ENGINE ==
            'django.contrib.sessions.backends.signed_cookies'
        ):
            max_cookie_size = getattr(
                settings, 'SESSION_COOKIE_MAX_SIZE', None)
            session_cookie_name = getattr(
                settings, 'SESSION_COOKIE_NAME', None)
            session_key = request.COOKIES.get(session_cookie_name)
            if max_cookie_size is not None and session_key is not None:
                cookie_size = sum((
                    len(key) + len(value)
                    for key, value in request.COOKIES.items()
                ))
                if cookie_size >= max_cookie_size:
                    LOG.error(
                        'Total Cookie size for user_id: %(user_id)s is '
                        '%(cookie_size)sB >= %(max_cookie_size)sB. '
                        'You need to configure file-based or database-backed '
                        'sessions instead of cookie-based sessions: '
                        'https://docs.openstack.org/horizon/latest/'
                        'admin/sessions.html',
                        {
                            'user_id': request.session.get(
                                'user_id', 'Unknown'),
                            'cookie_size': cookie_size,
                            'max_cookie_size': max_cookie_size,
                        }
                    )

        tz = utils.get_timezone(request)
        if tz:
            timezone.activate(tz)
1024324
def request(self, method, url, data=None, headers=None, **kwargs):
        """"""
        # pylint: disable=arguments-differ
        # Requests has a ton of arguments to request, but only two
        # (method, url) are required. We pass through all of the other
        # arguments to super, so no need to exhaustively list them here.

        # Use a kwarg for this instead of an attribute to maintain
        # thread-safety.
        _credential_refresh_attempt = kwargs.pop(
            '_credential_refresh_attempt', 0)

        # Make a copy of the headers. They will be modified by the credentials
        # and we want to pass the original headers if we recurse.
        request_headers = headers.copy() if headers is not None else {}

        self.credentials.before_request(
            self._auth_request, method, url, request_headers)

        response = super(AuthorizedSession, self).request(
            method, url, data=data, headers=request_headers, **kwargs)

        # If the response indicated that the credentials needed to be
        # refreshed, then refresh the credentials and re-attempt the
        # request.
        # A stored token may expire between the time it is retrieved and
        # the time the request is made, so we may need to try twice.
        if (response.status_code in self._refresh_status_codes
                and _credential_refresh_attempt < self._max_refresh_attempts):

            _LOGGER.info(
                'Refreshing credentials due to a %s response. Attempt %s/%s.',
                response.status_code, _credential_refresh_attempt + 1,
                self._max_refresh_attempts)

            auth_request_with_timeout = functools.partial(
                self._auth_request, timeout=self._refresh_timeout)
            self.credentials.refresh(auth_request_with_timeout)

            # Recurse. Pass in the original headers, not our modified set.
            return self.request(
                method, url, data=data, headers=headers,
                _credential_refresh_attempt=_credential_refresh_attempt + 1,
                **kwargs)

        return response
161535
def _request(self, method, url, **kwargs):
        # type: (str, str, **Any) -> requests.Response
        """"""
        self.last_request = None
        self.last_response = self.session.request(method, url, auth=self.auth, headers=self.headers, **kwargs)
        self.last_request = self.last_response.request
        self.last_url = self.last_response.url

        if self.last_response.status_code == requests.codes.forbidden:
            raise ForbiddenError(self.last_response.json()['results'][0]['detail'])

        return self.last_response
20168
def prepare_params(request):
    """"""
    return request.replace(
        params={key: dump_param(val) for key, val in request.params.items()
                if val is not None})
230540
def get(self, url, **kwargs):
        
        """

        kwargs.setdefault('allow_redirects', True)
        return self.request('GET', url, **kwargs)
686358
def parse_filters_kwargs(request, client_keywords=None):
    
    filters = {}
    kwargs = {}
    client_keywords = client_keywords or {}
    for param in request.GET:
        param_value = PARAM_MAPPING.get(request.GET[param], request.GET[param])
        if param in client_keywords:
            kwargs[param] = param_value
        else:
            filters[param] = param_value
    return filters, kwargs
596943
def options(self, url, **kwargs):
        
        """

        kwargs.setdefault('allow_redirects', True)
        return self.request('OPTIONS', url, **kwargs)
1017249
def get_redirect_args(self, request, callback):
        """"""
        callback = force_text(request.build_absolute_uri(callback))
        raw_token = self.get_request_token(request, callback)
        token, secret, _ = self.parse_raw_token(raw_token)
        if token is not None and secret is not None:
            request.session[self.session_key] = raw_token
        args = {
            'oauth_token': token,
            'oauth_callback': callback,
        }

        scope = self.get_scope(request)
        if scope:
            args['scope'] = self.scope_separator.join(self.get_scope(request))

        return args
175204
def _build_web_client(cls, session: AppSession):
        ''''''
        cookie_jar = cls._build_cookie_jar(session)
        http_client = cls._build_http_client(session)

        redirect_factory = functools.partial(
            session.factory.class_map['RedirectTracker'],
            max_redirects=session.args.max_redirect
        )

        return session.factory.new(
            'WebClient',
            http_client,
            redirect_tracker_factory=redirect_factory,
            cookie_jar=cookie_jar,
            request_factory=cls._build_request_factory(session),
        )
209450
def _wrap_sessions(sessions, request):
    
    result = set()
    for s in sessions:
        if s is SELF and request:
            result.add(request.session.session_key)
        else:
            result.add(s)
    return result
869870
def get_redirect_url(request):
    

    next_ = request.GET.get(REDIRECT_FIELD_NAME)
    if not next_:
        redirect_url = resolve_url(django_settings.CAS_REDIRECT_URL)
        if django_settings.CAS_IGNORE_REFERER:
            next_ = redirect_url
        else:
            next_ = request.META.get('HTTP_REFERER', redirect_url)
        prefix = urllib_parse.urlunparse(
            (get_protocol(request), request.get_host(), '', '', '', ''),
        )
        if next_.startswith(prefix):
            next_ = next_[len(prefix):]
    return next_
1168861
def configure_boto_session_method_kwargs(self, service, kw):
        """"""
        if service in self.endpoint_urls and not 'endpoint_url' in kw:
            kw['endpoint_url'] = self.endpoint_urls[service]
        return kw
204346
def safe_request(
    url,
    method=None,
    params=None,
    data=None,
    json=None,
    headers=None,
    allow_redirects=False,
    timeout=30,
    verify_ssl=True,
):
    """"""

    session = requests.Session()

    kwargs = {}

    if json:
        kwargs['json'] = json
        if not headers:
            headers = {}
        headers.setdefault('Content-Type', 'application/json')

    if data:
        kwargs['data'] = data

    if params:
        kwargs['params'] = params

    if headers:
        kwargs['headers'] = headers

    if method is None:
        method = 'POST' if (data or json) else 'GET'

    response = session.request(
        method=method,
        url=url,
        allow_redirects=allow_redirects,
        timeout=timeout,
        verify=verify_ssl,
        **kwargs
    )

    return response
312319
def request(self, method, path,
                params=None, headers=None, cookies=None, data=None, json=None, allow_redirects=None, timeout=None):
        
        headers = headers or {}
        timeout = timeout if timeout is not None else self._timeout
        allow_redirects = allow_redirects if allow_redirects is not None else self._allow_redirects

        if self._keep_alive and self.__session is None:
            self.__session = requests.Session()

        if self.__session is not None and not self._use_cookies:
            self.__session.cookies.clear()

        address = self._bake_address(path)
        req_headers = copy.deepcopy(self._additional_headers)
        req_headers.update(headers)

        response = http.request(method, address, session=self.__session,
                                params=params, headers=headers, cookies=cookies, data=data, json=json,
                                allow_redirects=allow_redirects, timeout=timeout)
        if self._auto_assert_ok:
            response.assert_ok()
        return response
1064631
async def _request(self, *, http_verb, api_url, req_args):
        
        if self.session and not self.session.closed:
            async with self.session.request(http_verb, api_url, **req_args) as res:
                self._logger.debug("Ran the request with existing session.")
                return {
                    "data": await res.json(),
                    "headers": res.headers,
                    "status_code": res.status,
                }
        async with aiohttp.ClientSession(
            loop=self._event_loop, timeout=aiohttp.ClientTimeout(total=self.timeout)
        ) as session:
            async with session.request(http_verb, api_url, **req_args) as res:
                self._logger.debug("Ran the request with a new session.")
                return {
                    "data": await res.json(),
                    "headers": res.headers,
                    "status_code": res.status,
                }