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


Python httpserver.HTTPServer方法代码示例

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


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

示例1: setUp

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def setUp(self):
        if IOLoop.configured_class().__name__ in ('TwistedIOLoop',
                                                  'AsyncIOMainLoop'):
            # TwistedIOLoop only supports the global reactor, so we can't have
            # separate IOLoops for client and server threads.
            # AsyncIOMainLoop doesn't work with the default policy
            # (although it could with some tweaks to this test and a
            # policy that created loops for non-main threads).
            raise unittest.SkipTest(
                'Sync HTTPClient not compatible with TwistedIOLoop or '
                'AsyncIOMainLoop')
        self.server_ioloop = IOLoop()

        sock, self.port = bind_unused_port()
        app = Application([('/', HelloWorldHandler)])
        self.server = HTTPServer(app, io_loop=self.server_ioloop)
        self.server.add_socket(sock)

        self.server_thread = threading.Thread(target=self.server_ioloop.start)
        self.server_thread.start()

        self.http_client = HTTPClient() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:24,代码来源:httpclient_test.py

示例2: test_chunked_request_body

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def test_chunked_request_body(self):
        # Chunked requests are not widely supported and we don't have a way
        # to generate them in AsyncHTTPClient, but HTTPServer will read them.
        self.stream.write(b"""\
POST /echo HTTP/1.1
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded

4
foo=
3
bar
0

""".replace(b"\n", b"\r\n"))
        read_stream_body(self.stream, self.stop)
        headers, response = self.wait()
        self.assertEqual(json_decode(response), {u('foo'): [u('bar')]}) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:httpserver_test.py

示例3: test_missing_key

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def test_missing_key(self):
        """A missing SSL key should cause an immediate exception."""

        application = Application()
        module_dir = os.path.dirname(__file__)
        existing_certificate = os.path.join(module_dir, 'test.crt')
        existing_key = os.path.join(module_dir, 'test.key')

        self.assertRaises((ValueError, IOError),
                          HTTPServer, application, ssl_options={
                              "certfile": "/__mising__.crt",
        })
        self.assertRaises((ValueError, IOError),
                          HTTPServer, application, ssl_options={
                              "certfile": existing_certificate,
                              "keyfile": "/__missing__.key"
        })

        # This actually works because both files exist
        HTTPServer(application, ssl_options={
                   "certfile": existing_certificate,
                   "keyfile": existing_key,
                   }) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:25,代码来源:httpserver_test.py

示例4: tornadoserver

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def tornadoserver():
    setup_logging('tornadoserver')
    app = create_app(parse_options())
    fsh_folder = app.blueprints['flask_statics_helper'].static_folder
    log_messages(app, OPTIONS['--port'], fsh_folder)

    # Setup the application.
    container = wsgi.WSGIContainer(app)
    application = web.Application([
        (r'/static/flask_statics_helper/(.*)', web.StaticFileHandler, dict(path=fsh_folder)),
        (r'/(favicon\.ico)', web.StaticFileHandler, dict(path=app.static_folder)),
        (r'/static/(.*)', web.StaticFileHandler, dict(path=app.static_folder)),
        (r'.*', web.FallbackHandler, dict(fallback=container))
    ])  # From http://maxburstein.com/blog/django-static-files-heroku/
    http_server = httpserver.HTTPServer(application)
    http_server.bind(OPTIONS['--port'])

    # Start the server.
    http_server.start(0)  # Forks multiple sub-processes
    ioloop.IOLoop.instance().start() 
开发者ID:Robpol86,项目名称:Flask-Large-Application-Example,代码行数:22,代码来源:manage.py

示例5: main

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def main():
    global config, output_wechat, app
    config = ConfigParser()
    config.read('config')
    from .utility import output_wechat
    app = Application()

    parse_command_line()
    try:
        from .views import app
        http_server = HTTPServer(app)
        http_server.listen(config['base']['port'])
        IOLoop.current().start()
    except Exception as e:
        print(e)
    finally:
        with open('config', 'w') as f:
            config.write(f) 
开发者ID:iakisey,项目名称:ServerMsgPush,代码行数:20,代码来源:__init__.py

示例6: setUp

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def setUp(self):
        self.server_ioloop = IOLoop()
        event = threading.Event()

        @gen.coroutine
        def init_server():
            sock, self.port = bind_unused_port()
            app = Application([("/", HelloWorldHandler)])
            self.server = HTTPServer(app)
            self.server.add_socket(sock)
            event.set()

        def start():
            self.server_ioloop.run_sync(init_server)
            self.server_ioloop.start()

        self.server_thread = threading.Thread(target=start)
        self.server_thread.start()
        event.wait()

        self.http_client = HTTPClient() 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:23,代码来源:httpclient_test.py

示例7: test_chunked_request_body

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def test_chunked_request_body(self):
        # Chunked requests are not widely supported and we don't have a way
        # to generate them in AsyncHTTPClient, but HTTPServer will read them.
        self.stream.write(
            b"""\
POST /echo HTTP/1.1
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded

4
foo=
3
bar
0

""".replace(
                b"\n", b"\r\n"
            )
        )
        start_line, headers, response = self.io_loop.run_sync(
            lambda: read_stream_body(self.stream)
        )
        self.assertEqual(json_decode(response), {u"foo": [u"bar"]}) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:25,代码来源:httpserver_test.py

示例8: _patch_httpserver

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def _patch_httpserver(self):
        """
        重写httpserver的xheader配置,让gunicorn可以加载xheaders设置
        :return:
        """
        httpserver = sys.modules["tornado.httpserver"]
        try:
            xhs = settings.XHEADERS
        except:
            xhs = True

        class TorngasHTTPServer(httpserver.HTTPServer):
            def __init__(self, request_callback, xheaders=xhs, **kwargs):
                super(TorngasHTTPServer, self).__init__(request_callback,
                                                        xheaders=xheaders,
                                                        **kwargs)

        httpserver.HTTPServer = TorngasHTTPServer
        sys.modules["tornado.httpserver"] = httpserver 
开发者ID:mqingyn,项目名称:torngas,代码行数:21,代码来源:webserver.py

示例9: load_httpserver

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def load_httpserver(self, sockets=None, **kwargs):
        if not sockets:
            from tornado.netutil import bind_sockets

            if settings.IPV4_ONLY:
                import socket

                sockets = bind_sockets(options.port, options.address, family=socket.AF_INET)
            else:
                sockets = bind_sockets(options.port, options.address)

        http_server = tornado.httpserver.HTTPServer(self.application, **kwargs)

        http_server.add_sockets(sockets)
        self.httpserver = http_server
        return self.httpserver 
开发者ID:mqingyn,项目名称:torngas,代码行数:18,代码来源:webserver.py

示例10: run

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def run(self):
        """
        Function to Run the server. Server runs on host: 127.0.0.1 and port: 2000 by default. Debug is also set to false
        by default

        Can be overriden by using the config.ini file
        """
        define("port", default=self.port, help="Run on given port", type=int)
        define("host", default=self.host, help="Run on given host", type=str)
        define("debug", default=self.debug, help="True for development", type=bool)

        parse_command_line()

        print(Fore.GREEN + "Starting Bast Server....")
        print(Fore.GREEN + "Bast Server Running on %s:%s" % (options.host, options.port))

        application = Application(self.handler, debug=options.debug)
        server = HTTPServer(application)
        server.listen(options.port, options.host)
        IOLoop.current().start() 
开发者ID:moluwole,项目名称:Bast,代码行数:22,代码来源:bast.py

示例11: setUp

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def setUp(self):
        if IOLoop.configured_class().__name__ == 'TwistedIOLoop':
            # TwistedIOLoop only supports the global reactor, so we can't have
            # separate IOLoops for client and server threads.
            raise unittest.SkipTest(
                'Sync HTTPClient not compatible with TwistedIOLoop')
        self.server_ioloop = IOLoop()

        sock, self.port = bind_unused_port()
        app = Application([('/', HelloWorldHandler)])
        server = HTTPServer(app, io_loop=self.server_ioloop)
        server.add_socket(sock)

        self.server_thread = threading.Thread(target=self.server_ioloop.start)
        self.server_thread.start()

        self.http_client = HTTPClient() 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:19,代码来源:httpclient_test.py

示例12: test_missing_key

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def test_missing_key(self):
        """A missing SSL key should cause an immediate exception."""

        application = Application()
        module_dir = os.path.dirname(__file__)
        existing_certificate = os.path.join(module_dir, 'test.crt')

        self.assertRaises(ValueError, HTTPServer, application, ssl_options={
                          "certfile": "/__mising__.crt",
                          })
        self.assertRaises(ValueError, HTTPServer, application, ssl_options={
                          "certfile": existing_certificate,
                          "keyfile": "/__missing__.key"
                          })

        # This actually works because both files exist
        HTTPServer(application, ssl_options={
                   "certfile": existing_certificate,
                   "keyfile": existing_certificate
                   }) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:22,代码来源:httpserver_test.py

示例13: test_unix_socket

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
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")
        stream.close()
        server.stop() 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:22,代码来源:httpserver_test.py

示例14: setUp

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def setUp(self):
        if IOLoop.configured_class().__name__ == 'TwistedIOLoop':
            # TwistedIOLoop only supports the global reactor, so we can't have
            # separate IOLoops for client and server threads.
            raise unittest.SkipTest(
                'Sync HTTPClient not compatible with TwistedIOLoop')
        self.server_ioloop = IOLoop()

        @gen.coroutine
        def init_server():
            sock, self.port = bind_unused_port()
            app = Application([('/', HelloWorldHandler)])
            self.server = HTTPServer(app)
            self.server.add_socket(sock)
        self.server_ioloop.run_sync(init_server)

        self.server_thread = threading.Thread(target=self.server_ioloop.start)
        self.server_thread.start()

        self.http_client = HTTPClient() 
开发者ID:tp4a,项目名称:teleport,代码行数:22,代码来源:httpclient_test.py

示例15: run

# 需要导入模块: from tornado import httpserver [as 别名]
# 或者: from tornado.httpserver import HTTPServer [as 别名]
def run(self, quiet=None, server=''):
        """ Start the tornado server, run forever.
            'quiet' and 'server' arguments are no longer used, they are keep only for backward compatibility
        """

        try:
            loop = IOLoop()
            http_server = HTTPServer(WSGIContainer(self.app))
            http_server.listen(self.port)
            loop.start()

        except socket.error as serr:
            # Re raise the socket error if not "[Errno 98] Address already in use"
            if serr.errno != errno.EADDRINUSE:
                raise serr
            else:
                logger.warning("""The webserver port {} is already used.
The SnapRobotServer is maybe already run or another software use this port.""".format(self.port)) 
开发者ID:poppy-project,项目名称:pypot,代码行数:20,代码来源:snap.py


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