# Path: gunstar/http.py
# PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
# GUNSTAR_TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')
# class RequestHandler(object):
# class NotFoundHandler(RequestHandler):
# class ErrorHandler(RequestHandler):
#     def __init__(self, app, request, response):
#     def before_dispatch(self):
#     def dispatch(self, *args, **kwargs):
#     def after_dispatch(self):
#     def abort(self, code, message=None):
#     def redirect(self, redirect_url, permanent=False, status_code=302):
#     def get_template_globals(self):
#     def get_template_filters(self):
#     def create_template_env(self):
#     def render_template(self, template_name, **kwargs):
#     def reverse_route(self, name, *args):
#     def get(self):
#     def get(self, exc_info):
# 
# Path: gunstar/routing.py
# class Router(object):
# 
#     routes = ()
# 
#     def __init__(self, routes=None):
#         if isinstance(routes, tuple):
#             for route in routes:
#                 self.add_route(route[0], route[1], route[2])
# 
#     def add_route(self, pattern, func, name):
#         self.routes += (
#             Route(pattern, func, name),
#         )
# 
#     def find_route(self, path):
#         for route in self.routes:
#             match = re.search(route.regex_pattern, path)
#             if match:
#                 return route
#         return None
# 
#     def find_route_by_name(self, name):
#         for route in self.routes:
#             if route.name == name:
#                 return route
#         return None
# 
# Path: gunstar/config.py
# class Config(dict):
# 
#     def load_from_object(self, obj):
#         if isinstance(obj, six.string_types):
#             obj = import_object(obj)
#         for key in dir(obj):
#             if key.isupper():
#                 self[key] = getattr(obj, key)
# 
# class DefaultConfig(object):
# 
#     DEBUG = True
#     TESTING = False
# 
#     SECRET_KEY = ''
#     SESSION_COOKIE_NAME = 'gsessionid'
#     SESSION_COOKIE_DOMAIN = None
#     SESSION_COOKIE_PATH = '/'
#     SESSION_COOKIE_HTTPONLY = True
#     SESSION_COOKIE_SECURE = False
#     PERMANENT_SESSION_LIFETIME = timedelta(days=30)
# 
#     STATIC_ROOT = ''
#     STATIC_PATH = ''
# 
#     HANDLER_FOR_404 = 'gunstar.http.NotFoundHandler'
#     HANDLER_FOR_500 = 'gunstar.http.ErrorHandler'
# 
# Path: gunstar/utils.py
# def import_object(name):
#     """ from tornado.utils.import_object """
#     if name.count('.') == 0:
#         return __import__(name, None, None)
# 
#     parts = name.split('.')
#     obj = __import__('.'.join(parts[:-1]), None, None, [parts[-1]], 0)
#     try:
#         return getattr(obj, parts[-1])
#     except AttributeError:
#         raise ImportError("No module named %s" % parts[-1])
# 
# Path: gunstar/signals.py



import sys
from gunstar.http import Request, Response, DirectoryApp
from gunstar.routing import Router
from gunstar.config import Config, DefaultConfig
from gunstar.utils import import_object
from gunstar.signals import (
    request_started_signal, request_finished_signal, request_exception_signal
)
# -*- coding: utf-8 -*-



class Application(object):

    def __init__(self, routes=None, config=None):
        # set router
        self.router = Router(routes)

        # set config
        self.config = Config()
        self.config.load_from_object(DefaultConfig)
        self.config.load_from_object(config)

        # add static dir route
        self.set_static_route()

        # handlers for 404 and 500
        self.handler404 = import_object(
            self.config.get('HANDLER_FOR_404')
        )

# Path: gunstar/http.py
# PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
# GUNSTAR_TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')
# class RequestHandler(object):
# class NotFoundHandler(RequestHandler):
# class ErrorHandler(RequestHandler):
#     def __init__(self, app, request, response):
#     def before_dispatch(self):
#     def dispatch(self, *args, **kwargs):
#     def after_dispatch(self):
#     def abort(self, code, message=None):
#     def redirect(self, redirect_url, permanent=False, status_code=302):
#     def get_template_globals(self):
#     def get_template_filters(self):
#     def create_template_env(self):
#     def render_template(self, template_name, **kwargs):
#     def reverse_route(self, name, *args):
#     def get(self):
#     def get(self, exc_info):
# 
# Path: gunstar/routing.py
# class Router(object):
# 
#     routes = ()
# 
#     def __init__(self, routes=None):
#         if isinstance(routes, tuple):
#             for route in routes:
#                 self.add_route(route[0], route[1], route[2])
# 
#     def add_route(self, pattern, func, name):
#         self.routes += (
#             Route(pattern, func, name),
#         )
# 
#     def find_route(self, path):
#         for route in self.routes:
#             match = re.search(route.regex_pattern, path)
#             if match:
#                 return route
#         return None
# 
#     def find_route_by_name(self, name):
#         for route in self.routes:
#             if route.name == name:
#                 return route
#         return None
# 
# Path: gunstar/config.py
# class Config(dict):
# 
#     def load_from_object(self, obj):
#         if isinstance(obj, six.string_types):
#             obj = import_object(obj)
#         for key in dir(obj):
#             if key.isupper():
#                 self[key] = getattr(obj, key)
# 
# class DefaultConfig(object):
# 
#     DEBUG = True
#     TESTING = False
# 
#     SECRET_KEY = ''
#     SESSION_COOKIE_NAME = 'gsessionid'
#     SESSION_COOKIE_DOMAIN = None
#     SESSION_COOKIE_PATH = '/'
#     SESSION_COOKIE_HTTPONLY = True
#     SESSION_COOKIE_SECURE = False
#     PERMANENT_SESSION_LIFETIME = timedelta(days=30)
# 
#     STATIC_ROOT = ''
#     STATIC_PATH = ''
# 
#     HANDLER_FOR_404 = 'gunstar.http.NotFoundHandler'
#     HANDLER_FOR_500 = 'gunstar.http.ErrorHandler'
# 
# Path: gunstar/utils.py
# def import_object(name):
#     """ from tornado.utils.import_object """
#     if name.count('.') == 0:
#         return __import__(name, None, None)
# 
#     parts = name.split('.')
#     obj = __import__('.'.join(parts[:-1]), None, None, [parts[-1]], 0)
#     try:
#         return getattr(obj, parts[-1])
#     except AttributeError:
#         raise ImportError("No module named %s" % parts[-1])
# 
# Path: gunstar/signals.py



# Path: gunstar/app.py
import sys
from gunstar.http import Request, Response, DirectoryApp
from gunstar.routing import Router
from gunstar.config import Config, DefaultConfig
from gunstar.utils import import_object
from gunstar.signals import (
    request_started_signal, request_finished_signal, request_exception_signal
)

# -*- coding: utf-8 -*-



class Application(object):

    def __init__(self, routes=None, config=None):
        # set router
        self.router = Router(routes)

        # set config
        self.config = Config()
        self.config.load_from_object(DefaultConfig)
        self.config.load_from_object(config)

        # add static dir route
        self.set_static_route()

        # handlers for 404 and 500
        self.handler404 = import_object(
            self.config.get('HANDLER_FOR_404')
        )

        self.handler500 = import_object(