本文整理汇总了Python中tornado.wsgi方法的典型用法代码示例。如果您正苦于以下问题:Python tornado.wsgi方法的具体用法?Python tornado.wsgi怎么用?Python tornado.wsgi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado
的用法示例。
在下文中一共展示了tornado.wsgi方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClass
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def setUpClass(self):
from pyspider.libs import wsgi_xmlrpc
def test_1():
return 'test_1'
class Test2(object):
def test_3(self, obj):
return obj
test = Test2()
application = wsgi_xmlrpc.WSGIXMLRPCApplication()
application.register_instance(Test2())
application.register_function(test_1)
container = tornado.wsgi.WSGIContainer(application)
self.io_loop = tornado.ioloop.IOLoop.current()
http_server = tornado.httpserver.HTTPServer(container, io_loop=self.io_loop)
http_server.listen(3423)
self.thread = utils.run_in_thread(self.io_loop.start)
示例2: access_validation_factory
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [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
示例3: __call__
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def __call__(self, environ, start_response):
method = environ["REQUEST_METHOD"]
uri = urllib_parse.quote(from_wsgi_str(environ.get("SCRIPT_NAME", "")))
uri += urllib_parse.quote(from_wsgi_str(environ.get("PATH_INFO", "")))
if environ.get("QUERY_STRING"):
uri += "?" + environ["QUERY_STRING"]
headers = httputil.HTTPHeaders()
if environ.get("CONTENT_TYPE"):
headers["Content-Type"] = environ["CONTENT_TYPE"]
if environ.get("CONTENT_LENGTH"):
headers["Content-Length"] = environ["CONTENT_LENGTH"]
for key in environ:
if key.startswith("HTTP_"):
headers[key[5:].replace("_", "-")] = environ[key]
if headers.get("Content-Length"):
body = environ["wsgi.input"].read(
int(headers["Content-Length"]))
else:
body = b""
protocol = environ["wsgi.url_scheme"]
remote_ip = environ.get("REMOTE_ADDR", "")
if environ.get("HTTP_HOST"):
host = environ["HTTP_HOST"]
else:
host = environ["SERVER_NAME"]
connection = _WSGIConnection(method, start_response,
_WSGIRequestContext(remote_ip, protocol))
request = httputil.HTTPServerRequest(
method, uri, "HTTP/1.1", headers=headers, body=body,
host=host, connection=connection)
request._parse_body()
self.application(request)
if connection._error:
raise connection._error
if not connection._finished:
raise Exception("request did not finish synchronously")
return connection._write_buffer
示例4: environ
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def environ(request):
"""Converts a `tornado.httputil.HTTPServerRequest` to a WSGI environment.
"""
hostport = request.host.split(":")
if len(hostport) == 2:
host = hostport[0]
port = int(hostport[1])
else:
host = request.host
port = 443 if request.protocol == "https" else 80
environ = {
"REQUEST_METHOD": request.method,
"SCRIPT_NAME": "",
"PATH_INFO": to_wsgi_str(escape.url_unescape(
request.path, encoding=None, plus=False)),
"QUERY_STRING": request.query,
"REMOTE_ADDR": request.remote_ip,
"SERVER_NAME": host,
"SERVER_PORT": str(port),
"SERVER_PROTOCOL": request.version,
"wsgi.version": (1, 0),
"wsgi.url_scheme": request.protocol,
"wsgi.input": BytesIO(escape.utf8(request.body)),
"wsgi.errors": sys.stderr,
"wsgi.multithread": False,
"wsgi.multiprocess": True,
"wsgi.run_once": False,
}
if "Content-Type" in request.headers:
environ["CONTENT_TYPE"] = request.headers.pop("Content-Type")
if "Content-Length" in request.headers:
environ["CONTENT_LENGTH"] = request.headers.pop("Content-Length")
for key, value in request.headers.items():
environ["HTTP_" + key.replace("-", "_").upper()] = value
return environ
示例5: __init__
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def __init__(self, handlers=None, default_host="", **settings):
web.Application.__init__(self, handlers, default_host, transforms=[],
wsgi=True, **settings)
示例6: environ
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def environ(request):
"""Converts a `tornado.httpserver.HTTPRequest` to a WSGI environment.
"""
hostport = request.host.split(":")
if len(hostport) == 2:
host = hostport[0]
port = int(hostport[1])
else:
host = request.host
port = 443 if request.protocol == "https" else 80
environ = {
"REQUEST_METHOD": request.method,
"SCRIPT_NAME": "",
"PATH_INFO": to_wsgi_str(escape.url_unescape(
request.path, encoding=None, plus=False)),
"QUERY_STRING": request.query,
"REMOTE_ADDR": request.remote_ip,
"SERVER_NAME": host,
"SERVER_PORT": str(port),
"SERVER_PROTOCOL": request.version,
"wsgi.version": (1, 0),
"wsgi.url_scheme": request.protocol,
"wsgi.input": BytesIO(escape.utf8(request.body)),
"wsgi.errors": sys.stderr,
"wsgi.multithread": False,
"wsgi.multiprocess": True,
"wsgi.run_once": False,
}
if "Content-Type" in request.headers:
environ["CONTENT_TYPE"] = request.headers.pop("Content-Type")
if "Content-Length" in request.headers:
environ["CONTENT_LENGTH"] = request.headers.pop("Content-Length")
for key, value in request.headers.items():
environ["HTTP_" + key.replace("-", "_").upper()] = value
return environ
示例7: environ
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def environ(request):
"""Converts a `tornado.httpserver.HTTPRequest` to a WSGI environment.
"""
hostport = request.host.split(":")
if len(hostport) == 2:
host = hostport[0]
port = int(hostport[1])
else:
host = request.host
port = 443 if request.protocol == "https" else 80
environ = {
"REQUEST_METHOD": request.method,
"SCRIPT_NAME": "",
"PATH_INFO": urllib.unquote(request.path),
"QUERY_STRING": request.query,
"REMOTE_ADDR": request.remote_ip,
"SERVER_NAME": host,
"SERVER_PORT": str(port),
"SERVER_PROTOCOL": request.version,
"wsgi.version": (1, 0),
"wsgi.url_scheme": request.protocol,
"wsgi.input": BytesIO(escape.utf8(request.body)),
"wsgi.errors": sys.stderr,
"wsgi.multithread": False,
"wsgi.multiprocess": True,
"wsgi.run_once": False,
}
if "Content-Type" in request.headers:
environ["CONTENT_TYPE"] = request.headers.pop("Content-Type")
if "Content-Length" in request.headers:
environ["CONTENT_LENGTH"] = request.headers.pop("Content-Length")
for key, value in request.headers.iteritems():
environ["HTTP_" + key.replace("-", "_").upper()] = value
return environ
示例8: make_wsgi_app
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def make_wsgi_app():
web_app = make_web_app()
return tornado.wsgi.WSGIAdapter(web_app)
示例9: run_wsgi
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def run_wsgi(wsgi_app, port):
"""Runs wsgi (Flask) app using tornado web server."""
container = tornado.wsgi.WSGIContainer(wsgi_app)
app = tornado.web.Application([
(r'.*', tornado.web.FallbackHandler, dict(fallback=container)),
])
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(port)
tornado.ioloop.IOLoop.instance().start()
示例10: run_wsgi_unix
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def run_wsgi_unix(wsgi_app, socket):
"""Runs wsgi (Flask) app using tornado unixsocket web server."""
container = tornado.wsgi.WSGIContainer(wsgi_app)
app = tornado.web.Application([
(r'.*', tornado.web.FallbackHandler, dict(fallback=container)),
])
http_server = tornado.httpserver.HTTPServer(app)
unix_socket = tornado.netutil.bind_unix_socket(socket)
http_server.add_socket(unix_socket)
tornado.ioloop.IOLoop.instance().start()
示例11: run
# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import wsgi [as 别名]
def run(self):
if not self._allowRoot:
self._checkForRoot()
global userManager
global eventManager
global loginManager
global debug
global softwareManager
global discoveryManager
global VERSION
global UI_API_KEY
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, FallbackHandler
from astroprint.printfiles.watchdogs import UploadCleanupWatchdogHandler
debug = self._debug
# first initialize the settings singleton and make sure it uses given configfile and basedir if available
self._initSettings(self._configfile, self._basedir)
s = settings()
if not s.getBoolean(['api', 'regenerate']) and s.getString(['api', 'key']):
UI_API_KEY = s.getString(['api', 'key'])
else:
UI_API_KEY = ''.join('%02X' % ord(z) for z in uuid.uuid4().bytes)
# then initialize logging
self._initLogging(self._debug, self._logConf)
logger = logging.getLogger(__name__)
if s.getBoolean(["accessControl", "enabled"]):
userManagerName = s.get(["accessControl", "userManager"])
try:
clazz = util.getClass(userManagerName)
userManager = clazz()
except AttributeError, e:
logger.exception("Could not instantiate user manager %s, will run with accessControl disabled!" % userManagerName)