# Path: damvitool/static_app.py
# class StaticApp(transaction_app):
#     def __init__(self):
#         super(StaticApp, self).__init__()
#         self.static = Cling(os.path.dirname(__file__) + '/static/')
# 
#     def __call__(self, environ, start_response):
#         request = self.request(environ)
#         response = self.publish(request)
#         if response.status_code == 404:
#             response = self.static.__call__(environ, start_response)
#             return response
#         return response(environ, start_response)


import morepath
import traceback
import logging
import time
from damvitool.static_app import StaticApp
from webob.exc import HTTPNotFound
__author__ = 'alex-smirnov'


@StaticApp.tween_factory(under=morepath.EXCVIEW)
def error_tween_factory(app, handler):
    def error_tween(request):
        """Intercepts exception, print info and reraise

        """
        try:
            return handler(request)
        except Exception as e:
            if not isinstance(e, HTTPNotFound):
                logging.warning(traceback.format_exc())
            raise e

    return error_tween



# Path: damvitool/static_app.py
# class StaticApp(transaction_app):
#     def __init__(self):
#         super(StaticApp, self).__init__()
#         self.static = Cling(os.path.dirname(__file__) + '/static/')
# 
#     def __call__(self, environ, start_response):
#         request = self.request(environ)
#         response = self.publish(request)
#         if response.status_code == 404:
#             response = self.static.__call__(environ, start_response)
#             return response
#         return response(environ, start_response)


# Path: damvitool/log.py
import morepath
import traceback
import logging
import time
from damvitool.static_app import StaticApp
from webob.exc import HTTPNotFound

__author__ = 'alex-smirnov'


@StaticApp.tween_factory(under=morepath.EXCVIEW)
def error_tween_factory(app, handler):
    def error_tween(request):
        """Intercepts exception, print info and reraise

        """
        try:
            return handler(request)
        except Exception as e:
            if not isinstance(e, HTTPNotFound):
                logging.warning(traceback.format_exc())
            raise e

    return error_tween



@StaticApp.tween_factory(over=morepath.EXCVIEW)