예제 #1
0
    def test_req_resp_handler_vargs_kwargs_convention(self):
        fcn, params = router.to_handler(
            "/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1",
            CONVENTION_PARAMS)
        self.assertEqual(
            first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1"], params)

        fcn, params = router.to_handler(
            "/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
            CONVENTION_PARAMS)
        self.assertEqual(
            first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"],
                             params)

        fcn, params = router.to_handler(
            "/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
            CONVENTION_PARAMS,
            param1="blah",
            param2="foo")
        self.assertEqual(
            first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"],
                             params)
예제 #2
0
    def test_complete_path_with_params(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_params/1/%C3%A7ao%40%26%20")
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1", "çao@& "], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_params/1", param2=2)
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1"], params)
예제 #3
0
    def test_complete_path_with_params(self):
        fcn, params = router.to_handler(
            "/pack/pack_handler/with_params/1/%C3%A7ao%40%26%20")
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1", "çao@& "], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_params/1",
                                        param2=2)
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1"], params)
예제 #4
0
    def test_complete_path_with_vargs(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_vargs/1")
        self.assertEqual(pack_handler.with_vargs, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_vargs/1/2")
        self.assertEqual(pack_handler.with_vargs, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_vargs/1/2/3")
        self.assertEqual(pack_handler.with_vargs, fcn)
        self.assertListEqual(["1", "2", "3"], params)
예제 #5
0
    def test_complete_path_with_vargs(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_vargs/1")
        self.assertEqual(pack_handler.with_vargs, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_vargs/1/2")
        self.assertEqual(pack_handler.with_vargs, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_vargs/1/2/3")
        self.assertEqual(pack_handler.with_vargs, fcn)
        self.assertListEqual(["1", "2", "3"], params)
예제 #6
0
    def test_req_resp_handler_vargs_kwargs_convention(self):
        fcn, params = router.to_handler("/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1", CONVENTION_PARAMS)
        self.assertEqual(first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1"], params)

        fcn, params = router.to_handler("/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
                                        CONVENTION_PARAMS)
        self.assertEqual(first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"], params)

        fcn, params = router.to_handler("/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
                                        CONVENTION_PARAMS, param1="blah", param2="foo")
        self.assertEqual(first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"], params)
예제 #7
0
    def make_convetion(self):
        kwargs = dict(_extract_values(self, a) for a in self.request.arguments())
        fcn, params = None, None

        def write_template(template_name, values={}):
            user = Usuario.current_user()
            if user:
                values["current_user"]=user
                values["logout_url"]=users.create_logout_url("/")
            else:
                cadastro_url=router.to_path(usuario.form)
                values["login_url"]=users.create_login_url(cadastro_url)

            document = tmpl.render(template_name, values)
            return self.response.write(document)

        convention_params = {"req": self.request, "resp": self.response,
                             "handler": self, "write_tmpl": write_template,
                             "tmpl": tmpl}
        convention_params["_dependencias"]=convention_params
        try:
            fcn, params = router.to_handler(self.request.path, convention_params, **kwargs)
            fcn(*params, **kwargs)
        except PathNotFound:
            logging.error("Path not Found: " + self.request.path)
            self.response.write("Ocorreu um erro, veja o console")
            raise Exception()
        except:
            logging.error((fcn, params, kwargs))
            logging.error(traceback.format_exc())
            self.response.write("Ocorreu um erro, veja o console")
예제 #8
0
    def make_convetion(self):
        angular_ajax_accept = r'application/json, text/plain, */*'
        header_value = getattr(self.request, 'accept', None)
        header_value = getattr(header_value, 'header_value', None)
        if header_value == angular_ajax_accept and self.request.body:
            kwargs = json.loads(self.request.body)
        else:
            kwargs = dict(_extract_values(self, a) for a in self.request.arguments())

        def write_tmpl(template_name, values=None):
            values = values or {}
            return self.response.write(tmpl.render(template_name, values))

        convention_params = {"_req": self.request,
                             "_resp": self.response,
                             "_handler": self,
                             "_render": tmpl.render,
                             "_write_tmpl": write_tmpl}
        convention_params["_dependencies"] = convention_params
        try:
            fcn, params = router.to_handler(self.request.path, convention_params, **kwargs)
            fcn(*params, **kwargs)
        except PathNotFound:
            self.response.status_code = 404
            logging.error("Path not Found: " + self.request.path)
예제 #9
0
    def test_complete_path_with_defaults(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_defaults")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1/2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults", param1="1", param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1", param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)
예제 #10
0
    def test_complete_path_with_defaults(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_defaults")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1/2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults",
                                        param1="1",
                                        param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1",
                                        param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)
예제 #11
0
    def make_convetion(self):
        kwargs = dict(_extract_values(self, a) for a in self.request.arguments())
        fcn, params = None, None

        def write_template(template_name, values={}):
            document = tmpl.render(template_name, values)
            return self.response.write(document)

        convention_params = {"req": self.request, "resp": self.response, "handler": self, "write_tmpl": write_template}

        try:
            fcn, params = router.to_handler(self.request.path, convention_params, **kwargs)
            fcn(*params, **kwargs)
        except PathNotFound:
            logging.error("Path not Found: " + self.request.path)
            self.response.write("Ocorreu um erro, veja o console")
            raise Exception()
        except:
            logging.error((fcn, params, kwargs))
            logging.error(traceback.format_exc())
            self.response.write("Ocorreu um erro, veja o console")
예제 #12
0
    def make_convetion(self):
        kwargs = dict(_extract_values(self, a) for a in self.request.arguments())

        def write_tmpl(template_name, values={}):
            return self.response.write(tmpl.render(template_name, values))

        convention_params = {
            "_req": self.request,
            "_resp": self.response,
            "_handler": self,
            "_render": tmpl.render,
            "_write_tmpl": write_tmpl,
        }
        convention_params["_dependecies"] = convention_params
        try:
            fcn, params = router.to_handler(self.request.path, convention_params, **kwargs)
            fcn(*params, **kwargs)
        except PathNotFound:
            logging.error("Path not Found: " + self.request.path)
        except:
            logging.error((fcn, params, kwargs))
            logging.error(traceback.format_exc())
예제 #13
0
    def make_convetion(self):
        kwargs = dict(_extract_values(self, a) for a in self.request.arguments())

        def write_tmpl(template_name, values={}):
            self.response.write(tmpl.render(template_name, values))

        convention_params = {'_req': self.request,
                             '_resp': self.response,
                             '_handler': self,
                             '_write_tmpl': write_tmpl
        }
        convention_params['_dependencies'] = convention_params
        try:
            fcn, params = router.to_handler(self.request.path, convention_params, **kwargs)
            fcn(*params, **kwargs)

        except PathNotFound:
            self.response.status_code = 404
            logging.error('Path not Found: ' + self.request.path)
        except Exception, e:
            self.response.status_code = 400
            logging.exception(e)
예제 #14
0
    def make_convetion(self):
        kwargs = dict(_extract_values(self, a) for a in self.request.arguments())
        locale = self.request.headers.get("Accept-Language", "en_US").split(",")[0]
        locale = locale.replace("-", "_")
        i18n.get_i18n().set_locale(locale)

        def write_tmpl(template_name, values={}):
            return self.response.write(tmpl.render(template_name, values))

        convention_params = {"_req": self.request,
                             "_resp": self.response,
                             "_handler": self,
                             "_render": tmpl.render,
                             "_write_tmpl": write_tmpl}
        convention_params["_dependencies"] = convention_params
        try:
            fcn, params = router.to_handler(self.request.path, convention_params, **kwargs)
            fcn(*params, **kwargs)
        except PathNotFound:
            logging.error("Path not Found: " + self.request.path)
        except:
            logging.error((fcn, params, kwargs))
            logging.error(traceback.format_exc())
예제 #15
0
    def make_convetion(self):
        kwargs = dict(
            _extract_values(self, a) for a in self.request.arguments())

        def write_tmpl(template_name, values={}):
            return self.response.write(tmpl.render(template_name, values))

        convention_params = {
            "_req": self.request,
            "_resp": self.response,
            "_handler": self,
            "_render": tmpl.render,
            "_write_tmpl": write_tmpl
        }
        convention_params["_dependecies"] = convention_params
        try:
            fcn, params = router.to_handler(self.request.path,
                                            convention_params, **kwargs)
            fcn(*params, **kwargs)
        except PathNotFound:
            logging.error("Path not Found: " + self.request.path)
        except:
            logging.error((fcn, params, kwargs))
            logging.error(traceback.format_exc())
예제 #16
0
 def test_resp_handler_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_resp_handler/1", CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_resp_handler, fcn)
     self.assertListEqual([RESPONSE, HANDLER, "1"], params)
예제 #17
0
 def test_complete_path(self):
     fcn, params = router.to_handler("/pack/pack_handler/complete_path")
     self.assertEqual(pack_handler.complete_path, fcn)
예제 #18
0
    def test_root(self):
        fcn, params = router.to_handler("/", CONVENTION_PARAMS)
        self.assertEqual(home.index, fcn)

        fcn, params = router.to_handler("/pack", CONVENTION_PARAMS)
        self.assertEqual(pack_home.index, fcn)
예제 #19
0
    def test_root(self):
        fcn, params = router.to_handler("/", CONVENTION_PARAMS)
        self.assertEqual(home.index, fcn)

        fcn, params = router.to_handler("/pack", CONVENTION_PARAMS)
        self.assertEqual(pack_home.index, fcn)
예제 #20
0
 def test_resp_handler_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_resp_handler/1",
                                     CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_resp_handler, fcn)
     self.assertListEqual([RESPONSE, HANDLER, "1"], params)
예제 #21
0
 def test_req_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_request/1",
                                     CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_request, fcn)
     self.assertListEqual([REQUEST, "1"], params)
예제 #22
0
 def test_complete_path(self):
     fcn, params = router.to_handler("/pack/pack_handler/complete_path")
     self.assertEqual(pack_handler.complete_path, fcn)
예제 #23
0
 def test_req_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_request/1", CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_request, fcn)
     self.assertListEqual([REQUEST, "1"], params)
예제 #24
0
def execute(next_process, handler, dependencies, **kwargs):
    fcn, params = router.to_handler(handler.request.path, dependencies, **kwargs)
    fcn(*params, **kwargs)
    next_process(dependencies, **kwargs)