本文整理汇总了Python中helper.H.url_encode方法的典型用法代码示例。如果您正苦于以下问题:Python H.url_encode方法的具体用法?Python H.url_encode怎么用?Python H.url_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper.H
的用法示例。
在下文中一共展示了H.url_encode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_real_path
# 需要导入模块: from helper import H [as 别名]
# 或者: from helper.H import url_encode [as 别名]
def get_real_path(uri, server=False):
"""
Get real path
Keyword arguments:
uri -- Uri of file that needs to be mapped and located
server -- Map local path to server path
TODO: Fix mapping for root (/) and drive letters (P:/)
"""
if uri is None:
return uri
# URLdecode uri
uri = H.url_decode(uri)
# Split scheme from uri to get absolute path
try:
# scheme:///path/file => scheme, /path/file
# scheme:///C:/path/file => scheme, C:/path/file
transport, filename = uri.split(':///', 1)
except:
filename = uri
# Normalize path for comparison and remove duplicate/trailing slashes
uri = os.path.normpath(filename)
# Pattern for checking if uri is a windows path
drive_pattern = re.compile(r'^[a-zA-Z]:[\\/]')
# Append leading slash if filesystem is not Windows
if not drive_pattern.match(uri) and not os.path.isabs(uri):
uri = os.path.normpath('/' + uri)
path_mapping = S.get_config_value('path_mapping')
if isinstance(path_mapping, dict):
# Go through path mappings
for server_path, local_path in path_mapping.items():
server_path = os.path.normpath(server_path)
local_path = os.path.normpath(local_path)
# Replace path if mapping available
if server:
# Map local path to server path
if local_path in uri:
uri = uri.replace(local_path, server_path)
break
else:
# Map server path to local path
if server_path in uri:
uri = uri.replace(server_path, local_path)
break
else:
sublime.set_timeout(lambda: sublime.status_message("Xdebug: No path mapping defined, returning given path."), 0)
# Replace slashes
if not drive_pattern.match(uri):
uri = uri.replace("\\", "/")
# Append scheme
if server:
return H.url_encode("file://" + uri)
return uri