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


Python wsgi.Server方法代码示例

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


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

示例1: start

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def start(self):
        d = PathInfoDispatcher({"/": self.app})
        self.server = Server(("0.0.0.0", self.proxyport), d)
        self.proxy_thread = threading.Thread(target=self.server.start)
        self.proxy_thread.daemon = True
        self.proxy_thread.start()
        BitcoinD.start(self)

        # Now that bitcoind is running on the real rpcport, let's tell all
        # future callers to talk to the proxyport. We use the bind_addr as a
        # signal that the port is bound and accepting connections.
        while self.server.bind_addr[1] == 0:
            pass
        self.proxiedport = self.rpcport
        self.rpcport = self.server.bind_addr[1]
        logging.debug(
            "bitcoind reverse proxy listening on {}, forwarding to {}".format(
                self.rpcport, self.proxiedport
            )
        ) 
开发者ID:willcl-ark,项目名称:lnd_grpc,代码行数:22,代码来源:btcproxy.py

示例2: run

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def run(self, handler):
        try:
            # First try to use the new version
            from cheroot.ssl.pyopenssl import pyOpenSSLAdapter
            from cheroot import wsgi
            server = wsgi.Server((self.host, self.port), handler, request_queue_size=32)
        except Exception:
            from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
            from cherrypy import wsgiserver
            server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler, request_queue_size=32)

        self.srv = server

        # If cert variable is has a valid path, SSL will be used
        # You can set it to None to disable SSL
        server.ssl_adapter = pyOpenSSLAdapter(Config.REST_SSL_CERTFILE,
                                              Config.REST_SSL_KEYFILE,
                                              Config.REST_SSL_CA_CERTS)
        try:
            server.start()
        finally:
            server.stop() 
开发者ID:grycap,项目名称:im,代码行数:24,代码来源:REST.py

示例3: run

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def run(self, handler): # pragma: no cover
        from cheroot import wsgi
        from cheroot.ssl import builtin
        self.options['bind_addr'] = (self.host, self.port)
        self.options['wsgi_app'] = handler
        certfile = self.options.pop('certfile', None)
        keyfile = self.options.pop('keyfile', None)
        chainfile = self.options.pop('chainfile', None)
        server = wsgi.Server(**self.options)
        if certfile and keyfile:
            server.ssl_adapter = builtin.BuiltinSSLAdapter(
                    certfile, keyfile, chainfile)
        try:
            server.start()
        finally:
            server.stop() 
开发者ID:brycesub,项目名称:silvia-pi,代码行数:18,代码来源:bottle.py

示例4: run

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def run(self, handler): # pragma: no cover
        from cheroot import wsgi
        from cheroot.ssl import builtin
        self.options['bind_addr'] = (self.host, self.port)
        self.options['wsgi_app'] = handler
        certfile = self.options.pop('certfile', None)
        keyfile = self.options.pop('keyfile', None)
        chainfile = self.options.pop('chainfile', None)
        server = wsgi.Server(**self.options)
        if certfile and keyfile:
            server.ssl_adapter = builtin.BuiltinSSLAdapter(
                    certfile, keyfile, chainfile)
        try:
            server.start()
        finally:
            server.stop()
############# 
开发者ID:gilestrolab,项目名称:ethoscope,代码行数:19,代码来源:server.py

示例5: simple_wsgi_server

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def simple_wsgi_server():
    """Fucking simple wsgi server fixture (duh)."""
    port = portend.find_available_local_port()

    def app(environ, start_response):
        status = '200 OK'
        response_headers = [('Content-type', 'text/plain')]
        start_response(status, response_headers)
        return [b'Hello world!']

    host = '::'
    addr = host, port
    server = wsgi.Server(addr, app)
    url = 'http://localhost:{port}/'.format(**locals())
    with server._run_in_thread() as thread:
        yield locals() 
开发者ID:cherrypy,项目名称:cheroot,代码行数:18,代码来源:test_wsgi.py

示例6: run

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def run(self):
        self._configure_flask_app()
        dispatcher = PathInfoDispatcher({"/": app})
        self.server = WSGIServer((self.host, self.port), dispatcher)
        self.server.start() 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:7,代码来源:web_app.py

示例7: setup

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def setup(self):
        """
        Generate the flask App and prepare the HTTP server.

        :return: server host and port tuple
        :rtype: ``Tuple[str, int]``
        """
        app, _ = generate_interactive_api(self.cfg.ihandler)
        self._server = wsgi.Server((self.cfg.host, self.cfg.port), app)
        self._server.prepare()

        return self._server.bind_addr 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:14,代码来源:http.py

示例8: start_web_rest_server

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def start_web_rest_server(models, rest_port, num_threads):
    d = PathInfoDispatcher({'/': create_rest_api(models)})
    server = WSGIServer(('0.0.0.0', rest_port), d,
                        numthreads=num_threads,
                        request_queue_size=GLOBAL_CONFIG[
                            'rest_requests_queue_size'])
    logger.info("REST server listens on port {port} and will be "
                "serving models: {models}".format(port=rest_port,
                                                  models=list(models.keys())))
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop() 
开发者ID:openvinotoolkit,项目名称:model_server,代码行数:15,代码来源:start.py

示例9: __init__

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def __init__(
        self, bind_addr, wsgi_app, numthreads=10, server_name=None,
        max=-1, request_queue_size=5, timeout=10, shutdown_timeout=5,
        accepted_queue_size=-1, accepted_queue_timeout=10,
        peercreds_enabled=False, peercreds_resolve_enabled=False,
    ):
        """Initialize WSGI Server instance.

        Args:
            bind_addr (tuple): network interface to listen to
            wsgi_app (callable): WSGI application callable
            numthreads (int): number of threads for WSGI thread pool
            server_name (str): web server name to be advertised via
                Server HTTP header
            max (int): maximum number of worker threads
            request_queue_size (int): the 'backlog' arg to
                socket.listen(); max queued connections
            timeout (int): the timeout in seconds for accepted connections
            shutdown_timeout (int): the total time, in seconds, to
                wait for worker threads to cleanly exit
            accepted_queue_size (int): maximum number of active
                requests in queue
            accepted_queue_timeout (int): timeout for putting request
                into queue
        """
        super(Server, self).__init__(
            bind_addr,
            gateway=wsgi_gateways[self.wsgi_version],
            server_name=server_name,
            peercreds_enabled=peercreds_enabled,
            peercreds_resolve_enabled=peercreds_resolve_enabled,
        )
        self.wsgi_app = wsgi_app
        self.request_queue_size = request_queue_size
        self.timeout = timeout
        self.shutdown_timeout = shutdown_timeout
        self.requests = threadpool.ThreadPool(
            self, min=numthreads or 1, max=max,
            accepted_queue_size=accepted_queue_size,
            accepted_queue_timeout=accepted_queue_timeout,
        ) 
开发者ID:cherrypy,项目名称:cheroot,代码行数:43,代码来源:wsgi.py

示例10: write

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def write(self, chunk):
        """WSGI callable to write unbuffered data to the client.

        This method is also used internally by start_response (to write
        data from the iterable returned by the WSGI application).
        """
        if not self.started_response:
            raise AssertionError('WSGI write called before start_response.')

        chunklen = len(chunk)
        rbo = self.remaining_bytes_out
        if rbo is not None and chunklen > rbo:
            if not self.req.sent_headers:
                # Whew. We can send a 500 to the client.
                self.req.simple_response(
                    '500 Internal Server Error',
                    'The requested resource returned more bytes than the '
                    'declared Content-Length.',
                )
            else:
                # Dang. We have probably already sent data. Truncate the chunk
                # to fit (so the client doesn't hang) and raise an error later.
                chunk = chunk[:rbo]

        self.req.ensure_headers_sent()

        self.req.write(chunk)

        if rbo is not None:
            rbo -= chunklen
            if rbo < 0:
                raise ValueError(
                    'Response body exceeds the declared Content-Length.',
                ) 
开发者ID:cherrypy,项目名称:cheroot,代码行数:36,代码来源:wsgi.py

示例11: run

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def run(self):
        """ Starts listening server"""

        logging.info (" [+] Starting Macro_Pack WebDAV server...")
        logging.info ("   [-] Files in \"" + self.WRoot + r"\" folder are accessible using url http://{ip}:{port}  or \\{ip}@{port}\DavWWWRoot".format(ip=getHostIp(), port=self.listenPort))
        logging.info ("   [-] Listening on port %s (ctrl-c to exit)...", self.listenPort)

        # Prepare WsgiDAV config
        config = {
            'middleware_stack' : {
                WsgiDavDirBrowser,  #Enabling dir_browser middleware
            },
            'verbose': 3,

            'add_header_MS_Author_Via': True,
            'unquote_path_info': False,
            're_encode_path_info': None,
            'host': '0.0.0.0',
            'dir_browser': {'davmount': False,
                'enable': True, #Enabling directory browsing on dir_browser
                'ms_mount': False,
                'show_user': True,
                'ms_sharepoint_plugin': True,
                'ms_sharepoint_urls': False,
                'response_trailer': False},
            'port': self.listenPort,    # Specifying listening port
            'provider_mapping': {'/': self.WRoot}   #Specifying root folder
        }

        app = WsgiDAVApp(config)

        server_args = {
            "bind_addr": (config["host"], config["port"]),
        "wsgi_app": app,
        }
        server = wsgi.Server(**server_args)
        
        try:
            log = logging.getLogger('wsgidav')
            log.raiseExceptions = False # hack to avoid false exceptions
            log.propagate = True
            log.setLevel(logging.INFO)
            server.start()
        except KeyboardInterrupt:
            logging.info("  [!] Ctrl + C detected, closing WebDAV sever")
            server.stop() 
开发者ID:sevagas,项目名称:macro_pack,代码行数:48,代码来源:Wlisten_server.py

示例12: _handle

# 需要导入模块: from cheroot import wsgi [as 别名]
# 或者: from cheroot.wsgi import Server [as 别名]
def _handle(self, environ):
        path = environ['bottle.raw_path'] = environ['PATH_INFO']
        if py3k:
            environ['PATH_INFO'] = path.encode('latin1').decode('utf8', 'ignore')

        environ['bottle.app'] = self
        request.bind(environ)
        response.bind()

        try:
            while True: # Remove in 0.14 together with RouteReset
                out = None
                try:
                    self.trigger_hook('before_request')
                    route, args = self.router.match(environ)
                    environ['route.handle'] = route
                    environ['bottle.route'] = route
                    environ['route.url_args'] = args
                    out = route.call(**args)
                    break
                except HTTPResponse as E:
                    out = E
                    break
                except RouteReset:
                    depr(0, 13, "RouteReset exception deprecated",
                                "Call route.call() after route.reset() and "
                                "return the result.")
                    route.reset()
                    continue
                finally:
                    if isinstance(out, HTTPResponse):
                        out.apply(response)
                    try:
                        self.trigger_hook('after_request')
                    except HTTPResponse as E:
                        out = E
                        out.apply(response)
        except (KeyboardInterrupt, SystemExit, MemoryError):
            raise
        except Exception as E:
            if not self.catchall: raise
            stacktrace = format_exc()
            environ['wsgi.errors'].write(stacktrace)
            environ['wsgi.errors'].flush()
            out = HTTPError(500, "Internal Server Error", E, stacktrace)
            out.apply(response)

        return out 
开发者ID:brycesub,项目名称:silvia-pi,代码行数:50,代码来源:bottle.py


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