Internal helper for creating a requests `session` with the correct
        authentication handling.
188887
def _build_session(self, auth_class, *args, **kwargs):
        
        session = requests.session()
        session.auth = auth_class(*args, **kwargs)
        session.headers.update({'CB-VERSION': self.API_VERSION,
                                'Accept': 'application/json',
                                'Content-Type': 'application/json',
                                'User-Agent': 'coinbase/python/2.0'})
        return session
513311
def _put_request(self, url, headers, data=None):
        
        return self._session.put(url, headers=headers, data=data)
1170656
def raw_request(self, method, resource, access_token=None, **kwargs):
        
        headers = self._pop_headers(kwargs)
        headers['Authorization'] = self._get_authorization_header(access_token)
        url = self._get_resource_url(resource)
        return self.session.request(method, url, allow_redirects=True, headers=headers, **kwargs)
639517
def _get_requests_session():
    """"""
    global requests_session
    if requests_session is not None:
        return requests_session
    import requests

    requests_session = requests.Session()
    adapter = requests.adapters.HTTPAdapter(
        max_retries=environments.PIPENV_MAX_RETRIES
    )
    requests_session.mount("https://pypi.org/pypi", adapter)
    return requests_session
660774
def create_session(self):
        
        ret = requests.Session()
        ret.headers['User-Agent'] = self.user_agent
        for k, v in self.options.items():
            setattr(ret, k, v)
        return ret
138542
def get_session(user_agent):
    """"""

    client = requests.Session()
    client.headers.update({
        'Content-Type': 'application/json',
        'User-Agent': user_agent,
    })
    retry = Retry(connect=3, backoff_factor=3)
    adapter = HTTPAdapter(max_retries=retry)
    client.mount('https://', adapter)
    return client
710204
def create_session(self, name=None):
        
        self.session = Session.create(self, name=name)
        return self.session
1217486
def _make_request(session, url, argument=None, params=None, raw=False):
    """"""
    if not params:
        params = {}
    params['key'] = session.auth.key
    try:
        if argument:
            request_url = '{}{}{}{}'.format(session.auth.base_url, VOOBLY_API_URL, url, argument)
        else:
            request_url = '{}{}'.format(VOOBLY_API_URL, url)
        resp = session.get(request_url, params=params)
    except RequestException:
        raise VooblyError('failed to connect')
    if resp.text == 'bad-key':
        raise VooblyError('bad api key')
    elif resp.text == 'too-busy':
        raise VooblyError('service too busy')
    elif not resp.text:
        raise VooblyError('no data returned')
    if raw:
        return resp.text
    try:
        return tablib.Dataset().load(resp.text).dict
    except UnsupportedFormat:
        raise VooblyError('unexpected error {}'.format(resp.text))
484799
def copy_session(session: requests.Session) -> requests.Session:
    """"""
    new = requests.Session()
    new.cookies = requests.utils.cookiejar_from_dict(requests.utils.dict_from_cookiejar(session.cookies))
    new.headers = session.headers.copy()
    return new
814843
def _create_session(self):
        
        self.driver = requests.Session(**self.driver_args)
        # Set default headers
        self.update_headers(self.current_headers)
        self.update_cookies(self.current_cookies)
        self.set_proxy(self.current_proxy)
1006387
def _authenticate(self, request):
        

        def ensure_user_obj():
            """ Make sure that request object has user property.

            If `request.user` is not present or is `None`, it is
            created and initialized with `AnonymousUser`.
            """

            try:
                if request.user:
                    return
            except AttributeError:
                pass

            request.user = AnonymousUser()

        def anonymous_access(exc_obj):
            """ Determine what to do with unauthenticated requests.

            If the request has already been authenticated, does
            nothing.

            :param exc_obj: exception object to be thrown if anonymous
            access is not permitted.
            """

            if request.user and request.user.is_authenticated():
                # request is already authenticated
                pass
            elif self.allow_anonymous:
                request.user = AnonymousUser()
            else:
                raise exc_obj

        # first, make sure that the request carries `user` attribute
        ensure_user_obj()
        if self.authentication:
            # authentication handler is configured
            try:
                self.authentication.authenticate(request)
            except errors.Unauthorized, exc:
                # http request doesn't carry any authentication information
                anonymous_access(exc)
        else:
            # no authentication configured
            anonymous_access(errors.Forbidden())
970508
function makeSession(session) {
  return {
    authenticated: !!session.token,
    token: session.token,
    scope: session.scope,
    error: session.error,
    errorDescription: session.errorDescription
  };
}
134460
def create_session(cls, session_id, user_id):
        
        count = SessionModel.count(user_id)
        if count < current_app.config['AUTH']['MAX_SESSIONS']:
            cls.__save_session(session_id, user_id)
            return
        elif count >= current_app.config['AUTH']['MAX_SESSIONS']:
            earliest_session = SessionModel.where_earliest(user_id)
            earliest_session.delete()
            cls.__save_session(session_id, user_id)
            return
455542
def authenticate(self, api_key):
        """"""
        self._api_key = api_key

        # Attach auth to session.
        self._session.auth = ('', self._api_key)

        return self._verify_api_key()
1160210
def authenticated(function):
    """"""
    def wrapped(session, *args, **kwargs):
        """Wrap function."""
        try:
            return function(session, *args, **kwargs)
        except VooblyError:
            with session.cache_disabled():
                _LOGGER.info("attempted to access page before login")
                login(session)
                return function(session, *args, **kwargs)
    return wrapped
939359
def _make_session():
        

        sess = requests.Session()
        sess.mount('http://', requests.adapters.HTTPAdapter(max_retries=False))
        sess.mount('https://', requests.adapters.HTTPAdapter(max_retries=False))

        return sess
1271366
def session(self, auth=None):
        
        url = '{server}{auth_url}'.format(**self._options)

        if isinstance(self._session.auth, tuple) or auth:
            if not auth:
                auth = self._session.auth
            username, password = auth
            authentication_data = {'username': username, 'password': password}
            r = self._session.post(url, data=json.dumps(authentication_data))
        else:
            r = self._session.get(url)

        user = User(self._options, self._session, json_loads(r))
        return user