Given a request return a session key that will be used. There may already
    be a session key associated, but if there is not, we force the session to
    create itself and persist between requests for the client behind the given
    request.
977475
def ensure_session_key(request):
    
    key = request.session.session_key
    if key is None:
        # @@@ Django forces us to handle session key collision amongst
        # multiple processes (not handled)
        request.session.save()
        # force session to persist for client
        request.session.modified = True
        key = request.session.session_key
    return key
1358553
def use(self, client_key):
        
        if not self.clients.has_client(client_key):
            raise ClientNotExist()

        self.current_client = self.clients.get_client(client_key)

        return self
609712
def get_session_key(limedict):
    """"""
    url = limedict['url']
    user = limedict['username']
    password = limedict['password']
    params = {'username': user, 'password': password}
    data = set_params('get_session_key', params)
    req = requests.post(url, data=data, headers=headers)
    return {'token': req.json()['result'], 'user': user, 'url': url}
668631
def add_request_session(self):
        """"""
        session = new_request_session(self.config, self.cookies)
        self.request_sessions[thread.get_ident()] = session
406221
def get(self, request):
        

        if request.user.is_authenticated():
            return HttpResponseRedirect(self.get_next(request))

        try:
            user, profile, client = self.get_session_data(request)
        except KeyError:
            return self.error_to_response(request, dict(
                error=_("Social profile is missing from your session.")))
         
        if GENERATE_USERNAME:
            return self.generate_username_and_redirect(request, user, profile, client)
            
        form = self.get_form()(initial=self.get_initial_data(request, user, profile, client))
        
        additional_context = self.get_context(request, user, profile, client)
        return self.render_to_response(dict({'form': form}, **additional_context))
754819
def _retrieve_session(self, session_key):
        
        session_id = session_key.session_id
        if (session_id is None):
            msg = ("Unable to resolve session ID from SessionKey [{0}]."
                   "Returning null to indicate a session could not be "
                   "found.".format(session_key))
            logger.debug(msg)
            return None

        session = self.session_store.read(session_id)

        if (session is None):
            # session ID was provided, meaning one is expected to be found,
            # but we couldn't find one:
            msg2 = "Could not find session with ID [{0}]".format(session_id)
            raise ValueError(msg2)

        return session
946387
public Session getSession(String key) {
        sessionsLockRead.lock();
        try {
            SessionEntry entry = this.sessions.get(key);
            return entry != null ? entry.getSession() : null;
        } finally {
            sessionsLockRead.unlock();
        }
    }
895359
def createSessionForKey(self, key, user):
        
        PersistentSession(
            store=self.store,
            sessionKey=key,
            authenticatedAs=user)
1371552
def get_data(self, request, key='params'):
        
        return request.session.get('%s:%s' % (constants.SESSION_KEY, key))
1217427
def request(self):
        

        headers = {'Accept': 'application/json'}

        # Use API Key if possible
        if self.api_key:
            headers['X-API-KEY'] = self.api_key
            return requests,headers
        else:
            # Try to use OAuth
            if self.token:
                return OAuth2Session(self.client_id, token=self.token),headers
            else:
                raise APIError("No API key and no OAuth session available")
333970
def new_csrf_token(self, session_key):
        
        try:
            csrf_token = self._generate_csrf_token()

            session = self._lookup_required_session(session_key)
            session.set_internal_attribute('csrf_token', csrf_token)
            self.session_handler.on_change(session)

        except AttributeError:
            raise CSRFTokenException('Could not save CSRF_TOKEN to session.')

        return csrf_token
436414
def key_for_request(self, method, url, **kwargs):
        
        if method != 'get':
            return None

        return requests.Request(url=url, params=kwargs.get('params', {})).prepare().url
1056916
public CmsUgcSession getSession(HttpServletRequest request, CmsUUID sessionId) {

        return (CmsUgcSession)request.getSession(true).getAttribute("" + sessionId);
    }
325697
def get_request_token(self, request):
        
        if self.oauth == 'oauth1':
            oauth = OAuth1Session(self.consumer_key, client_secret=self.consumer_secret)
            request_token = oauth.fetch_request_token(self.REQ_TOKEN)
            # Save the request token information for later
            request.session['oauth_token'] = request_token['oauth_token']
            request.session['oauth_token_secret'] = request_token['oauth_token_secret']

            return request_token
        else:
            callback_url = self.callback_url(request)
            oauth = OAuth2Session(client_id=self.consumer_key, redirect_uri=callback_url, scope=self.scope)
            authorization_url, state = oauth.authorization_url(self.AUTH_URL)
            return authorization_url
1040537
def get_key(cls, k, default=None):
        
        k = cls.__name__ + "__" + k
        if k in session:
            return session[k]
        else:
            return default
320434
def authenticate(self, request):
        
        for backend in self.authentication:
            client = backend().authenticate(request)
            if client is not None:
                return client
        return None
1373164
def request(self, method, url, **kwargs):
        
        resp = super(ClientSession, self).request(
            method, url, timeout=self._timeout, **kwargs)

        return resp