当前位置: 首页>>代码示例>>Python>>正文


Python web.url方法代码示例

本文整理汇总了Python中tornado.web.url方法的典型用法代码示例。如果您正苦于以下问题:Python web.url方法的具体用法?Python web.url怎么用?Python web.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.web的用法示例。


在下文中一共展示了web.url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_app

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def get_app(self):
        # callable objects to finish pending /trigger requests
        self.triggers = collections.deque()
        return Application([
            url("/trigger", TriggerHandler, dict(queue=self.triggers,
                                                 wake_callback=self.stop)),
            url("/chunk", ChunkHandler),
            url("/countdown/([0-9]+)", CountdownHandler, name="countdown"),
            url("/hang", HangHandler),
            url("/hello", HelloWorldHandler),
            url("/content_length", ContentLengthHandler),
            url("/head", HeadHandler),
            url("/options", OptionsHandler),
            url("/no_content", NoContentHandler),
            url("/see_other_post", SeeOtherPostHandler),
            url("/see_other_get", SeeOtherGetHandler),
            url("/host_echo", HostEchoHandler),
            url("/no_content_length", NoContentLengthHandler),
            url("/echo_post", EchoPostHandler),
            url("/respond_in_prepare", RespondInPrepareHandler),
            url("/redirect", RedirectHandler),
        ], gzip=True) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:24,代码来源:simple_httpclient_test.py

示例2: test_ipv6

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_ipv6(self):
        try:
            [sock] = bind_sockets(None, '::1', family=socket.AF_INET6)
            port = sock.getsockname()[1]
            self.http_server.add_socket(sock)
        except socket.gaierror as e:
            if e.args[0] == socket.EAI_ADDRFAMILY:
                # python supports ipv6, but it's not configured on the network
                # interface, so skip this test.
                return
            raise
        url = '%s://[::1]:%d/hello' % (self.get_protocol(), port)

        # ipv6 is currently enabled by default but can be disabled
        self.http_client.fetch(url, self.stop, allow_ipv6=False)
        response = self.wait()
        self.assertEqual(response.code, 599)

        self.http_client.fetch(url, self.stop)
        response = self.wait()
        self.assertEqual(response.body, b"Hello world!") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:23,代码来源:simple_httpclient_test.py

示例3: get_handlers

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def get_handlers(self):
        urls = [
            url("/typecheck/(.*)", TypeCheckHandler, name='typecheck'),
            url("/decode_arg/(.*)", DecodeArgHandler, name='decode_arg'),
            url("/decode_arg_kw/(?P<arg>.*)", DecodeArgHandler),
            url("/linkify", LinkifyHandler),
            url("/uimodule_resources", UIModuleResourceHandler),
            url("/optional_path/(.+)?", OptionalPathHandler),
            url("/multi_header", MultiHeaderHandler),
            url("/redirect", RedirectHandler),
            url("/web_redirect_permanent", WebRedirectHandler, {"url": "/web_redirect_newpath"}),
            url("/web_redirect", WebRedirectHandler, {"url": "/web_redirect_newpath", "permanent": False}),
            url("//web_redirect_double_slash", WebRedirectHandler, {"url": '/web_redirect_newpath'}),
            url("/header_injection", HeaderInjectionHandler),
            url("/get_argument", GetArgumentHandler),
            url("/get_arguments", GetArgumentsHandler),
        ]
        return urls 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:web_test.py

示例4: test_streaming_follow_redirects

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_streaming_follow_redirects(self):
        # When following redirects, header and streaming callbacks
        # should only be called for the final result.
        # TODO(bdarnell): this test belongs in httpclient_test instead of
        # simple_httpclient_test, but it fails with the version of libcurl
        # available on travis-ci. Move it when that has been upgraded
        # or we have a better framework to skip tests based on curl version.
        headers = []
        chunks = []
        self.fetch("/redirect?url=/hello",
                   header_callback=headers.append,
                   streaming_callback=chunks.append)
        chunks = list(map(to_unicode, chunks))
        self.assertEqual(chunks, ['Hello world!'])
        # Make sure we only got one set of headers.
        num_start_lines = len([h for h in headers if h.startswith("HTTP/")])
        self.assertEqual(num_start_lines, 1) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:simple_httpclient_test.py

示例5: get_app

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def get_app(self):
        return Application(
            [
                url("/hello", HelloWorldHandler),
                url("/post", PostHandler),
                url("/put", PutHandler),
                url("/redirect", RedirectHandler),
                url("/redirect_without_location", RedirectWithoutLocationHandler),
                url("/chunk", ChunkHandler),
                url("/auth", AuthHandler),
                url("/countdown/([0-9]+)", CountdownHandler, name="countdown"),
                url("/echopost", EchoPostHandler),
                url("/user_agent", UserAgentHandler),
                url("/304_with_content_length", ContentLength304Handler),
                url("/all_methods", AllMethodsHandler),
                url("/patch", PatchHandler),
                url("/set_header", SetHeaderHandler),
            ],
            gzip=True,
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:22,代码来源:httpclient_test.py

示例6: test_method_after_redirect

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_method_after_redirect(self):
        # Legacy redirect codes (301, 302) convert POST requests to GET.
        for status in [301, 302, 303]:
            url = "/redirect?url=/all_methods&status=%d" % status
            resp = self.fetch(url, method="POST", body=b"")
            self.assertEqual(b"GET", resp.body)

            # Other methods are left alone.
            for method in ["GET", "OPTIONS", "PUT", "DELETE"]:
                resp = self.fetch(url, method=method, allow_nonstandard_methods=True)
                self.assertEqual(utf8(method), resp.body)
            # HEAD is different so check it separately.
            resp = self.fetch(url, method="HEAD")
            self.assertEqual(200, resp.code)
            self.assertEqual(b"", resp.body)

        # Newer redirects always preserve the original method.
        for status in [307, 308]:
            url = "/redirect?url=/all_methods&status=307"
            for method in ["GET", "OPTIONS", "POST", "PUT", "DELETE"]:
                resp = self.fetch(url, method=method, allow_nonstandard_methods=True)
                self.assertEqual(method, to_unicode(resp.body))
            resp = self.fetch(url, method="HEAD")
            self.assertEqual(200, resp.code)
            self.assertEqual(b"", resp.body) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:27,代码来源:httpclient_test.py

示例7: __call__

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def __call__(self, pattern, handler, kwargs=None, name=None):
        kw = {}
        if self.overall_kw:
            kw.update(self.overall_kw)
        if kwargs:
            kw.update(kwargs)

        if self.prefix and isinstance(handler, str):
            handler = "%s.%s" % (self.prefix, handler)

        urlsp = urlspec(pattern,
                        handler,
                        kwargs=kw,
                        name=name)
        urlsp.repr_pattern = pattern
        return urlsp 
开发者ID:mqingyn,项目名称:torngas,代码行数:18,代码来源:urlhelper.py

示例8: get_app

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def get_app(self):
        # callable objects to finish pending /trigger requests
        self.triggers = collections.deque()
        return Application([
            url("/trigger", TriggerHandler, dict(queue=self.triggers,
                                                 wake_callback=self.stop)),
            url("/chunk", ChunkHandler),
            url("/countdown/([0-9]+)", CountdownHandler, name="countdown"),
            url("/hang", HangHandler),
            url("/hello", HelloWorldHandler),
            url("/content_length", ContentLengthHandler),
            url("/head", HeadHandler),
            url("/options", OptionsHandler),
            url("/no_content", NoContentHandler),
            url("/see_other_post", SeeOtherPostHandler),
            url("/see_other_get", SeeOtherGetHandler),
            url("/host_echo", HostEchoHandler),
        ], gzip=True) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:20,代码来源:simple_httpclient_test.py

示例9: test_ipv6

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_ipv6(self):
        try:
            self.http_server.listen(self.get_http_port(), address='::1')
        except socket.gaierror as e:
            if e.args[0] == socket.EAI_ADDRFAMILY:
                # python supports ipv6, but it's not configured on the network
                # interface, so skip this test.
                return
            raise
        url = self.get_url("/hello").replace("localhost", "[::1]")

        # ipv6 is currently disabled by default and must be explicitly requested
        self.http_client.fetch(url, self.stop)
        response = self.wait()
        self.assertEqual(response.code, 599)

        self.http_client.fetch(url, self.stop, allow_ipv6=True)
        response = self.wait()
        self.assertEqual(response.body, b"Hello world!") 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:21,代码来源:simple_httpclient_test.py

示例10: test_decode_argument

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_decode_argument(self):
        # These urls all decode to the same thing
        urls = ["/decode_arg/%C3%A9?foo=%C3%A9&encoding=utf-8",
                "/decode_arg/%E9?foo=%E9&encoding=latin1",
                "/decode_arg_kw/%E9?foo=%E9&encoding=latin1",
                ]
        for url in urls:
            response = self.fetch(url)
            response.rethrow()
            data = json_decode(response.body)
            self.assertEqual(data, {u('path'): [u('unicode'), u('\u00e9')],
                                    u('query'): [u('unicode'), u('\u00e9')],
                                    })

        response = self.fetch("/decode_arg/%C3%A9?foo=%C3%A9")
        response.rethrow()
        data = json_decode(response.body)
        self.assertEqual(data, {u('path'): [u('bytes'), u('c3a9')],
                                u('query'): [u('bytes'), u('c3a9')],
                                }) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:22,代码来源:web_test.py

示例11: test_max_redirects

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_max_redirects(self):
        response = self.fetch("/countdown/5", max_redirects=3)
        self.assertEqual(302, response.code)
        # We requested 5, followed three redirects for 4, 3, 2, then the last
        # unfollowed redirect is to 1.
        self.assertTrue(response.request.url.endswith("/countdown/5"))
        self.assertTrue(response.effective_url.endswith("/countdown/2"))
        self.assertTrue(response.headers["Location"].endswith("/countdown/1")) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:simple_httpclient_test.py

示例12: test_see_other_redirect

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_see_other_redirect(self):
        for code in (302, 303):
            response = self.fetch("/see_other_post", method="POST", body="%d" % code)
            self.assertEqual(200, response.code)
            self.assertTrue(response.request.url.endswith("/see_other_post"))
            self.assertTrue(response.effective_url.endswith("/see_other_get"))
            # request is the original request, is a POST still
            self.assertEqual("POST", response.request.method) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:simple_httpclient_test.py

示例13: test_host_header

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def test_host_header(self):
        host_re = re.compile(b"^localhost:[0-9]+$")
        response = self.fetch("/host_echo")
        self.assertTrue(host_re.match(response.body))

        url = self.get_url("/host_echo").replace("http://", "http://me:secret@")
        self.http_client.fetch(url, self.stop)
        response = self.wait()
        self.assertTrue(host_re.match(response.body), response.body) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:simple_httpclient_test.py

示例14: prepare

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def prepare(self):
        self.write('redirects can have bodies too')
        self.redirect(self.get_argument("url"),
                      status=int(self.get_argument("status", "302"))) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:httpclient_test.py

示例15: get_app

# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import url [as 别名]
def get_app(self):
        return Application([
            url("/hello", HelloWorldHandler),
            url("/post", PostHandler),
            url("/put", PutHandler),
            url("/redirect", RedirectHandler),
            url("/chunk", ChunkHandler),
            url("/auth", AuthHandler),
            url("/countdown/([0-9]+)", CountdownHandler, name="countdown"),
            url("/echopost", EchoPostHandler),
            url("/user_agent", UserAgentHandler),
            url("/304_with_content_length", ContentLength304Handler),
            url("/all_methods", AllMethodsHandler),
            url('/patch', PatchHandler),
        ], gzip=True) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:17,代码来源:httpclient_test.py


注:本文中的tornado.web.url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。