# Path: kokemomo/plugins/engine/controller/km_backend/km_plugin_manager.py
# class KMBaseController(object):
#     __metaclass__ = ABCMeta
# 
#     def __init__(self):
#         self.name = self.get_name()
#         self.logger = KMLogger(self.get_name())
#         self.data = KMData(self)
#         self.result = {}
#         self.plugin = KMPluginManager.get_instance().create_base_plugin(self.name)
#         for route in self.get_route_list():
#             if 'name' in route:
#                 self.add_route(route['rule'], route['method'], route['target'], route['name'])
#             else:
#                 self.add_route(route['rule'], route['method'], route['target'])
# 
#     @staticmethod
#     def action(template=None):
#         '''
# 
#         :param template:
#         :return:
#         '''
#         def _action(callback):
#             @wraps(callback)
#             def wrapper(*args, **kwargs):
#                 res = callback(*args, **kwargs)
#                 if template is None:
#                     return res
#                 else:
#                     # args[0]はself
#                     args[0].result['url'] = args[0].get_url # Method for calling from template.
#                     args[0].result['user_id'] = args[0].data.get_user_id()
#                     return args[0].render(template, result=args[0].result)
#             return wrapper
#         return _action
# 
#     def check_login():
#         """
#         """
#         def _check_login(callback):
#             @wraps(callback)
#             def wrapper(*args, **kwargs):
#                 user_id = KMLogin.get_session(args[0].data.get_request())
#                 if user_id is not None:
#                     return callback(*args, **kwargs)
#                 return args[0].redirect('/engine/auth_error')
#             return wrapper
#         return _check_login
# 
# 
#     @abstractmethod
#     def get_name(self):
#         pass
# 
#     @abstractmethod
#     def get_route_list(self):
#         pass
# 
#     def get_url(self, routename, filename):
#         return urljoin('/' + self.name + '/',
#                        self.plugin.app.get_url(routename, filename=filename))
# 
#     def add_route(self, rule, method, target, name=None):
#         self.plugin.add_route(
#             {'rule': rule, 'method': method, 'target': target, 'name': name}
#         )
# 
#     def render(self, template_path, **params):
#         return self.plugin.render(template_path, params)
# 
#     def load_static_file(self, filename, root):
#         # TODO 他のプラグインからの読み込みに対応する必要がある
#         return self.plugin.load_static_file(filename, root)
# 
#     def redirect(self, url, code=None):
#         self.plugin.redirect(url, code)
# 
# Path: kokemomo/plugins/engine/controller/km_exception.py
# def log(callback):
#     def wrapper(*args, **kwargs):
#         try:
#             return callback(*args, **kwargs)
#         except KMException as kme:
#             error("An error has occurred in the kokemomo.")
#             error(format_exc())
#             error(kme.msg)
#             raise kme
#         except BaseException as e:
#             error("An error has occurred in the application.")
#             error(format_exc())
#             raise e
#     return wrapper


import os
from .km_backend.km_plugin_manager import KMBaseController
from .km_exception import log
#!/usr/bin/env python
# -*- coding: utf-8 -*-


__author__ = 'hiroki'


class KMEngine(KMBaseController):

    def get_name(self):
        return 'engine'


    def get_route_list(self):
        list = (
            {'rule': '/engine-js/<filename>', 'method': 'GET', 'target': self.engine_js_static, 'name': 'engine_static_js'},
            {'rule': '/engine-css/<filename>', 'method': 'GET', 'target': self.engine_css_static, 'name': 'engine_static_css'},
            {'rule': '/engine-img/<filename>', 'method': 'GET', 'target': self.engine_img_static, 'name': 'engine_static_img'},
            {'rule': '/error', 'method': 'GET', 'target': self.engine_error},
            {'rule': '/auth_error', 'method': 'GET', 'target': self.engine_auth_error},
        )
        return list



# Path: kokemomo/plugins/engine/controller/km_backend/km_plugin_manager.py
# class KMBaseController(object):
#     __metaclass__ = ABCMeta
# 
#     def __init__(self):
#         self.name = self.get_name()
#         self.logger = KMLogger(self.get_name())
#         self.data = KMData(self)
#         self.result = {}
#         self.plugin = KMPluginManager.get_instance().create_base_plugin(self.name)
#         for route in self.get_route_list():
#             if 'name' in route:
#                 self.add_route(route['rule'], route['method'], route['target'], route['name'])
#             else:
#                 self.add_route(route['rule'], route['method'], route['target'])
# 
#     @staticmethod
#     def action(template=None):
#         '''
# 
#         :param template:
#         :return:
#         '''
#         def _action(callback):
#             @wraps(callback)
#             def wrapper(*args, **kwargs):
#                 res = callback(*args, **kwargs)
#                 if template is None:
#                     return res
#                 else:
#                     # args[0]はself
#                     args[0].result['url'] = args[0].get_url # Method for calling from template.
#                     args[0].result['user_id'] = args[0].data.get_user_id()
#                     return args[0].render(template, result=args[0].result)
#             return wrapper
#         return _action
# 
#     def check_login():
#         """
#         """
#         def _check_login(callback):
#             @wraps(callback)
#             def wrapper(*args, **kwargs):
#                 user_id = KMLogin.get_session(args[0].data.get_request())
#                 if user_id is not None:
#                     return callback(*args, **kwargs)
#                 return args[0].redirect('/engine/auth_error')
#             return wrapper
#         return _check_login
# 
# 
#     @abstractmethod
#     def get_name(self):
#         pass
# 
#     @abstractmethod
#     def get_route_list(self):
#         pass
# 
#     def get_url(self, routename, filename):
#         return urljoin('/' + self.name + '/',
#                        self.plugin.app.get_url(routename, filename=filename))
# 
#     def add_route(self, rule, method, target, name=None):
#         self.plugin.add_route(
#             {'rule': rule, 'method': method, 'target': target, 'name': name}
#         )
# 
#     def render(self, template_path, **params):
#         return self.plugin.render(template_path, params)
# 
#     def load_static_file(self, filename, root):
#         # TODO 他のプラグインからの読み込みに対応する必要がある
#         return self.plugin.load_static_file(filename, root)
# 
#     def redirect(self, url, code=None):
#         self.plugin.redirect(url, code)
# 
# Path: kokemomo/plugins/engine/controller/km_exception.py
# def log(callback):
#     def wrapper(*args, **kwargs):
#         try:
#             return callback(*args, **kwargs)
#         except KMException as kme:
#             error("An error has occurred in the kokemomo.")
#             error(format_exc())
#             error(kme.msg)
#             raise kme
#         except BaseException as e:
#             error("An error has occurred in the application.")
#             error(format_exc())
#             raise e
#     return wrapper


# Path: kokemomo/plugins/engine/controller/km_engine.py
import os
from .km_backend.km_plugin_manager import KMBaseController
from .km_exception import log

#!/usr/bin/env python
# -*- coding: utf-8 -*-


__author__ = 'hiroki'


class KMEngine(KMBaseController):

    def get_name(self):
        return 'engine'


    def get_route_list(self):
        list = (
            {'rule': '/engine-js/<filename>', 'method': 'GET', 'target': self.engine_js_static, 'name': 'engine_static_js'},
            {'rule': '/engine-css/<filename>', 'method': 'GET', 'target': self.engine_css_static, 'name': 'engine_static_css'},
            {'rule': '/engine-img/<filename>', 'method': 'GET', 'target': self.engine_img_static, 'name': 'engine_static_img'},
            {'rule': '/error', 'method': 'GET', 'target': self.engine_error},
            {'rule': '/auth_error', 'method': 'GET', 'target': self.engine_auth_error},
        )
        return list



    @log