當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。