本文整理汇总了Python中tornado.wsgi.WSGIContainer方法的典型用法代码示例。如果您正苦于以下问题:Python wsgi.WSGIContainer方法的具体用法?Python wsgi.WSGIContainer怎么用?Python wsgi.WSGIContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.wsgi
的用法示例。
在下文中一共展示了wsgi.WSGIContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_app
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def get_app(self):
class HelloHandler(RequestHandler):
def get(self):
self.write("Hello world!")
class PathQuotingHandler(RequestHandler):
def get(self, path):
self.write(path)
# It would be better to run the wsgiref server implementation in
# another thread instead of using our own WSGIContainer, but this
# fits better in our async testing framework and the wsgiref
# validator should keep us honest
return WSGIContainer(validator(WSGIApplication([
("/", HelloHandler),
("/path/(.*)", PathQuotingHandler),
("/typecheck", TypeCheckHandler),
])))
示例2: tornadoserver
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def tornadoserver():
setup_logging('tornadoserver')
app = create_app(parse_options())
fsh_folder = app.blueprints['flask_statics_helper'].static_folder
log_messages(app, OPTIONS['--port'], fsh_folder)
# Setup the application.
container = wsgi.WSGIContainer(app)
application = web.Application([
(r'/static/flask_statics_helper/(.*)', web.StaticFileHandler, dict(path=fsh_folder)),
(r'/(favicon\.ico)', web.StaticFileHandler, dict(path=app.static_folder)),
(r'/static/(.*)', web.StaticFileHandler, dict(path=app.static_folder)),
(r'.*', web.FallbackHandler, dict(fallback=container))
]) # From http://maxburstein.com/blog/django-static-files-heroku/
http_server = httpserver.HTTPServer(application)
http_server.bind(OPTIONS['--port'])
# Start the server.
http_server.start(0) # Forks multiple sub-processes
ioloop.IOLoop.instance().start()
示例3: get_app
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def get_app(self):
wsgi_app = WSGIContainer(self.wsgi_app)
class Handler(RequestHandler):
def get(self, *args, **kwargs):
self.finish(self.reverse_url("tornado"))
return RuleRouter(
[
(
PathMatches("/tornado.*"),
Application([(r"/tornado/test", Handler, {}, "tornado")]),
),
(PathMatches("/wsgi"), wsgi_app),
]
)
示例4: get_app
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def get_app(self):
class HelloHandler(RequestHandler):
def get(self):
self.write("Hello world!")
class PathQuotingHandler(RequestHandler):
def get(self, path):
self.write(path)
# It would be better to run the wsgiref server implementation in
# another thread instead of using our own WSGIContainer, but this
# fits better in our async testing framework and the wsgiref
# validator should keep us honest
with ignore_deprecation():
return WSGIContainer(validator(WSGIAdapter(
Application([
("/", HelloHandler),
("/path/(.*)", PathQuotingHandler),
("/typecheck", TypeCheckHandler),
]))))
示例5: get_app
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def get_app(self):
class HelloHandler(RequestHandler):
def get(self):
self.write("Hello world!")
class PathQuotingHandler(RequestHandler):
def get(self, path):
self.write(path)
# It would be better to run the wsgiref server implementation in
# another thread instead of using our own WSGIContainer, but this
# fits better in our async testing framework and the wsgiref
# validator should keep us honest
return WSGIContainer(validator(WSGIApplication([
("/", HelloHandler),
("/path/(.*)", PathQuotingHandler),
("/typecheck", TypeCheckHandler),
])))
示例6: access_validation_factory
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def access_validation_factory(validator):
"""
Creates an access validation wrapper using the supplied validator.
:param validator: the access validator to use inside the validation wrapper
:return: an access validation wrapper taking a request as parameter and performing the request validation
"""
def f(request):
"""
Creates a custom wsgi and Flask request context in order to be able to process user information
stored in the current session.
:param request: The Tornado request for which to create the environment and context
"""
wsgi_environ = tornado.wsgi.WSGIContainer.environ(request)
with app.request_context(wsgi_environ):
app.session_interface.open_session(app, request)
loginManager.reload_user()
validator(request)
return f
示例7: run
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def run(self, quiet=None, server=''):
""" Start the tornado server, run forever.
'quiet' and 'server' arguments are no longer used, they are keep only for backward compatibility
"""
try:
loop = IOLoop()
http_server = HTTPServer(WSGIContainer(self.app))
http_server.listen(self.port)
loop.start()
except socket.error as serr:
# Re raise the socket error if not "[Errno 98] Address already in use"
if serr.errno != errno.EADDRINUSE:
raise serr
else:
logger.warning("""The webserver port {} is already used.
The SnapRobotServer is maybe already run or another software use this port.""".format(self.port))
示例8: serve
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def serve(get_vec, port):
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
CORS(app)
@app.route('/api', methods=['GET'])
def api():
query = request.args['query']
start = time()
out = get_vec(query)
end = time()
print('latency: %dms' % int((end - start) * 1000))
return jsonify(out)
print('Starting server at %d' % port)
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(port)
IOLoop.instance().start()
示例9: build_webapp_thread
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def build_webapp_thread(self, port=constants.DEFAULT_WEB_UI_PORT):
app.session = self
http_server = HTTPServer(WSGIContainer(app))
while True:
try:
http_server.listen(port)
except socket.error as exc:
# Only handle "Address already in use"
if exc.errno != errno.EADDRINUSE:
raise
port += 1
else:
self._fuzz_data_logger.log_info("Web interface can be found at http://localhost:%d" % port)
break
flask_thread = threading.Thread(target=IOLoop.instance().start)
flask_thread.daemon = True
return flask_thread
示例10: test_types
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def test_types(self):
headers = {"Cookie": "foo=bar"}
response = self.fetch("/typecheck?foo=bar", headers=headers)
data = json_decode(response.body)
self.assertEqual(data, {})
response = self.fetch("/typecheck", method="POST", body="foo=bar", headers=headers)
data = json_decode(response.body)
self.assertEqual(data, {})
# This is kind of hacky, but run some of the HTTPServer tests through
# WSGIContainer and WSGIApplication to make sure everything survives
# repeated disassembly and reassembly.
示例11: wrap_web_tests_application
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def wrap_web_tests_application():
result = {}
for cls in web_test.wsgi_safe_tests:
class WSGIApplicationWrappedTest(cls):
def get_app(self):
self.app = WSGIApplication(self.get_handlers(),
**self.get_app_kwargs())
return WSGIContainer(validator(self.app))
result["WSGIApplication_" + cls.__name__] = WSGIApplicationWrappedTest
return result
示例12: start
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def start(self):
# get properties
flaskHost = Configuration.getFlaskHost()
flaskPort = Configuration.getFlaskPort()
flaskDebug = Configuration.getFlaskDebug()
# logging
if Configuration.getLogging():
logfile = Configuration.getLogfile()
pathToLog = logfile.rsplit('/', 1)[0]
if not os.path.exists(pathToLog):
os.makedirs(pathToLog)
maxLogSize = Configuration.getMaxLogSize()
backlog = Configuration.getBacklog()
file_handler = RotatingFileHandler(logfile, maxBytes=maxLogSize, backupCount=backlog)
file_handler.setLevel(logging.ERROR)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
self.app.logger.addHandler(file_handler)
if flaskDebug:
# start debug flask server
self.app.run(host=flaskHost, port=flaskPort, debug=flaskDebug)
else:
# start asynchronous server using tornado wrapper for flask
# ssl connection
print("Server starting...")
if Configuration.useSSL():
ssl_options = {"certfile": os.path.join(_runPath, "../", Configuration.getSSLCert()),
"keyfile": os.path.join(_runPath, "../", Configuration.getSSLKey())}
else:
ssl_options = None
signal.signal(signal.SIGTERM, self.sig_handler)
signal.signal(signal.SIGINT, self.sig_handler)
self.http_server = HTTPServer(WSGIContainer(self.app), ssl_options=ssl_options)
self.http_server.bind(flaskPort, address=flaskHost)
self.http_server.start(0) # Forks multiple sub-processes
IOLoop.instance().start()
示例13: _start_tornado
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def _start_tornado(self):
if os.name == 'nt' and sys.version_info > (3, 7):
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
log.info('Starting Tornado server on %s', _readable_listen_address(self.listen_address, self.listen_port))
# Max Buffersize set to 200MB )
http_server = HTTPServer(WSGIContainer(self.app),
max_buffer_size=209700000,
ssl_options=self.ssl_args)
http_server.listen(self.listen_port, self.listen_address)
self.wsgiserver = IOLoop.current()
self.wsgiserver.start()
# wait for stop signal
self.wsgiserver.close(True)
示例14: get_app
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def get_app(self):
return WSGIContainer(validator(self.wsgi_app))
示例15: wrap_web_tests
# 需要导入模块: from tornado import wsgi [as 别名]
# 或者: from tornado.wsgi import WSGIContainer [as 别名]
def wrap_web_tests():
result = {}
for cls in web_test.wsgi_safe_tests:
class WSGIWrappedTest(cls):
def get_app(self):
self.app = WSGIApplication(self.get_handlers(),
**self.get_app_kwargs())
return WSGIContainer(validator(self.app))
result["WSGIWrapped_" + cls.__name__] = WSGIWrappedTest
return result