本文整理匯總了Python中django.core.handlers.wsgi.get_path_info方法的典型用法代碼示例。如果您正苦於以下問題:Python wsgi.get_path_info方法的具體用法?Python wsgi.get_path_info怎麽用?Python wsgi.get_path_info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.handlers.wsgi
的用法示例。
在下文中一共展示了wsgi.get_path_info方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __call__
# 需要導入模塊: from django.core.handlers import wsgi [as 別名]
# 或者: from django.core.handlers.wsgi import get_path_info [as 別名]
def __call__(self, environ, start_response):
if not self._should_handle(get_path_info(environ)):
return self.application(environ, start_response)
return super(FSFilesHandler, self).__call__(environ, start_response)
示例2: __call__
# 需要導入模塊: from django.core.handlers import wsgi [as 別名]
# 或者: from django.core.handlers.wsgi import get_path_info [as 別名]
def __call__(self, environ, start_response):
if not self._should_handle(get_path_info(environ)):
return self.application(environ, start_response)
return super(StaticFilesHandler, self).__call__(environ, start_response)
示例3: __call__
# 需要導入模塊: from django.core.handlers import wsgi [as 別名]
# 或者: from django.core.handlers.wsgi import get_path_info [as 別名]
def __call__(self, environ, start_response):
if not self._should_handle(get_path_info(environ)):
return self.application(environ, start_response)
return super().__call__(environ, start_response)
示例4: distributed_sqlite
# 需要導入模塊: from django.core.handlers import wsgi [as 別名]
# 或者: from django.core.handlers.wsgi import get_path_info [as 別名]
def distributed_sqlite(environ, start_response):
"""
Custom WSGI application meant to work with ara.server.db.backends.distributed_sqlite
in order to dynamically load different databases at runtime.
"""
# This endpoint is read only, do not accept write requests.
if environ["REQUEST_METHOD"] not in ["GET", "HEAD", "OPTIONS"]:
handle_405(start_response)
script_name = get_script_name(environ)
path_info = get_path_info(environ)
from django.conf import settings
# The root under which database files are expected
root = settings.DISTRIBUTED_SQLITE_ROOT
# The prefix after which everything should be delegated (ex: /ara-report)
prefix = settings.DISTRIBUTED_SQLITE_PREFIX
# Static assets should always be served by the regular app
if path_info.startswith(settings.STATIC_URL):
return application(environ, start_response)
if prefix not in path_info:
logger.warn("Ignoring request: URL does not contain delegated prefix (%s)" % prefix)
return handle_404(start_response)
# Slice path_info up until after the prefix to obtain the requested directory
i = path_info.find(prefix) + len(prefix)
fs_path = path_info[:i]
# Make sure we aren't escaping outside the root and the directory exists
db_dir = os.path.abspath(os.path.join(root, fs_path.lstrip("/")))
if not db_dir.startswith(root):
logger.warn("Ignoring request: path is outside the root (%s)" % db_dir)
return handle_404(start_response)
elif not os.path.exists(db_dir):
logger.warn("Ignoring request: database directory not found (%s)" % db_dir)
return handle_404(start_response)
# Find the database file and make sure it exists
db_file = os.path.join(db_dir, "ansible.sqlite")
if not os.path.exists(db_file):
logger.warn("Ignoring request: database file not found (%s)" % db_file)
return handle_404(start_response)
# Tell Django about the new URLs it should be using
environ["SCRIPT_NAME"] = script_name + fs_path
environ["PATH_INFO"] = path_info[len(fs_path) :] # noqa: E203
# Store the path of the database in a thread so the distributed_sqlite
# database backend can retrieve it.
from ara.server.db.backends.distributed_sqlite.base import local_storage
local_storage.db_path = db_file
try:
return application(environ, start_response)
finally:
del local_storage.db_path