本文整理汇总了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
示例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_
示例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
示例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)
示例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)
示例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
示例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)