def app(environ, start_response): ''' The WSGI Application Server ''' from wsgi import container ''' |-------------------------------------------------------------------------- | Add Environ To Service Container |-------------------------------------------------------------------------- | | Add the environ to the service container. The environ is generated by the | the WSGI server above and used by a service provider to manipulate the | incoming requests | ''' container.bind('Environ', environ) ''' |-------------------------------------------------------------------------- | Execute All Service Providers That Require The WSGI Server |-------------------------------------------------------------------------- | | Run all service provider boot methods if the wsgi attribute is true. | ''' try: for provider in container.make('Application').PROVIDERS: located_provider = locate(provider)().load_app(container) if located_provider.wsgi is True: container.resolve(located_provider.boot) except Exception as e: container.make('ExceptionHandler').load_exception(e) ''' |-------------------------------------------------------------------------- | We Are Ready For Launch |-------------------------------------------------------------------------- | | If we have a solid response and not redirecting then we need to return | a 200 status code along with the data. If we don't, then we'll have | to return a 302 redirection to where ever the user would like go | to next. | ''' start_response(container.make('StatusCode'), container.make('Headers')) ''' |-------------------------------------------------------------------------- | Final Step |-------------------------------------------------------------------------- | | This will take the data variable from the Service Container and return | it to the WSGI server. | ''' return iter([bytes(container.make('Response'), 'utf-8')])
def app(environ, start_response): ''' The WSGI Application Server ''' from wsgi import container ''' |-------------------------------------------------------------------------- | Add Environ To Service Container |-------------------------------------------------------------------------- | | Add the environ to the service container. The environ is generated by the | the WSGI server above and used by a service provider to manipulate the | incoming requests | ''' container.bind('Environ', environ) ''' |-------------------------------------------------------------------------- | Execute All Service Providers That Require The WSGI Server |-------------------------------------------------------------------------- | | Run all service provider boot methods if the wsgi attribute is true. | ''' try: for provider in container.make('WSGIProviders'): container.resolve(provider.boot) except Exception as e: container.make('ExceptionHandler').load_exception(e) ''' |-------------------------------------------------------------------------- | We Are Ready For Launch |-------------------------------------------------------------------------- | | If we have a solid response and not redirecting then we need to return | a 200 status code along with the data. If we don't, then we'll have | to return a 302 redirection to where ever the user would like go | to next. | ''' start_response(container.make('StatusCode'), container.make('Headers')) ''' |-------------------------------------------------------------------------- | Final Step |-------------------------------------------------------------------------- | | This will take the data variable from the Service Container and return | it to the WSGI server. | ''' return iter([bytes(container.make('Response'), 'utf-8')])
def app(environ, start_response): from wsgi import container ''' |-------------------------------------------------------------------------- | Startup the Service Container |-------------------------------------------------------------------------- | | Instantiate the Service Container so we can bind classes into it and | bind the environ variable that is created by the WSGI server into | the container. | ''' container.bind('Environ', environ) ''' |-------------------------------------------------------------------------- | Execute All Service Providers |-------------------------------------------------------------------------- | | Run all service provider boot methods if the wsgi attribute is true. | ''' for provider in container.make('Application').PROVIDERS: located_provider = locate(provider)().load_app(container) if located_provider.wsgi is True: container.resolve(located_provider.boot) ''' |-------------------------------------------------------------------------- | We Are Ready For Launch |-------------------------------------------------------------------------- | | If we have a solid response and not redirecting then we need to return | a 200 status code along with the data. If we don't, then we'll have | to return a 302 and redirect to where the developer would like to | go next. | ''' start_response(container.make('StatusCode'), container.make('Headers')) ''' |-------------------------------------------------------------------------- | Final Step |-------------------------------------------------------------------------- | | This will take the data variable from above and return it to the WSGI | server. | ''' return iter([bytes(container.make('Response'), 'utf-8')])
def app(self, environ, start_response): """The WSGI Application Server. Arguments: environ {dict} -- The WSGI environ dictionary start_response {WSGI callable} Returns: WSGI Response """ from wsgi import container # print('imported', mark - first) """Add Environ To Service Container Add the environ to the service container. The environ is generated by the the WSGI server above and used by a service provider to manipulate the incoming requests """ container.bind('Environ', environ) """Execute All Service Providers That Require The WSGI Server Run all service provider boot methods if the wsgi attribute is true. """ try: for provider in container.make('WSGIProviders'): container.resolve(provider.boot) # print('time took for ', provider, time.time() - start) # print() # end = end - start except Exception as e: container.make('ExceptionHandler').load_exception(e) """We Are Ready For Launch If we have a solid response and not redirecting then we need to return a 200 status code along with the data. If we don't, then we'll have to return a 302 redirection to where ever the user would like go to next. """ start_response(container.make('Request').get_status_code(), container.make('Request').get_and_reset_headers()) """Final Step This will take the data variable from the Service Container and return it to the WSGI server. """ return iter([container.make('Response')])
def app(environ, start_response): """The WSGI Application Server Arguments: environ {dict} -- The WSGI environ dictionary start_response {WSGI callable} Returns: WSGI Response """ from wsgi import container """ |-------------------------------------------------------------------------- | Add Environ To Service Container |-------------------------------------------------------------------------- | | Add the environ to the service container. The environ is generated by the | the WSGI server above and used by a service provider to manipulate the | incoming requests | """ container.bind('Environ', environ) """ |-------------------------------------------------------------------------- | Execute All Service Providers That Require The WSGI Server |-------------------------------------------------------------------------- | | Run all service provider boot methods if the wsgi attribute is true. | """ try: for provider in container.make('WSGIProviders'): container.resolve(provider.boot) except Exception as e: container.make('ExceptionHandler').load_exception(e) """ |-------------------------------------------------------------------------- | We Are Ready For Launch |-------------------------------------------------------------------------- | | If we have a solid response and not redirecting then we need to return | a 200 status code along with the data. If we don't, then we'll have | to return a 302 redirection to where ever the user would like go | to next. | """ start_response( container.make('Request').get_status_code(), container.make('Request').get_and_reset_headers()) """ |-------------------------------------------------------------------------- | Final Step |-------------------------------------------------------------------------- | | This will take the data variable from the Service Container and return | it to the WSGI server. | """ return iter([bytes(container.make('Response'), 'utf-8')])
def create_container(self): container = App() from config import application from config import providers container.bind('WSGI', generate_wsgi()) container.bind('Application', application) container.bind('Container', container) container.bind('ProvidersConfig', providers) container.bind('Providers', []) container.bind('WSGIProviders', []) """Bind all service providers Let's register everything into the Service Container. Once everything is in the container we can run through all the boot methods. For reasons some providers don't need to execute with every request and should only run once when the server is started. Providers will be ran once if the wsgi attribute on a provider is False. """ for provider in container.make('ProvidersConfig').PROVIDERS: located_provider = provider() located_provider.load_app(container).register() if located_provider.wsgi: container.make('WSGIProviders').append(located_provider) else: container.make('Providers').append(located_provider) for provider in container.make('Providers'): container.resolve(provider.boot) """Get the application from the container Some providers may change the WSGI Server like wrapping the WSGI server in a Whitenoise container for an example. Let's get a WSGI instance from the container and pass it to the application variable. This will allow WSGI servers to pick it up from the command line """ return container