本文整理汇总了Python中ZPublisher.HTTPRequest.HTTPRequest.physicalPathToVirtualPath方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPRequest.physicalPathToVirtualPath方法的具体用法?Python HTTPRequest.physicalPathToVirtualPath怎么用?Python HTTPRequest.physicalPathToVirtualPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZPublisher.HTTPRequest.HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest.physicalPathToVirtualPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _physicalPathToVirtualPath
# 需要导入模块: from ZPublisher.HTTPRequest import HTTPRequest [as 别名]
# 或者: from ZPublisher.HTTPRequest.HTTPRequest import physicalPathToVirtualPath [as 别名]
def _physicalPathToVirtualPath(self, path):
"""
Remove the path to the VirtualRoot from a physical path
and add the path to the WebSite if any
"""
if isinstance(path, str):
path = path.split( '/')
# Every Web Section acts as a mini site though layout for document editing is the root layout
#website_path = self._v_request.get(WEBSECTION_KEY, self._v_request.get(WEBSITE_KEY, None))
# Only consider Web Site for absolute_url
request = getattr(self, '_v_request', None)
if request is None: request = self._v_request = get_request()
# In ignore_layout case, we only remove empty element from path
# XXX more support required for ignore_layout?
if request.get('ignore_layout', None):
return HTTPRequest.physicalPathToVirtualPath(request, path)
website_path = request.get(WEBSITE_KEY, None)
select_language = request.get(WEBSITE_LANGUAGE_KEY, None)
if website_path:
website_path = tuple(website_path) # Make sure all path are tuples
path = tuple(path) # Make sure all path are tuples
if select_language:
website_path = website_path + (select_language,) # Add the language part
# Search for the common part index
# XXX more testing should be added to check
# if the URL is the kind of URL which is a Web Site
common_index = 0
i = 0
path_len = len(path)
for name in website_path:
if i >= path_len:
break
if path[i] == name:
common_index = i
i += 1
# Insert the web site path after the common part of the path
if path_len > common_index + 1:
path = website_path + path[common_index + 1:]
rpp = request.other.get('VirtualRootPhysicalPath', ('', ))
i = 0
for name in rpp[:len(path)]:
if path[i] == name:
i = i + 1
else:
break
#if self._v_request.has_key(DOCUMENT_NAME_KEY):
# # Replace the last id of the path with the name which
# # was used to lookup the document
# path = path[:-1] + (self._v_request[DOCUMENT_NAME_KEY],)
return path[i:]