當前位置: 首頁>>代碼示例>>Python>>正文


Python simple_server.WSGIServer方法代碼示例

本文整理匯總了Python中wsgiref.simple_server.WSGIServer方法的典型用法代碼示例。如果您正苦於以下問題:Python simple_server.WSGIServer方法的具體用法?Python simple_server.WSGIServer怎麽用?Python simple_server.WSGIServer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wsgiref.simple_server的用法示例。


在下文中一共展示了simple_server.WSGIServer方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
    server_address = (addr, port)
    if threading:
        httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {})
    else:
        httpd_cls = WSGIServer
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
    if threading:
        # ThreadingMixIn.daemon_threads indicates how threads will behave on an
        # abrupt shutdown; like quitting the server by the user or restarting
        # by the auto-reloader. True means the server will not wait for thread
        # termination before it quits. This will make auto-reloader faster
        # and will prevent the need to kill the server manually if a thread
        # isn't terminating correctly.
        httpd.daemon_threads = True
    httpd.set_app(wsgi_handler)
    httpd.serve_forever() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:basehttp.py

示例2: run

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [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

示例3: test_bytes_validation

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def test_bytes_validation(self):
        def app(e, s):
            s("200 OK", [
                ("Content-Type", "text/plain; charset=utf-8"),
                ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"),
                ])
            return [b"data"]
        out, err = run_amock(validator(app))
        self.assertTrue(err.endswith('"GET / HTTP/1.0" 200 4\n'))
        ver = sys.version.split()[0].encode('ascii')
        py  = python_implementation().encode('ascii')
        pyver = py + b"/" + ver
        self.assertEqual(
                b"HTTP/1.0 200 OK\r\n"
                b"Server: WSGIServer/0.2 "+ pyver + b"\r\n"
                b"Content-Type: text/plain; charset=utf-8\r\n"
                b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n"
                b"\r\n"
                b"data",
                out) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:test_wsgiref.py

示例4: run

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def run(self, app):
        from wsgiref.simple_server import WSGIRequestHandler, WSGIServer
        from wsgiref.simple_server import make_server

        class FixedHandler(WSGIRequestHandler):
            def address_string(self):
                return self.client_address[0]

            parent = self

            def log_request(self, *args, **kw):
                if not self.parent.quiet:
                    return WSGIRequestHandler.log_request(self, *args, **kw)

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

        self.srv = make_server(self.host, self.port, app, server_cls, handler_cls)
        thread = Thread(target=self.srv.serve_forever)
        thread.daemon = True
        thread.start()
        self._thread = thread
        self.srv.wait = self.wait
        return self.srv 
開發者ID:box,項目名稱:box-python-sdk,代碼行數:26,代碼來源:http_utils.py

示例5: __init__

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [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

示例6: __init__

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def __init__(self, *args, **kwargs):
        if kwargs.pop('ipv6', False):
            self.address_family = socket.AF_INET6
        super(WSGIServer, self).__init__(*args, **kwargs) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:6,代碼來源:basehttp.py

示例7: server_bind

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def server_bind(self):
        """Override server_bind to store the server name."""
        super(WSGIServer, self).server_bind()
        self.setup_environ() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:6,代碼來源:basehttp.py

示例8: handle_error

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def handle_error(self, request, client_address):
        if is_broken_pipe_error():
            sys.stderr.write("- Broken pipe from %s\n" % (client_address,))
        else:
            super(WSGIServer, self).handle_error(request, client_address)


# Inheriting from object required on Python 2. 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:basehttp.py

示例9: check_hello

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def check_hello(self, out, has_length=True):
        self.assertEqual(out,
            "HTTP/1.0 200 OK\r\n"
            "Server: WSGIServer/0.1 Python/"+sys.version.split()[0]+"\r\n"
            "Content-Type: text/plain\r\n"
            "Date: Mon, 05 Jun 2006 18:49:54 GMT\r\n" +
            (has_length and  "Content-Length: 13\r\n" or "") +
            "\r\n"
            "Hello, world!"
        ) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_wsgiref.py

示例10: run

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def run(self, handler):  # pragma: no cover
        import flup.server.fcgi
        self.options.setdefault('bindAddress', (self.host, self.port))
        flup.server.fcgi.WSGIServer(handler, **self.options).run() 
開發者ID:brycesub,項目名稱:silvia-pi,代碼行數:6,代碼來源:bottle.py

示例11: setup

# 需要導入模塊: from wsgiref import simple_server [as 別名]
# 或者: from wsgiref.simple_server import WSGIServer [as 別名]
def setup(cls):
        def app(env, start_response):
            result = ('Proxied: ' + env['PATH_INFO']).encode('utf-8')
            headers = [('Content-Length', str(len(result)))]
            start_response('200 OK', headers=headers)
            return iter([result])

        from wsgiprox.wsgiprox import WSGIProxMiddleware
        wsgiprox = WSGIProxMiddleware(app, '/')

        class NoLogServer(WSGIServer):
            def handle_error(self, request, client_address):
                pass

        server = make_server('localhost', 0, wsgiprox, server_class=NoLogServer)
        addr, cls.port = server.socket.getsockname()

        cls.proxies = {'https': 'localhost:' + str(cls.port),
                       'http': 'localhost:' + str(cls.port)
                      }

        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,代碼行數:33,代碼來源:test_capture_http_proxy.py


注:本文中的wsgiref.simple_server.WSGIServer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。