# Path: snakeguice/injector.py
# def create_injector(modules):
#     """Factory for creating Injector instances."""
#     return Injector(modules)
# 
# Path: snakeguice/extras/snakeweb.py
# class Application(object):
# 
#     def __init__(self, injector):
#         self._injector = injector
# 
#     def __call__(self, environ, start_response):
#         request = Request(environ)
# 
#         binder = self._injector.get_instance(RoutesBinder)
# 
#         route = binder.match(environ['PATH_INFO'], environ)
#         if not route:
#             return HTTPNotFound('no matching route')(environ, start_response)
# 
#         controller = route.pop('controller')
#         controller = binder.controller_map.get(controller)
# 
#         if inspect.isclass(controller):
#             action = route.pop('action', 'index')
#             controller = self.controller_from_class(controller, action)
# 
#         elif is_unbound_method(controller):
#             controller = self.controller_from_method(controller)
# 
#         elif not callable(controller):
#             return HTTPNotFound()(environ, start_response)
# 
#         if not controller:
#             return HTTPNotFound()(environ, start_response)
# 
#         response = controller(request, **route)
#         return response(environ, start_response)
# 
#     def controller_from_class(self, controller, action):
#         controller = self._injector.get_instance(controller)
#         return getattr(controller, action, None)
# 
#     def controller_from_method(self, controller):
#         return self.controller_from_class(controller.im_class,
#                 controller.__name__)


import sys
from wsgiref.simple_server import make_server
from snakeguice import create_injector
from snakeguice.extras.snakeweb import Application
from scopes import WSGIRequestScopeMiddleware
from modules import MainModule, URLMapperModule



def main(args):
    injector = create_injector([MainModule(), URLMapperModule()])
    application = Application(injector)

    httpd = make_server('', 8000, application)
    httpd.serve_forever()



# Path: snakeguice/injector.py
# def create_injector(modules):
#     """Factory for creating Injector instances."""
#     return Injector(modules)
# 
# Path: snakeguice/extras/snakeweb.py
# class Application(object):
# 
#     def __init__(self, injector):
#         self._injector = injector
# 
#     def __call__(self, environ, start_response):
#         request = Request(environ)
# 
#         binder = self._injector.get_instance(RoutesBinder)
# 
#         route = binder.match(environ['PATH_INFO'], environ)
#         if not route:
#             return HTTPNotFound('no matching route')(environ, start_response)
# 
#         controller = route.pop('controller')
#         controller = binder.controller_map.get(controller)
# 
#         if inspect.isclass(controller):
#             action = route.pop('action', 'index')
#             controller = self.controller_from_class(controller, action)
# 
#         elif is_unbound_method(controller):
#             controller = self.controller_from_method(controller)
# 
#         elif not callable(controller):
#             return HTTPNotFound()(environ, start_response)
# 
#         if not controller:
#             return HTTPNotFound()(environ, start_response)
# 
#         response = controller(request, **route)
#         return response(environ, start_response)
# 
#     def controller_from_class(self, controller, action):
#         controller = self._injector.get_instance(controller)
#         return getattr(controller, action, None)
# 
#     def controller_from_method(self, controller):
#         return self.controller_from_class(controller.im_class,
#                 controller.__name__)


# Path: examples/wsgiapp/app.py
import sys
from wsgiref.simple_server import make_server
from snakeguice import create_injector
from snakeguice.extras.snakeweb import Application
from scopes import WSGIRequestScopeMiddleware
from modules import MainModule, URLMapperModule




def main(args):
    injector = create_injector([MainModule(), URLMapperModule()])
    application = Application(injector)

    httpd = make_server('', 8000, application)
    httpd.serve_forever()



if __name__ == '__main__':