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


Python SimpleHTTPRequestHandler.translate_path方法代码示例

本文整理汇总了Python中http.server.SimpleHTTPRequestHandler.translate_path方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleHTTPRequestHandler.translate_path方法的具体用法?Python SimpleHTTPRequestHandler.translate_path怎么用?Python SimpleHTTPRequestHandler.translate_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.server.SimpleHTTPRequestHandler的用法示例。


在下文中一共展示了SimpleHTTPRequestHandler.translate_path方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: translate_path

# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import translate_path [as 别名]
	def translate_path(self, path):
		if os.path.exists(path):
			return path
		if py3:
			super(MyHTTPRequestHandler, self).translate_path(path)
		else:
			SimpleHTTPRequestHandler.translate_path(self, path)
		#half = int(len(path)/2)
		#if path.startswith("/") and len(path) % 2 == 0 and path[half:] == path[:half]:
		#	return path[half:]
		return path
开发者ID:greeny2612,项目名称:shairport-decoder,代码行数:13,代码来源:webserver.py

示例2: translate_path

# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import translate_path [as 别名]
 def translate_path(self, path_):
     """
      Now accepts local fitting paths automatically
     E.g. "/path/to/www-dir/foo.png" is valid if that folder exists.
     Now it won't change the path to "/path/to/www-dir/foo.png/path/to/www-dir/foo.png", like it did before.
     :param path: path for the webserver.
     :return:
     """
     if path.exists(path_):
         return path_
     if py3:
         super(BetterHTTPRequestHandler, self).translate_path(path_)
     else:
         SimpleHTTPRequestHandler.translate_path(self, path_)
     return path_
开发者ID:luckydonald,项目名称:luckydonald-utils,代码行数:17,代码来源:__init__.py

示例3: translate_path

# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import translate_path [as 别名]
    def translate_path(self, path):
        """
        translates 'path' (the path-part of an uri) to a file-system based
        path. 

        we assume self.server.folder to be the standard chroot-folder. if
        the user tries to access /packages, the self.server.packages folder
        is used as the chroot

        """

        chroot = self.server.chroot
        if path.find("/packages/") == 0:
            chroot = self.server.packages
            _, path = path.split("/packages/", 1)

        if not os.path.isabs(chroot):
            chroot = os.path.abspath(chroot)

        result = SimpleHTTPRequestHandler.translate_path(self, path)
        _, result = result.split(os.getcwd(), 1)
        if len(result) > 0 and result[0] == "/":
            result = result[1:]

        result = os.path.join(chroot, result)
        return result
开发者ID:pokymobo,项目名称:redomat,代码行数:28,代码来源:result_httpd.py

示例4: translate_path

# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import translate_path [as 别名]
    def translate_path(self, path):
        """Serve the pages directory instead of the current directory."""

        pages_dir = os.path.relpath(
            os.path.join(os.path.dirname(__file__), '..', '..', 'html_pages'))

        return SimpleHTTPRequestHandler.translate_path(
            self, '/' + pages_dir + path)
开发者ID:electroniceagle,项目名称:aloe_webdriver,代码行数:10,代码来源:steps.py

示例5: translate_path

# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import translate_path [as 别名]
    def translate_path(self, path):
        """Change working directory and translate path.

        Returns:
            str: Path to web server resource

        """
        os.chdir(os.path.join(os.path.dirname(__file__), "web"))
        return SimpleHTTPRequestHandler.translate_path(self, path)
开发者ID:silne30,项目名称:foxpuppet,代码行数:11,代码来源:webserver.py

示例6: translate_path

# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import translate_path [as 别名]
 def translate_path(self, path):
     path = SimpleHTTPRequestHandler.translate_path(self, path)
     print("HTTPServer: requested {}".format(path))
     if not path.startswith(path_id):
         print("HTTPServer: ignoring request for {}".format(path), file=sys.stderr)
         return "/dev/null"
     for src, dest in path_rewrites:
         if path.startswith(src):
             newpath = dest + path[len(src):]
             print("HTTPServer: rewriting {}->{}".format(path, newpath), file=sys.stderr)
             return newpath
     return path
开发者ID:radio-astro,项目名称:radiopadre,代码行数:14,代码来源:http_server.py

示例7: translate_path

# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import translate_path [as 别名]
 def translate_path(self, path):
     if path.startswith(self.node_dir):
         return self.main_dir + path
     else:
         return SimpleHTTPRequestHandler.translate_path(self, path)
开发者ID:dwillmer,项目名称:playground,代码行数:7,代码来源:server.py


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