Пример #1
0
    def get_app(self):
        class SetCookieHandler(RequestHandler):
            def get(self):
                # Try setting cookies with different argument types
                # to ensure that everything gets encoded correctly
                self.set_cookie("str", "asdf")
                self.set_cookie("unicode", u"qwer")
                self.set_cookie("bytes", b("zxcv"))

        class GetCookieHandler(RequestHandler):
            def get(self):
                self.write(self.get_cookie("foo"))

        class SetCookieDomainHandler(RequestHandler):
            def get(self):
                # unicode domain and path arguments shouldn't break things
                # either (see bug #285)
                self.set_cookie("unicode_args",
                                "blah",
                                domain=u"foo.com",
                                path=u"/foo")

        class SetCookieSpecialCharHandler(RequestHandler):
            def get(self):
                self.set_cookie("equals", "a=b")
                self.set_cookie("semicolon", "a;b")
                self.set_cookie("quote", 'a"b')

        return Application([
            ("/set", SetCookieHandler),
            ("/get", GetCookieHandler),
            ("/set_domain", SetCookieDomainHandler),
            ("/special_char", SetCookieSpecialCharHandler),
        ])
Пример #2
0
    def get_app(self):
        loader = DictLoader({
            "linkify.html":
            "{% module linkify(message) %}",
            "page.html":
            """\
<html><head></head><body>
{% for e in entries %}
{% module Template("entry.html", entry=e) %}
{% end %}
</body></html>""",
            "entry.html":
            """\
{{ set_resources(embedded_css=".entry { margin-bottom: 1em; }", embedded_javascript="js_embed()", css_files=["/base.css", "/foo.css"], javascript_files="/common.js", html_head="<meta>", html_body='<script src="/analytics.js"/>') }}
<div class="entry">...</div>""",
        })
        urls = [
            url("/typecheck/(.*)", TypeCheckHandler, name='typecheck'),
            url("/decode_arg/(.*)", DecodeArgHandler),
            url("/decode_arg_kw/(?P<arg>.*)", DecodeArgHandler),
            url("/linkify", LinkifyHandler),
            url("/uimodule_resources", UIModuleResourceHandler),
            url("/optional_path/(.+)?", OptionalPathHandler),
            url("/flow_control", FlowControlHandler),
            url("/multi_header", MultiHeaderHandler),
        ]
        return Application(urls,
                           template_loader=loader,
                           autoescape="xhtml_escape")
Пример #3
0
    def get_app(self):
        return Application(
            [
                # test endpoints
                ('/openid/client/login', OpenIdClientLoginHandler,
                 dict(test=self)),
                ('/oauth10/client/login', OAuth1ClientLoginHandler,
                 dict(test=self, version='1.0')),
                ('/oauth10/client/request_params',
                 OAuth1ClientRequestParametersHandler, dict(version='1.0')),
                ('/oauth10a/client/login', OAuth1ClientLoginHandler,
                 dict(test=self, version='1.0a')),
                ('/oauth10a/client/request_params',
                 OAuth1ClientRequestParametersHandler, dict(version='1.0a')),
                ('/oauth2/client/login', OAuth2ClientLoginHandler,
                 dict(test=self)),

                # simulated servers
                ('/openid/server/authenticate', OpenIdServerAuthenticateHandler
                 ),
                ('/oauth1/server/request_token',
                 OAuth1ServerRequestTokenHandler),
                ('/oauth1/server/access_token',
                 OAuth1ServerAccessTokenHandler),
            ],
            http_client=self.http_client)
Пример #4
0
 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),
         ], gzip=True)
Пример #5
0
def run():
    app = Application()
    port = random.randrange(options.min_port, options.max_port)
    app.listen(port, address='127.0.0.1')
    signal.signal(signal.SIGCHLD, handle_sigchld)
    args = ["ab"]
    args.extend(["-n", str(options.n)])
    args.extend(["-c", str(options.c)])
    if options.keepalive:
        args.append("-k")
    if options.quiet:
        # just stops the progress messages printed to stderr
        args.append("-q")
    args.append("http://127.0.0.1:%d/" % port)
    subprocess.Popen(args)
    IOLoop.instance().start()
    IOLoop.instance().close()
    del IOLoop._instance
    assert not IOLoop.initialized()
Пример #6
0
def run():
    app = Application()
    port = random.randrange(options.min_port, options.max_port)
    app.listen(port, address='127.0.0.1')
    signal.signal(signal.SIGCHLD, handle_sigchld)
    args = ["ab"]
    args.extend(["-n", str(options.n)])
    args.extend(["-c", str(options.c)])
    if options.keepalive:
        args.append("-k")
    if options.quiet:
        # just stops the progress messages printed to stderr
        args.append("-q")
    args.append("http://127.0.0.1:%d/" % port)
    subprocess.Popen(args)
    IOLoop.instance().start()
    IOLoop.instance().close()
    del IOLoop._instance
    assert not IOLoop.initialized()
Пример #7
0
 def get_app(self):
     class ProcessHandler(RequestHandler):
         def get(self):
             if self.get_argument("exit", None):
                 # must use os._exit instead of sys.exit so unittest's
                 # exception handler doesn't catch it
                 os._exit(int(self.get_argument("exit")))
             if self.get_argument("signal", None):
                 os.kill(os.getpid(),
                         int(self.get_argument("signal")))
             self.write(str(os.getpid()))
     return Application([("/", ProcessHandler)])
Пример #8
0
    def get_app(self):
        class DefaultHandler(RequestHandler):
            def get(self):
                if self.get_argument("status", None):
                    raise HTTPError(int(self.get_argument("status")))
                1 / 0

        class WriteErrorHandler(RequestHandler):
            def get(self):
                if self.get_argument("status", None):
                    self.send_error(int(self.get_argument("status")))
                else:
                    1 / 0

            def write_error(self, status_code, **kwargs):
                self.set_header("Content-Type", "text/plain")
                if "exc_info" in kwargs:
                    self.write("Exception: %s" %
                               kwargs["exc_info"][0].__name__)
                else:
                    self.write("Status: %d" % status_code)

        class GetErrorHtmlHandler(RequestHandler):
            def get(self):
                if self.get_argument("status", None):
                    self.send_error(int(self.get_argument("status")))
                else:
                    1 / 0

            def get_error_html(self, status_code, **kwargs):
                self.set_header("Content-Type", "text/plain")
                if "exception" in kwargs:
                    self.write("Exception: %s" % sys.exc_info()[0].__name__)
                else:
                    self.write("Status: %d" % status_code)

        class FailedWriteErrorHandler(RequestHandler):
            def get(self):
                1 / 0

            def write_error(self, status_code, **kwargs):
                raise Exception("exception in write_error")

        return Application([
            url("/default", DefaultHandler),
            url("/write_error", WriteErrorHandler),
            url("/get_error_html", GetErrorHtmlHandler),
            url("/failed_write_error", FailedWriteErrorHandler),
        ])
Пример #9
0
    def get_app(self):
        class StaticUrlHandler(RequestHandler):
            def get(self, path):
                self.write(self.static_url(path))

        class AbsoluteStaticUrlHandler(RequestHandler):
            include_host = True

            def get(self, path):
                self.write(self.static_url(path))

        return Application(
            [('/static_url/(.*)', StaticUrlHandler),
             ('/abs_static_url/(.*)', AbsoluteStaticUrlHandler)],
            static_path=os.path.join(os.path.dirname(__file__), 'static'))
Пример #10
0
    def get_app(self):
        class MyStaticFileHandler(StaticFileHandler):
            def get(self, path):
                assert path == "foo.txt"
                self.write("bar")

            @classmethod
            def make_static_url(cls, settings, path):
                return "/static/%s?v=42" % path

        class StaticUrlHandler(RequestHandler):
            def get(self, path):
                self.write(self.static_url(path))

        return Application([("/static_url/(.*)", StaticUrlHandler)],
                           static_path="dummy",
                           static_handler_class=MyStaticFileHandler)
Пример #11
0
 def test_unix_socket(self):
     sockfile = os.path.join(self.tmpdir, "test.sock")
     sock = netutil.bind_unix_socket(sockfile)
     app = Application([("/hello", HelloWorldRequestHandler)])
     server = HTTPServer(app, io_loop=self.io_loop)
     server.add_socket(sock)
     stream = IOStream(socket.socket(socket.AF_UNIX), io_loop=self.io_loop)
     stream.connect(sockfile, self.stop)
     self.wait()
     stream.write(b("GET /hello HTTP/1.0\r\n\r\n"))
     stream.read_until(b("\r\n"), self.stop)
     response = self.wait()
     self.assertEqual(response, b("HTTP/1.0 200 OK\r\n"))
     stream.read_until(b("\r\n\r\n"), self.stop)
     headers = HTTPHeaders.parse(self.wait().decode('latin1'))
     stream.read_bytes(int(headers["Content-Length"]), self.stop)
     body = self.wait()
     self.assertEqual(body, b("Hello world"))
Пример #12
0
 def get_app(self):
     return Application([('/', HelloHandler)])
Пример #13
0
 def get_app(self):
     return Application([('/', HelloWorldRequestHandler,
                          dict(protocol="https"))])
Пример #14
0
 def get_app(self):
     return Application([
         ("/echo", EchoHandler),
         ("/typecheck", TypeCheckHandler),
     ])
Пример #15
0
 def get_app(self):
     return Application(self.get_handlers())
Пример #16
0
 def get_app(self):
     return Application([('/', TestRequestHandler,
                          dict(io_loop=self.io_loop))])
Пример #17
0
 def get_app(self):
     return Application([
         ('/sequence', GenSequenceHandler),
         ('/task', GenTaskHandler),
     ])
Пример #18
0
 def get_app(self):
     return Application([('/relative', AuthRedirectRequestHandler,
                          dict(login_url='/login')),
                         ('/absolute', AuthRedirectRequestHandler,
                          dict(login_url='http://example.com/login'))])
Пример #19
0
 def get_app(self):
     return Application([('/', ConnectionCloseHandler, dict(test=self))])
Пример #20
0
 def get_app(self):
     return Application([("/(.*)", EchoHandler)])