本文整理汇总了Python中django.core.handlers.wsgi.WSGIHandler方法的典型用法代码示例。如果您正苦于以下问题:Python wsgi.WSGIHandler方法的具体用法?Python wsgi.WSGIHandler怎么用?Python wsgi.WSGIHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.handlers.wsgi
的用法示例。
在下文中一共展示了wsgi.WSGIHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def run(self):
"""
Set up the live server and databases, and then loop over handling
HTTP requests.
"""
if self.connections_override:
# Override this thread's database connections with the ones
# provided by the main thread.
for alias, conn in self.connections_override.items():
connections[alias] = conn
try:
# Create the handler for serving static and media files
handler = self.static_handler(_MediaFilesHandler(WSGIHandler()))
self.httpd = self._create_server()
# If binding to port zero, assign the port allocated by the OS.
if self.port == 0:
self.port = self.httpd.server_address[1]
self.httpd.set_app(handler)
self.is_ready.set()
self.httpd.serve_forever()
except Exception as e:
self.error = e
self.is_ready.set()
finally:
connections.close_all()
示例2: run
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def run(self):
"""
Set up the live server and databases, and then loop over handling
HTTP requests.
"""
try:
# Create the handler for serving static and media files
self.httpd = self._create_server()
# If binding to port zero, assign the port allocated by the OS.
if self.port == 0:
self.port = self.httpd.server_address[1]
self.httpd.set_app(WSGIHandler())
self.is_ready.set()
self.httpd.serve_forever()
except Exception as e:
self.error = e
self.is_ready.set()
示例3: run
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def run(self):
"""
Sets up the live server and databases, and then loops over handling
http requests.
"""
if self.connections_override:
# Override this thread's database connections with the ones
# provided by the main thread.
for alias, conn in self.connections_override.items():
connections[alias] = conn
try:
# Create the handler for serving static and media files
handler = self.static_handler(_MediaFilesHandler(WSGIHandler()))
self.httpd = self._create_server()
# If binding to port zero, assign the port allocated by the OS.
if self.port == 0:
self.port = self.httpd.server_address[1]
self.httpd.set_app(handler)
self.is_ready.set()
self.httpd.serve_forever()
except Exception as e:
self.error = e
self.is_ready.set()
finally:
connections.close_all()
示例4: test_get_response_sends_signal_on_serialization_failures
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def test_get_response_sends_signal_on_serialization_failures(self):
get_response = self.patch(WSGIHandler, "get_response")
get_response.side_effect = (
lambda request: self.cause_serialization_failure()
)
send_request_exception = self.patch_autospec(
signals.got_request_exception, "send"
)
handler = views.WebApplicationHandler(1)
request = make_request()
request.path = factory.make_name("path")
handler.get_response(request)
self.assertThat(
send_request_exception,
MockCalledOnceWith(
sender=views.WebApplicationHandler, request=request
),
)
示例5: test_get_response_sends_signal_on_deadlock_failures
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def test_get_response_sends_signal_on_deadlock_failures(self):
get_response = self.patch(WSGIHandler, "get_response")
get_response.side_effect = make_deadlock_failure()
send_request_exception = self.patch_autospec(
signals.got_request_exception, "send"
)
handler = views.WebApplicationHandler(1)
request = make_request()
request.path = factory.make_name("path")
handler.get_response(request)
self.assertThat(
send_request_exception,
MockCalledOnceWith(
sender=views.WebApplicationHandler, request=request
),
)
示例6: test_get_response_is_in_retry_context_in_transaction
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def test_get_response_is_in_retry_context_in_transaction(self):
handler = views.WebApplicationHandler(2)
def check_retry_context_active(request):
self.assertThat(retry_context.active, Is(True))
get_response = self.patch(WSGIHandler, "get_response")
get_response.side_effect = check_retry_context_active
request = make_request()
request.path = factory.make_name("path")
self.assertThat(retry_context.active, Is(False))
handler.get_response(request)
self.assertThat(retry_context.active, Is(False))
self.assertThat(get_response, MockCalledOnceWith(request))
示例7: get_handler
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def get_handler(self, *args, **options):
"""
Returns the django.contrib.staticfiles handler.
"""
handler = WSGIHandler()
try:
from django.contrib.staticfiles.handlers import StaticFilesHandler
except ImportError:
return handler
use_static_handler = options.get('use_static_handler')
insecure_serving = options.get('insecure_serving', False)
if (settings.DEBUG and use_static_handler or
(use_static_handler and insecure_serving)):
handler = StaticFilesHandler(handler)
return handler
示例8: make_wsgi_application
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def make_wsgi_application():
# validate models
s = StringIO()
if get_validation_errors(s):
s.seek(0)
error = s.read()
msg = "One or more models did not validate:\n%s" % error
print(msg, file=sys.stderr)
sys.stderr.flush()
sys.exit(1)
translation.activate(settings.LANGUAGE_CODE)
if django14:
return get_internal_wsgi_application()
return WSGIHandler()
示例9: get_wsgi_application
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def get_wsgi_application():
"""
The public interface to Django's WSGI support. Should return a WSGI
callable.
Allows us to avoid making django.core.handlers.WSGIHandler public API, in
case the internal WSGI implementation changes or moves in the future.
"""
django.setup()
return WSGIHandler()
示例10: get_wsgi_application
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def get_wsgi_application():
"""
The public interface to Django's WSGI support. Should return a WSGI
callable.
Allows us to avoid making django.core.handlers.WSGIHandler public API, in
case the internal WSGI implementation changes or moves in the future.
"""
return WSGIHandler()
示例11: run
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def run(self, netloc='0.0.0.0:9090', reload=True, log=True):
"""Run the CherryPy server."""
from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler
from paste.translogger import TransLogger
url_parts = urlparse.urlsplit(netloc)
host = "0.0.0.0"
port = 9090
cherrypy.config.update({
'server.socket_host': host,
'server.socket_port': port,
'log.screen': False,
'engine.autoreload.on': reload,
'log.access_file': cherry_access_log,
'log.error_file': cherry_error_log,
})
self.cfg_assets(settings.MEDIA_URL, settings.MEDIA_ROOT)
self.cfg_assets(settings.STATIC_URL, settings.STATIC_ROOT)
self.cfg_favicon(settings.STATIC_ROOT)
app = WSGIHandler()
app = TransLogger(app, logger_name='cherrypy.access',
setup_console_handler=False)
if self.domains:
app = cherrypy.wsgi.VirtualHost(app, self.domains)
cherrypy.tree.graft(app)
cherrypy.engine.start()
示例12: run
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def run(self):
"""
Sets up the live server and databases, and then loops over handling
http requests.
"""
if self.connections_override:
# Override this thread's database connections with the ones
# provided by the main thread.
for alias, conn in self.connections_override.items():
connections[alias] = conn
try:
# Create the handler for serving static and media files
handler = self.static_handler(_MediaFilesHandler(WSGIHandler()))
# Go through the list of possible ports, hoping that we can find
# one that is free to use for the WSGI server.
for index, port in enumerate(self.possible_ports):
try:
self.httpd = self._create_server(port)
except socket.error as e:
if (index + 1 < len(self.possible_ports) and
e.errno == errno.EADDRINUSE):
# This port is already in use, so we go on and try with
# the next one in the list.
continue
else:
# Either none of the given ports are free or the error
# is something else than "Address already in use". So
# we let that error bubble up to the main thread.
raise
else:
# A free port was found.
self.port = port
break
self.httpd.set_app(handler)
self.is_ready.set()
self.httpd.serve_forever()
except Exception as e:
self.error = e
self.is_ready.set()
示例13: __init__
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def __init__(self):
self.app = WSGIHandler()
self.factory = DjangoRequestFactory()
示例14: test_assert_application
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def test_assert_application(self):
self.assertIsInstance(application, WSGIHandler)
示例15: test_data_upload_max_memory_size_exceeded
# 需要导入模块: from django.core.handlers import wsgi [as 别名]
# 或者: from django.core.handlers.wsgi import WSGIHandler [as 别名]
def test_data_upload_max_memory_size_exceeded(self):
response = WSGIHandler()(self.get_suspicious_environ(), lambda *a, **k: None)
self.assertEqual(response.status_code, 400)