# Path: ziggurat_foundations/exc.py
# class ZigguratSessionException(ZigguratException):
#     pass


import sqlalchemy as sa
from ziggurat_foundations.exc import ZigguratSessionException
    from ziggurat_foundations import models
        db_session.delete(self)

def get_db_session(session=None, obj=None):
    """
    utility function that attempts to return sqlalchemy session that could
    have been created/passed in one of few ways:

    * It first tries to read session attached to instance
      if object argument was passed

    * then it tries to return  session passed as argument

    * finally tries to read pylons-like threadlocal called DBSession

    * if this fails exception is thrown

    :param session:
    :param obj:
    :return:
    """
    # try to read the session from instance

    if obj:
        return sa.orm.session.object_session(obj)
    # try passed session
    elif session:
        return session
    # try global pylons-like session then
    elif models.DBSession:
        return models.DBSession

# Path: ziggurat_foundations/exc.py
# class ZigguratSessionException(ZigguratException):
#     pass


# Path: ziggurat_foundations/models/base.py
import sqlalchemy as sa
from ziggurat_foundations.exc import ZigguratSessionException
    from ziggurat_foundations import models

        db_session.delete(self)

def get_db_session(session=None, obj=None):
    """
    utility function that attempts to return sqlalchemy session that could
    have been created/passed in one of few ways:

    * It first tries to read session attached to instance
      if object argument was passed

    * then it tries to return  session passed as argument

    * finally tries to read pylons-like threadlocal called DBSession

    * if this fails exception is thrown

    :param session:
    :param obj:
    :return:
    """
    # try to read the session from instance

    if obj:
        return sa.orm.session.object_session(obj)
    # try passed session
    elif session:
        return session
    # try global pylons-like session then
    elif models.DBSession:
        return models.DBSession

    raise ZigguratSessionException("No Session found")