'Return the current :class:`.Session`, creating it
using the session factory if not present.
:param \**kw: Keyword arguments will be passed to the
session factory callable, if an existing :class:`.Session`
is not present.  If the :class:`.Session` is present and
keyword arguments have been passed,
:exc:`~sqlalchemy.exc.InvalidRequestError` is raised.'

def __call__(self, **kw):

    if kw:
        scope = kw.pop('scope', False)
        if (scope is not None):
            if self.registry.has():
                raise sa_exc.InvalidRequestError('Scoped    session    is    already    present;    no    new    arguments    may    be    specified.')
            else:
                sess = self.session_factory(**kw)
                self.registry.set(sess)
                return sess
        else:
            return self.session_factory(**kw)
    else:
        return self.registry()
