本文整理汇总了Python中wsgiref.simple_server.WSGIServer.set_app方法的典型用法代码示例。如果您正苦于以下问题:Python WSGIServer.set_app方法的具体用法?Python WSGIServer.set_app怎么用?Python WSGIServer.set_app使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wsgiref.simple_server.WSGIServer
的用法示例。
在下文中一共展示了WSGIServer.set_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runserver
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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()
示例2: start_wsgi_server
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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)
示例3: run_wsgi
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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: serve
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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()
示例5: run
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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()
示例6: run
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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()
示例7: serve
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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()
示例8: run
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
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()
示例9: start_simple
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
def start_simple(filename, hostname, port):
"""
Start a wsgiref.simple_server to run our app.
Provides the simplest base for testing, debugging
and development.
XXX no longer used
"""
os.environ = {}
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
hostname = config["server_host"]["host"]
port = int(config["server_host"]["port"])
httpd = WSGIServer((hostname, port), WSGIRequestHandler)
httpd.set_app(load_app())
print >>sys.stderr, "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
httpd.serve_forever()
示例10: GaeTestServer
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
class GaeTestServer(object):
def __init__(self):
self.sdk_path = resolve_sdk_path()
print 'python sdk found', self.sdk_path
sys.path.insert(0, self.sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
sys.path.insert(0, 'src')
self.testbed = None
self.httpd = None
def boot_gae(self):
from google.appengine.api import memcache
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from google.appengine.datastore import datastore_stub_util
self.testbed = testbed.Testbed()
self.testbed.activate()
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
self.testbed.init_memcache_stub()
def boot_web(self, port, app):
self.port = port
self.httpd = WSGIServer(('localhost', port), WSGIRequestHandler)
self.httpd.set_app(app)
def server_forever_background(self):
self.thread = threading.Thread(target=self.httpd.serve_forever)
self.thread.start()
def server_forever(self):
self.httpd.serve_forever()
def shutdown(self):
if self.testbed:
self.testbed.deactivate()
if self.httpd:
self.httpd.shutdown()
self.httpd = None
示例11: ThreadedAmfServer
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
class ThreadedAmfServer(object):
"""
Threaded WSGI server that doesn't block the Swing GUI.
"""
def __init__(self, host, port, serviceName):
services = {serviceName: self.echo}
gw = WSGIGateway(services, logger=logging)
self.httpd = WSGIServer((host, port),
ServerRequestLogger)
self.httpd.set_app(gw)
def start(self):
"""
Start the server.
"""
class WSGIThread(lang.Runnable):
"""
Create a thread for the server.
"""
def run(this):
try:
self.httpd.serve_forever()
except lang.InterruptedException:
return
self.thread = lang.Thread(WSGIThread())
self.thread.start()
def stop(self):
"""
Stop the server.
"""
self.thread = None
def echo(self, data):
"""
Just return data back to the client.
"""
return data
示例12: _HTTPServer
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
class _HTTPServer(bottle.ServerAdapter):
"""
Reimplement bottle's WSGIRefServer. Override the request handler class and
add a stop() method for cleanly shutting down the server.
"""
srv = None
app = None
def run(self, handler):
# Handle the TIME_WAIT state for quick server restarts
WSGIServer.allow_reuse_address = 1
# Create the server and start it
self.srv = WSGIServer((self.host, self.port), _HTTPRequestHandler)
self.srv.set_app(self.app)
try:
self.srv.serve_forever()
finally:
self.srv.server_close()
def stop(self):
if self.srv:
self.srv.shutdown()
示例13: start_response
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
ret = tools.sparql_post(env)
elif path[0].lower() == 'submit':
ret = tools.submit(env)
elif env['REQUEST_METHOD'] == 'PUT':
if path[0].lower() == 'submit':
ret = tools.submit(env)
elif env['REQUEST_METHOD'] == 'DELETE':
# Not supported until authentication gets added TODO
pass
else:
# Unsupported as yet
pass
status, headers, content = ret
start_response(status, headers)
return content
if __name__ == '__main__':
if 'REQUEST_METHOD' in os.environ:
from wsgiref.handlers import BaseCGIHandler
BaseCGIHandler(sys.stdin, sys.stdout, sys.stderr, os.environ).run(run)
else:
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
httpd = WSGIServer(('', config.port), WSGIRequestHandler)
httpd.set_app(run)
print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
httpd.serve_forever()
示例14: server
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
def server(cls):
server = WSGIServer(('localhost', 8999), WsgiHandler)
server.set_app(cls.wsgi_app)
server.serve_forever()
示例15: run
# 需要导入模块: from wsgiref.simple_server import WSGIServer [as 别名]
# 或者: from wsgiref.simple_server.WSGIServer import set_app [as 别名]
def run(app):
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
httpd = WSGIServer(('127.0.0.1', 8080), WSGIRequestHandler)
httpd.set_app(app)
print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname()
httpd.serve_forever()