(self, username_key=None, **attributes)
return session
Create a new session and persist it according to its username and token
        values.

        :param attributes: Keyword parameters containing zero or more of
            ``username``, ``token``, and ``tenant_id``.  Any fields that are
            not specified will be filled out automatically.

        :return: A new session with all fields filled out and an expiration
                 time 1 day in the future (according to the clock associated
                 with this :obj:`MimicCore`).
        :rtype: :obj:`Session`
Create a new session and persist it according to its username and token
        values.
Create a new session and persist it according to its username and token values .
def _new_session(self, username_key=None, **attributes):
        """
        Create a new session and persist it according to its username and token
        values.

        :param attributes: Keyword parameters containing zero or more of
            ``username``, ``token``, and ``tenant_id``.  Any fields that are
            not specified will be filled out automatically.

        :return: A new session with all fields filled out and an expiration
                 time 1 day in the future (according to the clock associated
                 with this :obj:`MimicCore`).
        :rtype: :obj:`Session`
        """
        for key in ['username', 'token', 'tenant_id']:
            if attributes.get(key, None) is None:
                attributes[key] = key + "_" + text_type(uuid4())
                if key == 'tenant_id':
                    # integer tenant IDs - uuid4 ints are too long
                    attributes[key] = text_type(int(uuid4().int % 1e15))

        if 'expires' not in attributes:
            attributes['expires'] = (
                datetime.utcfromtimestamp(self.clock.seconds())
                + timedelta(days=1)
            )

        session = Session(**attributes)
        if username_key is None:
            username_key = session.username
        self._username_to_token[username_key] = session.token
        self._token_to_session[session.token] = session
        self._userid_to_session[session.user_id] = session
        self._tenant_to_session[session.tenant_id] = session
        return session
def _new_session ( self , username_key = None , * * attributes ) : for key in [ 'username' , 'token' , 'tenant_id' ] : if attributes . get ( key , None ) is None : attributes [ key ] = key + "_" + text_type ( uuid4 ( ) ) if key == 'tenant_id' : # integer tenant IDs - uuid4 ints are too long attributes [ key ] = text_type ( int ( uuid4 ( ) . int % 1e15 ) ) if 'expires' not in attributes : attributes [ 'expires' ] = ( datetime . utcfromtimestamp ( self . clock . seconds ( ) ) + timedelta ( days = 1 ) ) session = Session ( * * attributes ) if username_key is None : username_key = session . username self . _username_to_token [ username_key ] = session . token self . _token_to_session [ session . token ] = session self . _userid_to_session [ session . user_id ] = session self . _tenant_to_session [ session . tenant_id ] = session return session