# Path: spline/config/environment.py
# def load_environment(global_conf, app_conf):
#     """Configure the Pylons environment"""
#     config = PylonsConfig()
# 
#     # Pylons paths
#     root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#     paths = dict(root=root,
#                  controllers=os.path.join(root, 'controllers'),
#                  static_files={},
#                  content_files=[],
#                  templates=[os.path.join(root, 'templates')])
# 
#     # Initialize config with the basic options
#     config.init_app(global_conf, app_conf, package='spline', paths=paths)
# 
#     extra_plugins = {}
#     config_dir = os.path.dirname(global_conf['__file__'])
#     paths['local'] = config_dir
#     if config_dir != root:
#         # This app isn't running out of a vanilla spline checkout.  See if it
#         # publishes its own local plugin class, and if not, create a generic
#         # one
#         original_path = sys.path
#         sys.path = [config_dir]
#         try:
#             local_module = __import__('plugin')
#             plugin_class = local_module.LocalPlugin
#         except:
#             plugin_class = LocalPlugin
#         finally:
#             # Restore path no matter what!
#             sys.path = original_path
#         extra_plugins['local'] = plugin_class(config_dir)
# 
#     # Load plugins before routing so we have a list of controllers
#     load_plugins(config, paths, extra_plugins)
#     # Add our static directory
#     paths['static_files']['spline'] = os.path.join(root, 'public')
# 
#     config['routes.map'] = make_map(config, content_dirs=paths['content_files'])
#     config['pylons.app_globals'] = app_globals.Globals(config)
#     pylons.cache._push_object(config['pylons.app_globals'].cache)
#     config['pylons.h'] = spline.lib.helpers
# 
#     # Create the Mako TemplateLookup, with the default auto-escaping
#     module_directory = {}
#     if 'cache_dir' in app_conf:
#         module_directory['module_directory'] \
#             = os.path.join(app_conf['cache_dir'], 'templates')
#     config['pylons.app_globals'].mako_lookup = TemplateLookup(
#         directories=paths['templates'],
#         error_handler=handle_mako_error,
#         input_encoding='utf-8', output_encoding='utf-8',
#         imports=['from webhelpers.html import escape'],
#         default_filters=['escape'],
#         filesystem_checks=asbool(config.get('mako.filesystem_checks', True)),
#         preprocessor=spline.lib.makoext.i18n_preprocessor,
#         **module_directory)
# 
#     # Set up SQLAlchemy database engine
#     engine = engine_from_config(config, 'sqlalchemy.')
#     init_model(engine)
# 
#     # Set up our timer events
#     # We attach them globally to the Engine class so we can automatically track
#     # any other database connections used by the app. *coughpokedexcough*
#     config['spline.sql_debugging'] = asbool(
#         config.get('spline.sql_debugging', False))
#     spline.lib.base.attach_timer(Engine)
#     if config['spline.sql_debugging']:
#         spline.lib.base.attach_query_log(Engine)
# 
#     # Backwards compatibility
#     config['spline._sqlalchemy_proxy'] = None
# 
#     # CONFIGURATION OPTIONS HERE (note: all config options will override
#     # any Pylons config options)
# 
#     # Use strict templating; none of this default-to-empty-string nonsense
#     config['pylons.strict_c'] = True
# 
#     # Remove any stale cron lock
#     del config['pylons.app_globals'].cache.get_cache('spline:cron')['LOCK']
# 
#     return config
# 
# Path: spline/lib/plugin/load.py
# def run_hooks(_spline_hook_name, *args, **kwargs):
#     """Runs the hooks registered for the given name, in priority order, passing
#     along all other arguments.
# 
#     If the hook is called outside the normal request cycle, such as with the
#     `routes_mapping` hook, then the `config` object must be explicitly passed
#     in.
# 
#     Current hooks:
# 
#     after_setup(config)
#         immediately following the Pylons environment setup
# 
#     routes_mapping(config, map)
#         near the end of Routes mapping, just before default routes are defined
# 
#     before_controller(action)
#         immediately before any controller is run
# 
#     after_controller()
#         immediately after any controller is run
#     """
# 
#     config = kwargs.get('config', pylons.config)
#     all_hooks = config['spline.plugins.hooks']
# 
#     if not _spline_hook_name in all_hooks:
#         # No hooks; bail
#         return []
#     hooks = all_hooks[_spline_hook_name]
# 
#     results = []
#     for priority in [1, 2, 3, 4, 5]:
#         if not priority in hooks:
#             # Nothing for this priority; bail
#             continue
# 
#         for function in hooks[priority]:
#             result = function(*args, **kwargs)
#             if result != None:
#                 results.append(result)
# 
#     return results


from beaker.middleware import CacheMiddleware, SessionMiddleware
from paste import request as paste_request
from paste.cascade import Cascade
from paste.registry import RegistryManager
from paste.urlparser import StaticURLParser
from paste.deploy.converters import asbool
from pylons.middleware import ErrorHandler, StatusCodeRedirect
from pylons.wsgiapp import PylonsApp
from routes.middleware import RoutesMiddleware
from spline.config.environment import load_environment
from spline.lib.plugin.load import run_hooks
"""Pylons middleware initialization"""


class SplineApp(PylonsApp):
    def find_controller(self, controller):
        """Controller search method that scans the plugin controller list,
        falling back to the default Pylons way if it's not found."""


# Path: spline/config/environment.py
# def load_environment(global_conf, app_conf):
#     """Configure the Pylons environment"""
#     config = PylonsConfig()
# 
#     # Pylons paths
#     root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#     paths = dict(root=root,
#                  controllers=os.path.join(root, 'controllers'),
#                  static_files={},
#                  content_files=[],
#                  templates=[os.path.join(root, 'templates')])
# 
#     # Initialize config with the basic options
#     config.init_app(global_conf, app_conf, package='spline', paths=paths)
# 
#     extra_plugins = {}
#     config_dir = os.path.dirname(global_conf['__file__'])
#     paths['local'] = config_dir
#     if config_dir != root:
#         # This app isn't running out of a vanilla spline checkout.  See if it
#         # publishes its own local plugin class, and if not, create a generic
#         # one
#         original_path = sys.path
#         sys.path = [config_dir]
#         try:
#             local_module = __import__('plugin')
#             plugin_class = local_module.LocalPlugin
#         except:
#             plugin_class = LocalPlugin
#         finally:
#             # Restore path no matter what!
#             sys.path = original_path
#         extra_plugins['local'] = plugin_class(config_dir)
# 
#     # Load plugins before routing so we have a list of controllers
#     load_plugins(config, paths, extra_plugins)
#     # Add our static directory
#     paths['static_files']['spline'] = os.path.join(root, 'public')
# 
#     config['routes.map'] = make_map(config, content_dirs=paths['content_files'])
#     config['pylons.app_globals'] = app_globals.Globals(config)
#     pylons.cache._push_object(config['pylons.app_globals'].cache)
#     config['pylons.h'] = spline.lib.helpers
# 
#     # Create the Mako TemplateLookup, with the default auto-escaping
#     module_directory = {}
#     if 'cache_dir' in app_conf:
#         module_directory['module_directory'] \
#             = os.path.join(app_conf['cache_dir'], 'templates')
#     config['pylons.app_globals'].mako_lookup = TemplateLookup(
#         directories=paths['templates'],
#         error_handler=handle_mako_error,
#         input_encoding='utf-8', output_encoding='utf-8',
#         imports=['from webhelpers.html import escape'],
#         default_filters=['escape'],
#         filesystem_checks=asbool(config.get('mako.filesystem_checks', True)),
#         preprocessor=spline.lib.makoext.i18n_preprocessor,
#         **module_directory)
# 
#     # Set up SQLAlchemy database engine
#     engine = engine_from_config(config, 'sqlalchemy.')
#     init_model(engine)
# 
#     # Set up our timer events
#     # We attach them globally to the Engine class so we can automatically track
#     # any other database connections used by the app. *coughpokedexcough*
#     config['spline.sql_debugging'] = asbool(
#         config.get('spline.sql_debugging', False))
#     spline.lib.base.attach_timer(Engine)
#     if config['spline.sql_debugging']:
#         spline.lib.base.attach_query_log(Engine)
# 
#     # Backwards compatibility
#     config['spline._sqlalchemy_proxy'] = None
# 
#     # CONFIGURATION OPTIONS HERE (note: all config options will override
#     # any Pylons config options)
# 
#     # Use strict templating; none of this default-to-empty-string nonsense
#     config['pylons.strict_c'] = True
# 
#     # Remove any stale cron lock
#     del config['pylons.app_globals'].cache.get_cache('spline:cron')['LOCK']
# 
#     return config
# 
# Path: spline/lib/plugin/load.py
# def run_hooks(_spline_hook_name, *args, **kwargs):
#     """Runs the hooks registered for the given name, in priority order, passing
#     along all other arguments.
# 
#     If the hook is called outside the normal request cycle, such as with the
#     `routes_mapping` hook, then the `config` object must be explicitly passed
#     in.
# 
#     Current hooks:
# 
#     after_setup(config)
#         immediately following the Pylons environment setup
# 
#     routes_mapping(config, map)
#         near the end of Routes mapping, just before default routes are defined
# 
#     before_controller(action)
#         immediately before any controller is run
# 
#     after_controller()
#         immediately after any controller is run
#     """
# 
#     config = kwargs.get('config', pylons.config)
#     all_hooks = config['spline.plugins.hooks']
# 
#     if not _spline_hook_name in all_hooks:
#         # No hooks; bail
#         return []
#     hooks = all_hooks[_spline_hook_name]
# 
#     results = []
#     for priority in [1, 2, 3, 4, 5]:
#         if not priority in hooks:
#             # Nothing for this priority; bail
#             continue
# 
#         for function in hooks[priority]:
#             result = function(*args, **kwargs)
#             if result != None:
#                 results.append(result)
# 
#     return results


# Path: spline/config/middleware.py
from beaker.middleware import CacheMiddleware, SessionMiddleware
from paste import request as paste_request
from paste.cascade import Cascade
from paste.registry import RegistryManager
from paste.urlparser import StaticURLParser
from paste.deploy.converters import asbool
from pylons.middleware import ErrorHandler, StatusCodeRedirect
from pylons.wsgiapp import PylonsApp
from routes.middleware import RoutesMiddleware
from spline.config.environment import load_environment
from spline.lib.plugin.load import run_hooks

"""Pylons middleware initialization"""


class SplineApp(PylonsApp):
    def find_controller(self, controller):
        """Controller search method that scans the plugin controller list,
        falling back to the default Pylons way if it's not found."""


        try: