本文整理汇总了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()
示例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()
示例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)
示例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
示例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)
示例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)
示例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()
示例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.
示例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!"
)
示例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()
示例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)