Python tornado.web.url() Examples
The following are 30
code examples of tornado.web.url().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tornado.web
, or try the search function
.
Example #1
Source File: simple_httpclient_test.py From tornado-zh with MIT License | 7 votes |
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!")
Example #2
Source File: simple_httpclient_test.py From tornado-zh with MIT License | 6 votes |
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)
Example #3
Source File: simple_httpclient_test.py From tornado-zh with MIT License | 6 votes |
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)
Example #4
Source File: simple_httpclient_test.py From viewfinder with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: simple_httpclient_test.py From viewfinder with Apache License 2.0 | 6 votes |
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!")
Example #6
Source File: simple_httpclient_test.py From tornado-zh with MIT License | 6 votes |
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)
Example #7
Source File: simple_httpclient_test.py From viewfinder with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: web_test.py From tornado-zh with MIT License | 6 votes |
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
Example #9
Source File: urlhelper.py From torngas with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #10
Source File: web_test.py From viewfinder with Apache License 2.0 | 6 votes |
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')], })
Example #11
Source File: httpclient_test.py From opendevops with GNU General Public License v3.0 | 6 votes |
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)
Example #12
Source File: simple_httpclient_test.py From teleport with Apache License 2.0 | 6 votes |
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)
Example #13
Source File: httpclient_test.py From opendevops with GNU General Public License v3.0 | 6 votes |
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, )
Example #14
Source File: web_test.py From viewfinder with Apache License 2.0 | 5 votes |
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("/header_injection", HeaderInjectionHandler), url("/get_argument", GetArgumentHandler), ] return urls
Example #15
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
def test_reuse_request_from_response(self): # The response.request attribute should be an HTTPRequest, not # a _RequestProxy. # This test uses self.http_client.fetch because self.fetch calls # self.get_url on the input unconditionally. url = self.get_url('/hello') response = yield self.http_client.fetch(url) self.assertEqual(response.request.url, url) self.assertTrue(isinstance(response.request, HTTPRequest)) response2 = yield self.http_client.fetch(response.request) self.assertEqual(response2.body, b'Hello world!')
Example #16
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
def test_credentials_in_url(self): url = self.get_url("/auth").replace("http://", "http://me:secret@") self.http_client.fetch(url, self.stop) response = self.wait() self.assertEqual(b"Basic " + base64.b64encode(b"me:secret"), response.body)
Example #17
Source File: web_test.py From viewfinder with Apache License 2.0 | 5 votes |
def test_decode_argument_plus(self): # These urls are all equivalent. urls = ["/decode_arg/1%20%2B%201?foo=1%20%2B%201&encoding=utf-8", "/decode_arg/1%20+%201?foo=1+%2B+1&encoding=utf-8"] for url in urls: response = self.fetch(url) response.rethrow() data = json_decode(response.body) self.assertEqual(data, {u('path'): [u('unicode'), u('1 + 1')], u('query'): [u('unicode'), u('1 + 1')], })
Example #18
Source File: app.py From gprime with GNU General Public License v2.0 | 5 votes |
def server_info(self): """ Return the server url information """ return "The gPrime server is running at: %s:" % (self.options.host, self.options.port)
Example #19
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
def test_credentials_in_url(self): url = self.get_url("/auth").replace("http://", "http://me:secret@") self.http_client.fetch(url, self.stop) response = self.wait() self.assertEqual(b"Basic " + base64.b64encode(b"me:secret"), response.body)
Example #20
Source File: web_test.py From viewfinder with Apache License 2.0 | 5 votes |
def test_decode_argument_plus(self): # These urls are all equivalent. urls = ["/decode_arg/1%20%2B%201?foo=1%20%2B%201&encoding=utf-8", "/decode_arg/1%20+%201?foo=1+%2B+1&encoding=utf-8"] for url in urls: response = self.fetch(url) response.rethrow() data = json_decode(response.body) self.assertEqual(data, {u('path'): [u('unicode'), u('1 + 1')], u('query'): [u('unicode'), u('1 + 1')], })
Example #21
Source File: httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
def get_app(self): return Application([ url("/hello", HelloWorldHandler), url("/post", PostHandler), 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), ], gzip=True)
Example #22
Source File: simple_httpclient_test.py From teleport with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: simple_httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
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)
Example #24
Source File: simple_httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: simple_httpclient_test.py From viewfinder with Apache License 2.0 | 5 votes |
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"))
Example #26
Source File: httpclient_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
def test_bind_source_ip(self): url = self.get_url("/hello") request = HTTPRequest(url, network_interface="127.0.0.1") response = yield self.http_client.fetch(request) self.assertEqual(response.code, 200) with self.assertRaises((ValueError, HTTPError)) as context: request = HTTPRequest(url, network_interface="not-interface-or-ip") yield self.http_client.fetch(request) self.assertIn("not-interface-or-ip", str(context.exception))
Example #27
Source File: httpclient_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
def test_reuse_request_from_response(self): # The response.request attribute should be an HTTPRequest, not # a _RequestProxy. # This test uses self.http_client.fetch because self.fetch calls # self.get_url on the input unconditionally. url = self.get_url("/hello") response = yield self.http_client.fetch(url) self.assertEqual(response.request.url, url) self.assertTrue(isinstance(response.request, HTTPRequest)) response2 = yield self.http_client.fetch(response.request) self.assertEqual(response2.body, b"Hello world!")
Example #28
Source File: httpclient_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
def test_credentials_in_url(self): url = self.get_url("/auth").replace("http://", "http://me:secret@") response = self.fetch(url) self.assertEqual(b"Basic " + base64.b64encode(b"me:secret"), response.body)
Example #29
Source File: httpclient_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
def test_redirect_put_with_body(self): response = self.fetch( "/redirect?url=/put&status=307", method="PUT", body="hello" ) self.assertEqual(response.body, b"Put body: hello")
Example #30
Source File: httpclient_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
def prepare(self): self.write("redirects can have bodies too") self.redirect( self.get_argument("url"), status=int(self.get_argument("status", "302")) )