当前位置: 首页>>代码示例>>Python>>正文


Python wsgi.get_path_info方法代码示例

本文整理汇总了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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:testcases.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:handlers.py

示例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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:6,代码来源:testcases.py

示例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 
开发者ID:ansible-community,项目名称:ara,代码行数:61,代码来源:wsgi.py


注:本文中的django.core.handlers.wsgi.get_path_info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。