Beispiel #1
0
	def route(self):
		"""
		route(): It chooses the appropriate controller
		"""
		if self.request.ok:
			return self.resolve()
		else:
			return Response(code = 'Not Found', body = "Invalid route")
Beispiel #2
0
    def action(self, action_name):
        """
		action(): It tries to call a method called 'action_name' from the current Controller object. Then it returns the output of that method.
		If that method is not found, it returns a warning.
		"""
        if hasattr(self, action_name) and callable(getattr(self, action_name)):
            self.response.body = getattr(self, action_name)()
            return self.response
        else:
            return Response(code='Not Found',
                            body="Action '{}' unavailable".format(action_name))
Beispiel #3
0
	def call_controller(self, package):
		"""
		call_controller(): It tries to find the required controller
		"""
		controller_name = None
		if package:
			controller_name = self.translate_controller_name(package, self.request.controller)

		if controller_name:
			return self.instance_controller(package, controller_name)
		else:
			return Response(code = 'Not Found', body = "Controller '{}' from module '{}' not found".format(self.request.controller, self.request.module))
Beispiel #4
0
	def resolve(self):
		"""
		resolve(): It call the specified controller
		""" 
		if self.request.module in modules_aliases().keys():
			self.request.module = modules_aliases()[self.request.module]

		treater = self.call_controller(general.get_package_from_module("controllers.treaters", "modules.{}".format(self.request.module)))
		if treater.code == 'OK' or treater.code == 'Not Found':
			return self.call_controller(general.get_package_from_module("controllers", "modules.{}".format(self.request.module)))
		else:
			return Response(code = treater.code, body = treater.body)
Beispiel #5
0
def bootstrap(environment, meta):
    request = Request(environment)
    try:
        response = Application(request).run()
    except Exception as e:
        debugger.applog('/'.join(request.urn_list) + "\n" +
                        traceback.format_exc())
        response = Response(
            code='Internal Server Error',
            body="I'm sorry Dave, I'm afraid I can't do that ({})".format(
                str(e)))

    server_output = response.prepare()
    meta(response.status, response.headers)
    return [server_output]
Beispiel #6
0
	def __init__(self, request):
		super().__init__(request)
		self.response = Response()