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


Python simple_server.make_server方法代码示例

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


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

示例1: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def run(self, app): # pragma: no cover
        from wsgiref.simple_server import WSGIRequestHandler, WSGIServer
        from wsgiref.simple_server import make_server
        import socket

        class FixedHandler(WSGIRequestHandler):
            def address_string(self): # Prevent reverse DNS lookups please.
                return self.client_address[0]
            def log_request(*args, **kw):
                if not self.quiet:
                    return WSGIRequestHandler.log_request(*args, **kw)

        handler_cls = self.options.get('handler_class', FixedHandler)
        server_cls  = self.options.get('server_class', WSGIServer)

        if ':' in self.host: # Fix wsgiref for IPv6 addresses.
            if getattr(server_cls, 'address_family') == socket.AF_INET:
                class server_cls(server_cls):
                    address_family = socket.AF_INET6

        srv = make_server(self.host, self.port, app, server_cls, handler_cls)
        srv.serve_forever() 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:24,代码来源:__init__.py

示例2: main

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def main():
    gmr.TextGuruMeditation.setup_autorun(version)

    app = api_app.setup_app(argv=sys.argv)

    host = cfg.CONF.api_settings.bind_host
    port = cfg.CONF.api_settings.bind_port
    LOG.info("Starting API server on %(host)s:%(port)s",
             {"host": host, "port": port})
    if cfg.CONF.api_settings.auth_strategy != constants.KEYSTONE:
        LOG.warning('Octavia configuration [api_settings] auth_strategy is '
                    'not set to "keystone". This is not a normal '
                    'configuration and you may get "Missing project ID" '
                    'errors from API calls."')
    LOG.warning('You are running the Octavia API wsgi application using '
                'simple_server. We do not recommend this outside of simple '
                'testing. We recommend you run the Octavia API wsgi with '
                'a more full function server such as gunicorn or uWSGI.')
    srv = simple_server.make_server(host, port, app)

    srv.serve_forever() 
开发者ID:openstack,项目名称:octavia,代码行数:23,代码来源:api.py

示例3: __init__

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def __init__(self, host='127.0.0.1', port=0, application=None, **kwargs):
        self.app = application
        if self.port_envvar in os.environ:
            port = int(os.environ[self.port_envvar])
        self._server = make_server(
            host,
            port,
            self.app,
            handler_class=Handler,
            **kwargs
        )
        self.host = self._server.server_address[0]
        self.port = self._server.server_address[1]
        self.protocol = 'http'

        self._thread = threading.Thread(
            name=self.__class__,
            target=self._server.serve_forever,
        ) 
开发者ID:pypa,项目名称:pipenv,代码行数:21,代码来源:serve.py

示例4: setup_class

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def setup_class(cls):
        from httpbin import app as httpbin_app

        cls.temp_dir = tempfile.mkdtemp('warctest')

        server = make_server('localhost', 0, httpbin_app)
        addr, cls.port = server.socket.getsockname()

        def run():
            try:
                server.serve_forever()
            except  Exception as e:
                print(e)

        thread = threading.Thread(target=run)
        thread.daemon = True
        thread.start()
        time.sleep(0.1) 
开发者ID:webrecorder,项目名称:warcio,代码行数:20,代码来源:test_capture_http.py

示例5: builtin_httpd

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def builtin_httpd(address, port):
    from wsgiref.simple_server import make_server
    log.info('Starting builtin httpd...')
    server = make_server(address, port, application)
    try:
        server.serve_forever()
    except (KeyboardInterrupt, SystemExit):
        if RESPONSE_WORKER:
            log.debug('Stopping workers...')
            REQUEST_HANDLER.ipc.send(None)  # HAXX
            RESPONSE_WORKER.join()
        log.info('Finished...')


# Initialize subprocess immediately. Only use this if you use the uWSGI
# `lazy-apps` setting or have a single worker only! 
开发者ID:ossobv,项目名称:slackbridge,代码行数:18,代码来源:wsgi.py

示例6: _start_server

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def _start_server(self, app):
        """Starts a server and returns its origin ("http://localhost:PORT")."""
        (_, localhost) = _localhost()
        server_class = _make_ipv6_compatible_wsgi_server()
        server = simple_server.make_server(localhost, 0, app, server_class)
        executor = futures.ThreadPoolExecutor()
        future = executor.submit(server.serve_forever, poll_interval=0.01)

        def cleanup():
            server.shutdown()  # stop handling requests
            server.server_close()  # release port
            future.result(timeout=3)  # wait for server termination

        self.addCleanup(cleanup)
        if ":" in localhost and not localhost.startswith("["):
            # IPv6 IP address, probably "::1".
            localhost = "[%s]" % localhost
        return "http://%s:%d" % (localhost, server.server_port) 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:20,代码来源:server_info_test.py

示例7: roulette_server_3

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def roulette_server_3(count: int = 1) -> None:
    from wsgiref.simple_server import make_server
    from wsgiref.validate import validator

    wheel = American(seed=1)
    roulette = Roulette(wheel)
    debug = validator(roulette)
    httpd = make_server("", 8080, debug)
    if count is None:
        httpd.serve_forever()
    else:
        for c in range(count):
            httpd.handle_request()


# Client 
开发者ID:PacktPublishing,项目名称:Mastering-Object-Oriented-Python-Second-Edition,代码行数:18,代码来源:ch13_e1_ex3.py

示例8: roulette_server_4

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def roulette_server_4(count: int = 1):
    from wsgiref.simple_server import make_server
    from wsgiref.validate import validator

    wheel = American()
    roulette = Roulette(wheel)
    debug = validator(roulette)
    httpd = make_server("", 8080, debug)
    if count is None:
        httpd.serve_forever()
    else:
        for c in range(count):
            httpd.handle_request()


# Client 
开发者ID:PacktPublishing,项目名称:Mastering-Object-Oriented-Python-Second-Edition,代码行数:18,代码来源:ch13_e1_ex4.py

示例9: auth_server

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def auth_server(count: int = 1) -> None:
    from wsgiref.simple_server import make_server
    from wsgiref.validate import validator

    secure_app = Some_App()
    authenticated_app = Authenticate(users, secure_app)
    debug = validator(authenticated_app)
    httpd = make_server("", 8080, debug)
    if count is None:
        httpd.serve_forever()
    else:
        for c in range(count):
            httpd.handle_request()


# Demo 
开发者ID:PacktPublishing,项目名称:Mastering-Object-Oriented-Python-Second-Edition,代码行数:18,代码来源:ch13_e1_ex4.py

示例10: __init__

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def __init__(self):
        app = falcon.API(middleware=NormalizeMiddleware())
        app.req_options.auto_parse_form_urlencoded = True
        self.attach(app)

        # Set up log handlers
        log_handlers = []
        if config.LOGGING_BACKEND == "sql":
            from certidude.mysqllog import LogHandler
            from certidude.api.log import LogResource
            uri = config.cp.get("logging", "database")
            log_handlers.append(LogHandler(uri))
        elif config.LOGGING_BACKEND == "syslog":
            from logging.handlers import SysLogHandler
            log_handlers.append(SysLogHandler())
            # Browsing syslog via HTTP is obviously not possible out of the box
        elif config.LOGGING_BACKEND:
            raise ValueError("Invalid logging.backend = %s" % config.LOGGING_BACKEND)
        from certidude.push import EventSourceLogHandler
        log_handlers.append(EventSourceLogHandler())

        for j in logging.Logger.manager.loggerDict.values():
            if isinstance(j, logging.Logger): # PlaceHolder is what?
                if j.name.startswith("certidude."):
                    j.setLevel(logging.DEBUG)
                    for handler in log_handlers:
                        j.addHandler(handler)

        self.server = make_server("127.0.1.1", self.PORT, app, WSGIServer)
        setproctitle("certidude: %s" % self.NAME) 
开发者ID:laurivosandi,项目名称:certidude,代码行数:32,代码来源:__init__.py

示例11: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def run(self):
        server = make_server(self.host, self.port, self._app())
        self.port = server.server_port
        while not self._stopped():
            server.handle_request() 
开发者ID:pilosa,项目名称:python-pilosa,代码行数:7,代码来源:test_client_it.py

示例12: main

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def main(args=None):
    parser = ArgumentParser(description="Pyro http gateway command line launcher.")
    parser.add_argument("-H", "--host", default="localhost", help="hostname to bind server on (default=%(default)s)")
    parser.add_argument("-p", "--port", type=int, default=8080, help="port to bind server on (default=%(default)d)")
    parser.add_argument("-e", "--expose", default=pyro_app.ns_regex, help="a regex of object names to expose (default=%(default)s)")
    parser.add_argument("-g", "--gatewaykey", help="the api key to use to connect to the gateway itself")
    parser.add_argument("-t", "--timeout", type=float, default=pyro_app.comm_timeout,
                        help="Pyro timeout value to use (COMMTIMEOUT setting, default=%(default)f)")

    options = parser.parse_args(args)
    pyro_app.gateway_key = (options.gatewaykey or "").encode("utf-8")
    pyro_app.ns_regex = options.expose
    pyro_app.comm_timeout = config.COMMTIMEOUT = options.timeout
    if pyro_app.ns_regex:
        print("Exposing objects with names matching: ", pyro_app.ns_regex)
    else:
        print("Warning: exposing all objects (no expose regex set)")
    try:
        ns = get_nameserver()
    except errors.PyroError:
        print("Not yet connected to a name server.")
    else:
        print("Connected to name server at: ", ns._pyroUri)
    server = make_server(options.host, options.port, pyro_app)
    print("Pyro HTTP gateway running on http://{0}:{1}/pyro/".format(*server.socket.getsockname()))
    server.serve_forever()
    server.server_close()
    return 0 
开发者ID:irmen,项目名称:Pyro5,代码行数:30,代码来源:httpgateway.py

示例13: run_amock

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def run_amock(app=hello_app, data="GET / HTTP/1.0\n\n"):
    server = make_server("", 80, app, MockServer, MockHandler)
    inp, out, err, olderr = StringIO(data), StringIO(), StringIO(), sys.stderr
    sys.stderr = err

    try:
        server.finish_request((inp,out), ("127.0.0.1",8888))
    finally:
        sys.stderr = olderr

    return out.getvalue(), err.getvalue() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_wsgiref.py

示例14: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def run(self, handler): # pragma: no cover
        from wsgiref.simple_server import make_server, WSGIRequestHandler
        if self.quiet:
            class QuietHandler(WSGIRequestHandler):
                def log_request(*args, **kw): pass
            self.options['handler_class'] = QuietHandler
        srv = make_server(self.host, self.port, handler, **self.options)
        srv.serve_forever() 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:10,代码来源:bottle.py

示例15: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import make_server [as 别名]
def run(self, port=9000, host='127.0.0.1'):
        from wsgiref.simple_server import make_server
        print('application (%s) will start at %s:%s...' %
              (self._document_root, host, port))
        server = make_server(
            host, port, self.get_wsgi_application(debug=True))
        server.serve_forever() 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:9,代码来源:web.py


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