def testcase_handler(application, environ, start_response, exception_handling=True): """The WSGI Application Server. Arguments: environ {dict} -- The WSGI environ dictionary start_response {WSGI callable} Returns: WSGI Response """ from wsgi import application application.bind("environ", environ) """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 """ # """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 application.get_providers(): application.resolve(provider.boot) except Exception as e: if not exception_handling: raise e application.make("exception_handler").handle(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. """ request, response = application.make("request"), application.make( "response") start_response( response.get_status_code(), response.get_headers() + response.cookie_jar.render_response(), ) """Final Step This will take the data variable from the Service Container and return it to the WSGI server. """ return (request, response)
def notify(self, notification, drivers=[], dry=False, fail_silently=False): """Send the given notification.""" from wsgi import application return application.make("notification").send(self, notification, drivers, dry, fail_silently)
def view_helper(errors={}): if errors: return MessageBag(errors) from wsgi import application return MessageBag(application.make("request").session.get("errors") or {})
def get_named_routes(self): """Get a list of the application's named routes, keyed by their names.""" from wsgi import application app_routes = application.make("router").routes routes = {} for route in app_routes: name = route.get_name() if name: data = { "uri": convert_uri(route.url), "methods": list(map(lambda m: m.upper(), route.request_method)), "bindings": {}, # not implemented for now } if route._domain: data["domain"] = route._domain # if route.list_middleware: # data["middleware"] = route.list_middleware routes.update({name: data}) return routes
def __init__(self, key=None): """Sign constructor. Keyword Arguments: key {string} -- The secret key to use. If nothing is passed it then it will use the secret key from the config file. (default: {None}) Raises: InvalidSecretKey -- Thrown if the secret key does not exist. """ if key: self.key = key else: from wsgi import application self.key = application.make("key") if not self.key: raise InvalidSecretKey( "The encryption key passed in is: None. Be sure there is a secret key present in your .env file or your config/application.py file." ) self.encryption = None
def __getattr__(self, attribute, *args, **kwargs): from wsgi import application return getattr(application.make(self.key), attribute)
def _build_path(location_key, relative_path, absolute): from wsgi import application relative_dir = join(as_filepath(application.make(location_key)), relative_path) return abspath(relative_dir) if absolute else relative_dir