'Create a new GalaxySession for this request, possibly with a connection
to a previous session (in `prev_galaxy_session`) and an existing user
(in `user_for_new_session`).
Caller is responsible for flushing the returned session.'

def __create_new_session(self, prev_galaxy_session=None, user_for_new_session=None):

    session_key = self.security.get_new_guid()
    galaxy_session = self.app.model.GalaxySession(session_key=session_key, is_valid=True, remote_host=self.request.remote_host, remote_addr=self.request.remote_addr, referer=self.request.headers.get('Referer', None))
    if prev_galaxy_session:
        galaxy_session.prev_session_id = prev_galaxy_session.id
    if user_for_new_session:
        galaxy_session.user = user_for_new_session
    return galaxy_session
