本文整理汇总了Python中CGIHTTPServer._url_collapse_path_split方法的典型用法代码示例。如果您正苦于以下问题:Python CGIHTTPServer._url_collapse_path_split方法的具体用法?Python CGIHTTPServer._url_collapse_path_split怎么用?Python CGIHTTPServer._url_collapse_path_split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGIHTTPServer
的用法示例。
在下文中一共展示了CGIHTTPServer._url_collapse_path_split方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_url_collapse_path_split
# 需要导入模块: import CGIHTTPServer [as 别名]
# 或者: from CGIHTTPServer import _url_collapse_path_split [as 别名]
def test_url_collapse_path_split(self):
test_vectors = {
"": ("/", ""),
"..": IndexError,
"/.//..": IndexError,
"/": ("/", ""),
"//": ("/", ""),
"/\\": ("/", "\\"),
"/.//": ("/", ""),
"cgi-bin/file1.py": ("/cgi-bin", "file1.py"),
"/cgi-bin/file1.py": ("/cgi-bin", "file1.py"),
"a": ("/", "a"),
"/a": ("/", "a"),
"//a": ("/", "a"),
"./a": ("/", "a"),
"./C:/": ("/C:", ""),
"/a/b": ("/a", "b"),
"/a/b/": ("/a/b", ""),
"/a/b/c/..": ("/a/b", ""),
"/a/b/c/../d": ("/a/b", "d"),
"/a/b/c/../d/e/../f": ("/a/b/d", "f"),
"/a/b/c/../d/e/../../f": ("/a/b", "f"),
"/a/b/c/../d/e/.././././..//f": ("/a/b", "f"),
"../a/b/c/../d/e/.././././..//f": IndexError,
"/a/b/c/../d/e/../../../f": ("/a", "f"),
"/a/b/c/../d/e/../../../../f": ("/", "f"),
"/a/b/c/../d/e/../../../../../f": IndexError,
"/a/b/c/../d/e/../../../../f/..": ("/", ""),
}
for path, expected in test_vectors.iteritems():
if isinstance(expected, type) and issubclass(expected, Exception):
self.assertRaises(expected, CGIHTTPServer._url_collapse_path_split, path)
else:
actual = CGIHTTPServer._url_collapse_path_split(path)
self.assertEqual(expected, actual, msg="path = %r\nGot: %r\nWanted: %r" % (path, actual, expected))
示例2: is_cgi
# 需要导入模块: import CGIHTTPServer [as 别名]
# 或者: from CGIHTTPServer import _url_collapse_path_split [as 别名]
def is_cgi(self):
path = self.path
i = path.rfind("?")
if i >= 0:
path, query = path[:i], path[i:]
else:
query = ""
root, ext = os.path.splitext(path)
if self.is_cgi_extension(ext):
self.cgi_info = CGIHTTPServer._url_collapse_path_split(self.path)
return True
return False
示例3: is_cgi
# 需要导入模块: import CGIHTTPServer [as 别名]
# 或者: from CGIHTTPServer import _url_collapse_path_split [as 别名]
def is_cgi(self):
splitpath = CGIHTTPServer._url_collapse_path_split(self.path)
script_query = splitpath[1].split("?", 1)
if script_query[0].endswith(".py"):
if splitpath[0].startswith("/"):
# Workaround for some weirdness with how CGIHTTPServer
# computes the SCRIPT_NAME environment variable.
splitpath = list(splitpath)
splitpath[0] = ''
splitpath = tuple(splitpath)
self.cgi_info = splitpath
return True
return False
示例4: test_url_collapse_path_split
# 需要导入模块: import CGIHTTPServer [as 别名]
# 或者: from CGIHTTPServer import _url_collapse_path_split [as 别名]
def test_url_collapse_path_split(self):
test_vectors = {
'': ('/', ''),
'..': IndexError,
'/.//..': IndexError,
'/': ('/', ''),
'//': ('/', ''),
'/\\': ('/', '\\'),
'/.//': ('/', ''),
'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
'/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
'/cgi-bin/file1.py/PATH-INFO': ('/cgi-bin', 'file1.py/PATH-INFO'),
'a': ('/', 'a'),
'/a': ('/', 'a'),
'//a': ('/', 'a'),
'./a': ('/', 'a'),
'./C:/': ('/C:', ''),
'/a/b': ('/a', 'b'),
'/a/b/': ('/a/b', ''),
'/a/b/c/..': ('/a/b', ''),
'/a/b/c/../d': ('/a/b', 'd'),
'/a/b/c/../d/e/../f': ('/a/b/d', 'f'),
'/a/b/c/../d/e/../../f': ('/a/b', 'f'),
'/a/b/c/../d/e/.././././..//f': ('/a/b', 'f'),
'../a/b/c/../d/e/.././././..//f': IndexError,
'/a/b/c/../d/e/../../../f': ('/a', 'f'),
'/a/b/c/../d/e/../../../../f': ('/', 'f'),
'/a/b/c/../d/e/../../../../../f': IndexError,
'/a/b/c/../d/e/../../../../f/..': ('/', ''),
}
for path, expected in test_vectors.iteritems():
if isinstance(expected, type) and issubclass(expected, Exception):
self.assertRaises(expected,
CGIHTTPServer._url_collapse_path_split, path)
else:
actual = CGIHTTPServer._url_collapse_path_split(path)
self.assertEqual(expected, actual,
msg='path = %r\nGot: %r\nWanted: %r' %
(path, actual, expected))