Python tornado.web 模块,URLSpec() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用tornado.web.URLSpec()

项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def run(self):
        import tornado.autoreload
        tornado.autoreload.watch('index.wsgi')

        import re
        from tornado.web import URLSpec, StaticFileHandler
        # The user should not use `tornado.web.Application.add_handlers`
        # since here in SAE one application only has a single host, so here
        # we can just use the first host_handers.
        handlers = self.application.handlers[0][1]
        for prefix, path in self.static_files.iteritems():
            pattern = re.escape(prefix) + r"(.*)"
            handlers.insert(0, URLSpec(pattern, StaticFileHandler, {"path": path}))

        os.environ['sae.run_main'] = '1'

        import tornado.ioloop
        from tornado.httpserver import HTTPServer
        server = HTTPServer(self.application, xheaders=True)
        server.listen(self.conf.port, self.conf.host)
        tornado.ioloop.IOLoop.instance().start()
项目:globibot    作者:best-coloc-ever    | 项目源码 | 文件源码
def add_routes(self, context, *handlers):
        self.url_specs[context] += [
            web.URLSpec(*handler).regex
            for handler in handlers
        ]

        self.add_handlers(r'.*$', handlers)
项目:wdom    作者:miyakogi    | 项目源码 | 文件源码
def add_favicon_path(self, path: str) -> None:
        """Add path to serve favicon file.

        ``path`` should be a directory, which contains favicon file
        (``favicon.ico``) for your app.
        """
        spec = web.URLSpec(
            '/(favicon.ico)',
            StaticFileHandler,
            dict(path=path)
        )
        # Need some check
        handlers = self.handlers[0][1]
        handlers.append(spec)
项目:lampost_lib    作者:genzgd    | 项目源码 | 文件源码
def add_raw_route(url_regex, handler, **kwargs):
    _handlers.append(URLSpec(url_regex, handler, kwargs))
项目:rabbitChat    作者:anirbanroydas    | 项目源码 | 文件源码
def include(prefix, module_path):
    module = __import__(module_path, globals(), locals(), fromlist=["*"])
    urls = getattr(module, 'urls')
    print urls
    final_urls = list()
    for url in urls:
        pattern = url.regex.pattern
        if pattern.startswith("/"):
            pattern = r"%s%s" % (prefix, pattern[1:])
        else:
            pattern = r"%s%s" % (prefix, pattern)
        final_urls.append(URLSpec(pattern, url.handler_class, kwargs=url.kwargs, name=url.name))
    return final_urls
项目:rabbitChat    作者:anirbanroydas    | 项目源码 | 文件源码
def include(prefix, module_path):
    module = __import__(module_path, globals(), locals(), fromlist=["*"])
    urls = getattr(module, 'urls')
    print urls
    final_urls = list()
    for url in urls:
        pattern = url.regex.pattern
        if pattern.startswith("/"):
            pattern = r"%s%s" % (prefix, pattern[1:])
        else:
            pattern = r"%s%s" % (prefix, pattern)
        final_urls.append(URLSpec(pattern, url.handler_class, kwargs=url.kwargs, name=url.name))
    return final_urls
项目:tensorflow-pspnet    作者:pudae    | 项目源码 | 文件源码
def __init__(self, config):

    self._graph = tf.Graph()

    tf_config = None
    if not config.get("gpu", None):
        tf_config = tf.ConfigProto(device_count={"GPU":0})
    else:
        tf_config = tf.ConfigProto(device_count={"GPU":1})
        tf_config.gpu_options.allow_growth = True
        tf_config.gpu_options.per_process_gpu_memory_fraction=config["gpu_memory_fraction"]

    self._sess = tf.Session(config=tf_config, graph=self._graph)

    with self._sess.graph.as_default():
        graph_def = tf.GraphDef()
        with open(config['model'], 'rb') as file:
            graph_def.ParseFromString(file.read())
        tf.import_graph_def(graph_def, name="")

    self._input_x = self._sess.graph.get_operation_by_name('ph_input_x').outputs[0]
    self._pred = self._sess.graph.get_operation_by_name('predictions').outputs[0]
    self._softmax = self._sess.graph.get_operation_by_name('softmax').outputs[0]

    self._http_app = web.Application(
        handlers=[
            web.URLSpec(r"/api/echo/(.*)", EchoHandler, dict(app=self)),
            web.URLSpec(r"/api/image", EchoHandler, dict(app=self)),
            web.URLSpec(r"/ui/segmentation", TestUIHandler, dict(app=self))
        ],
        debug=config["debug"],
    )
项目:mosquittoChat    作者:anirbanroydas    | 项目源码 | 文件源码
def include(prefix, module_path):
    module = __import__(module_path, globals(), locals(), fromlist=["*"])
    urls = getattr(module, 'urls')
    print urls
    final_urls = list()
    for url in urls:
        pattern = url.regex.pattern
        if pattern.startswith("/"):
            pattern = r"%s%s" % (prefix, pattern[1:])
        else:
            pattern = r"%s%s" % (prefix, pattern)
        final_urls.append(URLSpec(pattern, url.handler_class, kwargs=url.kwargs, name=url.name))
    return final_urls
项目:mosquittoChat    作者:anirbanroydas    | 项目源码 | 文件源码
def include(prefix, module_path):
    module = __import__(module_path, globals(), locals(), fromlist=["*"])
    urls = getattr(module, 'urls')
    print urls
    final_urls = list()
    for url in urls:
        pattern = url.regex.pattern
        if pattern.startswith("/"):
            pattern = r"%s%s" % (prefix, pattern[1:])
        else:
            pattern = r"%s%s" % (prefix, pattern)
        final_urls.append(URLSpec(pattern, url.handler_class, kwargs=url.kwargs, name=url.name))
    return final_urls