def test_view_name(self): @http_handler(r"", view_name="blah") class A(ExhibitionistRequestHandler): pass self.assertEqual(http_handler.get_view_name(A), "blah") pass
def subscribe(self, h): if self.isAlive(): raise RuntimeError( "Registering http handlers after server start is not allowed") # exst_names=[x for x in self.http_handlers # if get_view_name(x) == get_view_name(h)] # if exst_names and exst_names[0] != h: if h in self.http_handlers: raise RuntimeError("view_name collision, " "there's already a handler called %s" % http_handler.get_view_name(h)) if h not in self.http_handlers: tmpl = "Discovered {type} handler '{name}' tagged with {route}" logger.debug(tmpl.format(type='http', name=http_handler.get_view_name(h), route=http_handler.get_route(h))) self.http_handlers.add(h)
def _register_handlers(self): """ register http_handlers with tornado application""" from tornado.web import URLSpec,Application urlconf = [URLSpec(http_handler.get_route(h), h, name=http_handler.get_view_name(h), kwargs=http_handler.get_kwds(h)) for h in self.http_handlers] self.application = Application(urlconf, **self.tornado_app_settings)