def build_engine_session(connection, echo=False, autoflush=None, autocommit=None, expire_on_commit=None,<EOL>scopefunc=None):
if connection is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>engine = create_engine(connection, echo=echo)<EOL>autoflush = autoflush if autoflush is not None else False<EOL>autocommit = autocommit if autocommit is not None else False<EOL>expire_on_commit = expire_on_commit if expire_on_commit is not None else True<EOL>log.debug('<STR_LIT>', autoflush, autocommit, expire_on_commit)<EOL>session_maker = sessionmaker(<EOL>bind=engine,<EOL>autoflush=autoflush,<EOL>autocommit=autocommit,<EOL>expire_on_commit=expire_on_commit,<EOL>)<EOL>session = scoped_session(<EOL>session_maker,<EOL>scopefunc=scopefunc<EOL>)<EOL>return engine, session<EOL>
Build an engine and a session.

    :param str connection: An RFC-1738 database connection string
    :param bool echo: Turn on echoing SQL
    :param Optional[bool] autoflush: Defaults to True if not specified in kwargs or configuration.
    :param Optional[bool] autocommit: Defaults to False if not specified in kwargs or configuration.
    :param Optional[bool] expire_on_commit: Defaults to False if not specified in kwargs or configuration.
    :param scopefunc: Scoped function to pass to :func:`sqlalchemy.orm.scoped_session`
    :rtype: tuple[Engine,Session]

    From the Flask-SQLAlchemy documentation:

    An extra key ``'scopefunc'`` can be set on the ``options`` dict to
    specify a custom scope function.  If it's not provided, Flask's app
    context stack identity is used. This will ensure that sessions are
    created and removed with the request/response cycle, and should be fine
    in most cases.