本文整理汇总了Python中wsgiref.simple_server.WSGIServer类的典型用法代码示例。如果您正苦于以下问题:Python WSGIServer类的具体用法?Python WSGIServer怎么用?Python WSGIServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WSGIServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serve
def serve(site_factory, port=0, use_reloader=False, dry=False):
"""Create a new WSGI server listening on `host` and `port` for `app`"""
server = WSGIServer(('', port), WSGIRequestHandler)
server.set_app(site_factory.wsgi())
LOGGER.info('Serving on port {0}'.format(port))
if not dry: #pragma nocover
server.serve_forever()
示例2: server_close
def server_close(self):
"""
Properly initiate closing handshakes on
all websockets when the WSGI server terminates.
"""
print "closing sockets"
_WSGIServer.server_close(self)
示例3: run_wsgi
def run_wsgi(port=8123):
server = WSGIServer(('', port), WSGIRequestHandler)
app = create_publisher()
server.set_app(app)
print 'serving on %s:%d' % (interface, port,)
server.serve_forever()
示例4: start_wsgi_server
def start_wsgi_server():
from rdb.RobotDebuger import DebugSetting
app_settings = DebugSetting()
work_root = os.getcwd()
config_path = os.path.abspath(config_file)
if os.path.isfile(config_path):
app_settings.load_from_file(config_path)
init_sys_logging(app_settings)
logger = logging.getLogger("rdb.proxy")
logger.info("Loading RDB proxy at %s" % work_root)
try:
SERVER_CONTEXT = ApplicationContext(work_root, app_settings)
globals()['SERVER_CONTEXT'] = SERVER_CONTEXT
from wsgiref.simple_server import WSGIServer
server_address = (app_settings.WEB_BIND, int(app_settings.WEB_PORT))
server = WSGIServer(server_address, RDBProxyWSGIHandler)
server.set_app(wsgi_global_app)
SERVER_CONTEXT.server = server
logger.info("Serving HTTP on %s:%s..." %(app_settings.WEB_BIND,
app_settings.WEB_PORT))
server.serve_forever()
except BaseException, e:
logger.exception(e)
示例5: runserver
def runserver():
"""Lance un serveur wsgi de test, puis lui attribue l'application a
lancer avec eventuellement le chainage de middleware
"""
from pyson.middleware.error import HandleError
from pyson.middleware.log import Log
from pyson.middleware.session import Session #se wrapp automatiquement avec cookie
from pyson.middleware.force_auth import Force_auth
from pyson.middleware.http_basic import Http_basic
from pyson.middleware.formdata import Formdata
from pyson.middleware.restriction import Middle as Restriction
if os.environ.get("REQUEST_METHOD", ""):
from wsgiref.handlers import BaseCGIHandler
BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(urls.urls)
print "------------- Attention ---------------"
else:
import wsgiref
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
httpd = WSGIServer(('', int(context.conf["port"])), WSGIRequestHandler)
wrapper = Session(Formdata((Restriction(urls.urls))))
httpd.set_app(wrapper)
print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
httpd.serve_forever()
示例6: __init__
def __init__(self, machine_id, host, port, ui):
self.machine_id = machine_id
WSGIServer.__init__(self, (host, port), WSGIRequestHandler)
self.set_app(self.wsgi_app)
Partner.__init__(self, ui)
self.text_format = XMLFormat()
self.stopped = False
self.sessions = {} # {session_token: session}
self.session_token_for_user = {} # {user_name: session_token}
示例7: __init__
def __init__(self, *args, **kwargs):
WSGIServer.__init__(self, *args, **kwargs)
# NonBlockingClient -> timestamp
self.clients = {}
# Number of simultaneous clients.
self.limit = 1000
# Number of seconds before we bounce idle clients.
self.timeout = 60
self._shutdown_event = threading.Event()
示例8: run
def run():
import urls
if os.environ.get("REQUEST_METHOD", ""):
from wsgiref.handlers import BaseCGIHandler
BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(urls.urls)
else:
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
httpd = WSGIServer(('', 8000), WSGIRequestHandler)
httpd.set_app(urls.urls)
print "Serving HTTP os %s port %s ..." % httpd.socket.getsockname()
httpd.serve_forever()
示例9: __init__
def __init__(self, server_address, HandlerClass):
WSGIServer.__init__(self, server_address, HandlerClass)
if self.cert_file:
ctx = SSL.Context(SSL.SSLv3_METHOD)
ctx.use_privatekey_file(self.cert_file)
ctx.use_certificate_file(self.cert_file)
self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
self.socket_type))
self.server_bind()
self.server_activate()
示例10: server_close
def server_close(self):
"""
Properly initiate closing handshakes on
all websockets when the WSGI server terminates.
"""
if hasattr(self, 'manager'):
self.manager.close_all()
self.manager.stop()
self.manager.join()
delattr(self, 'manager')
_WSGIServer.server_close(self)
示例11: run
def run():
import urls
if os.environ.get('REQUEST_METHOD', ''):
from wsgiref.handlers import BaseCGIHandler
BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(urls.urls)
else:
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
httpd = WSGIServer(('', 8080), WSGIRequestHandler)
httpd.set_app(urls.urls)
host, port = httpd.socket.getsockname()[:2]
print 'Serving HTTP on {0} port {1}...'.format(host, port)
httpd.serve_forever()
示例12: serve
def serve(handler, host='localhost', port=8080, debug=True):
"""
Starts a developent server on the local machine. By default, the
server runs on port 8080 on localhost. You can pass in a different
hostname and/or IP using the keyword arguments.
"""
if debug:
handler = DebugMiddleware.wrap(handler)
httpd = WSGIServer((host, port), WSGIRequestHandler)
httpd.set_app(WSGIHandler(handler))
print("Development server is running at http://%s:%s/" % (host, port))
httpd.serve_forever()
示例13: get_request
def get_request(self):
socket, client_address = WSGIServer.get_request(self)
socket = ssl.wrap_socket(socket,
server_side=True,
certfile=SERVER_CERT_FILE,
keyfile=SERVER_KEY_FILE)
return socket, client_address
示例14: run
def run(selector):
"""Run the server provided by selector"""
print selector
exec "from " + selector + " import urls, port"
if os.environ.get("REQUEST_METHOD", ""):
from wsgiref.handlers import BaseCGIHandler
BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ) \
.run(urls)
else:
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
# with the code like this we are binding to no particular interface, matter?
httpd = WSGIServer(('', port), WSGIRequestHandler)
httpd.set_app(urls)
print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
httpd.serve_forever()
示例15: get_unix_request
def get_unix_request(self):
sock, _ = WSGIServer.get_request(self)
cred = sock.getsockopt(socket.SOL_SOCKET,
socket.SO_PEERCRED,
self.csize)
cred = struct.unpack('3i', cred)
ret = [sock, ['pid: %i, uid: %i, gid: %i' % cred, 0]]
return ret