Exemplo n.º 1
0
    def get_app(self):
        from huacaya.auth import Server, Provider, ServerDaoWithStorage
        from huacaya.auth import EndpointApplication
        from huacaya.storage import StorageService
        from tornado.wsgi import WSGIAdapter

        self._storage = StorageService()
        serv_dao = ServerDaoWithStorage(self._storage)
        self._serv = Server(serv_dao)
        self._provider = Provider(self._serv)
        return WSGIAdapter(EndpointApplication(self._serv, self._provider))
Exemplo n.º 2
0
def test_tornado(wsgi_tester, hello_robot):
    from tornado.wsgi import WSGIAdapter
    import tornado.web
    from werobot.contrib.tornado import make_handler

    token = generate_token()
    endpoint = r'/werobot_tornado'
    hello_robot.token = token

    tornado_app = tornado.web.Application([
        (endpoint, make_handler(hello_robot)),
    ], debug=True)
    wsgi_tester(WSGIAdapter(tornado_app), token=token, endpoint=endpoint)
Exemplo n.º 3
0
 def run(self, isWsgi=False, debug=True):
     self.isWsgi = isWsgi
     self.debug = debug
     MainHandler = self.__construct_handler(isWsgi)
     app = tornado.web.Application([('/', MainHandler)], debug=debug)
     if isWsgi:
         return WSGIAdapter(app)
     else:
         app.listen(80)
         try:
             self.ioLoop.start()
         except:
             self.ioLoop.stop()
Exemplo n.º 4
0
def run(self, isWsgi=False, debug=True, port=80):
    self.isWsgi = isWsgi
    self.debug = debug
    if debug: set_logging(loggingLevel=logging.DEBUG)
    MainHandler = construct_handler(self, isWsgi)
    app = tornado.web.Application([('/', MainHandler)], debug=debug)
    logger.info('itchatmp started!%s' %
                (' press Ctrl+C to exit.' if debug else ''))
    if isWsgi:
        return WSGIAdapter(app)
    else:
        port = int(port)
        env_test(port)
        app.listen(port)
        try:
            self.ioLoop.start()
        except:
            logger.info('Bye~')
            self.ioLoop.stop()
Exemplo n.º 5
0
def main(app):

    global http_server

    if not tornado.options.options.fcgi:

        server_opts = le_config.tornado.server
        xheaders = False
        if 'xheaders' in server_opts:
            xheaders = server_opts.xheaders

        http_server = tornado.httpserver.HTTPServer(app, xheaders=xheaders)

        host = server_opts.host
        port = server_opts.port
        base = server_opts.base
        http_server.listen(port, address=host)
        tornado.log.gen_log.info('HTTP Server started on http://%s:%s/%s',
                                 host, port, base)

        signal.signal(signal.SIGTERM, sig_handler)
        signal.signal(signal.SIGINT, sig_handler)

        try:
            tornado.ioloop.IOLoop.instance().start()
        except KeyboardInterrupt:
            if hasattr(app, 'shutdown_hook'):
                app.shutdown_hook()
            raise

    else:

        from tornado.wsgi import WSGIAdapter

        wsgi_app = WSGIAdapter(app)

        def fcgiapp(env, start):
            # set the script name to "" so it does not appear in the tornado path match pattern
            env['SCRIPT_NAME'] = ''
            return wsgi_app(env, start)

        from flup.server.fcgi import WSGIServer
        WSGIServer(fcgiapp, bindAddress=tornado.options.options.fcgi).run()
Exemplo n.º 6
0
    def get_app(self):
        class HelloHandler(RequestHandler):
            def get(self):
                self.write("Hello world!")

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

        # It would be better to run the wsgiref server implementation in
        # another thread instead of using our own WSGIContainer, but this
        # fits better in our async testing framework and the wsgiref
        # validator should keep us honest
        with ignore_deprecation():
            return WSGIContainer(validator(WSGIAdapter(
                Application([
                    ("/", HelloHandler),
                    ("/path/(.*)", PathQuotingHandler),
                    ("/typecheck", TypeCheckHandler),
                ]))))
Exemplo n.º 7
0
        if not access_token:
            raise tornado.web.HTTPError(403)
        rsp_2 = ss.get("https://api.github.com/user", headers={
            "Authorization": f"token {access_token}",
        })
        token = jwt.encode({
            "role": "q",
            "name": rsp_2.json()["login"],
        }, 'x' * 32, algorithm='HS256').decode()
        self.write(tpl_script.format(authorization=rsp_2.text, jwt=token))


app = tornado.web.Application([
    (r"/gh", Api),
])


if __name__ == '__main__':
    from tornado.options import define, parse_command_line, options
    from tornado.httpserver import HTTPServer
    from tornado.netutil import bind_unix_socket
    from tornado.ioloop import IOLoop
    define("sock", default=".sock")
    parse_command_line()
    server = HTTPServer(app, xheaders=True)
    server.add_socket(bind_unix_socket(options.sock, 0o666))
    IOLoop.current().start()
else:
    from tornado.wsgi import WSGIAdapter
    application = WSGIAdapter(app)
Exemplo n.º 8
0
 def setUp(self):
     AsyncHTTPTestCase.setUp(self)
     self.app = webtest.TestApp(WSGIAdapter(self.get_app()),
                                cookiejar=CookieJar())
Exemplo n.º 9
0
 def get_app(self):
     self.app = Application(self.get_handlers(),
                            **self.get_app_kwargs())
     return WSGIContainer(validator(WSGIAdapter(self.app)))
Exemplo n.º 10
0
 def get_app(self):
     with ignore_deprecation():
         return WSGIContainer(validator(WSGIAdapter(Application(self.get_handlers()))))
Exemplo n.º 11
0
 def __call__(self, environ, start_response):
     if not self._app:
         self._app = WSGIAdapter(
             EndpointApplication(self._auth_server, self._auth_provider))
     return self._app(environ, start_response)