# Path: falconswagger/models/orm/session.py
# class _SessionBase(SessionSA):
#     def __init__(
#             self, bind=None, autoflush=True,
#             expire_on_commit=True, _enable_transaction_accounting=True,
#             autocommit=False, twophase=False, weak_identity_map=True,
#             binds=None, extension=None, info=None, query_cls=Query, redis_bind=None):
#     def _clean_redis_sets(self):
#     def commit(self):
#     def delete(self, instance):
#     def _update_objects_on_redis(self):
#     def _exec_hdel(self, insts):
#     def _get_filters_names_set(self, inst):
#     def _exec_hmset(self, insts):
#     def mark_for_hdel(self, inst):
#     def mark_for_hmset(self, inst):
# def deleted_from_database(session, instance):
# def added_to_database(session, instance):
# 
# Path: falconswagger/models/orm/sqlalchemy_redis.py
# class ModelSQLAlchemyRedisMeta(
#         ModelSQLAlchemyRedisInitMetaMixin,
#         ModelSQLAlchemyRedisOperationsMetaMixin):
#     pass


from falconswagger.models.orm.session import Session
from falconswagger.models.orm.sqlalchemy_redis import ModelSQLAlchemyRedisMeta
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.




class SessionMiddleware(object):

    def __init__(self, sqlalchemy_bind=None, redis_bind=None):
        self.sqlalchemy_bind = sqlalchemy_bind
        self.redis_bind = redis_bind

    def process_resource(self, req, resp, model, uri_params):
        if getattr(model, '__session__', None):
            req.context['session'] = model.__session__
            return


# Path: falconswagger/models/orm/session.py
# class _SessionBase(SessionSA):
#     def __init__(
#             self, bind=None, autoflush=True,
#             expire_on_commit=True, _enable_transaction_accounting=True,
#             autocommit=False, twophase=False, weak_identity_map=True,
#             binds=None, extension=None, info=None, query_cls=Query, redis_bind=None):
#     def _clean_redis_sets(self):
#     def commit(self):
#     def delete(self, instance):
#     def _update_objects_on_redis(self):
#     def _exec_hdel(self, insts):
#     def _get_filters_names_set(self, inst):
#     def _exec_hmset(self, insts):
#     def mark_for_hdel(self, inst):
#     def mark_for_hmset(self, inst):
# def deleted_from_database(session, instance):
# def added_to_database(session, instance):
# 
# Path: falconswagger/models/orm/sqlalchemy_redis.py
# class ModelSQLAlchemyRedisMeta(
#         ModelSQLAlchemyRedisInitMetaMixin,
#         ModelSQLAlchemyRedisOperationsMetaMixin):
#     pass


# Path: falconswagger/middlewares.py
from falconswagger.models.orm.session import Session
from falconswagger.models.orm.sqlalchemy_redis import ModelSQLAlchemyRedisMeta

# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.




class SessionMiddleware(object):

    def __init__(self, sqlalchemy_bind=None, redis_bind=None):
        self.sqlalchemy_bind = sqlalchemy_bind
        self.redis_bind = redis_bind

    def process_resource(self, req, resp, model, uri_params):
        if getattr(model, '__session__', None):
            req.context['session'] = model.__session__
            return


        req.context['session'] = Session(bind=self.sqlalchemy_bind, redis_bind=self.redis_bind)