def relpath(self, path, start='.'): # Since os.path.relpath() calls os.path.normpath() # (see http://docs.python.org/library/os.path.html#os.path.abspath ) # it also removes trailing slashes and converts forward and backward # slashes to the preferred slash os.sep. start = self.abspath(start) path = self.abspath(path) common_root = start dot_dot = '' while not common_root == '': if path.startswith(common_root): break common_root = self.dirname(common_root) dot_dot += '..' + self.sep rel_path = path[len(common_root):] if not rel_path: return '.' if rel_path[0] == self.sep: # It is probably sufficient to remove just the first character # since os.path.normpath() collapses separators, but we use # lstrip() just to be sure. rel_path = rel_path.lstrip(self.sep) elif not common_root == '/': # We are in the case typified by the following example: # path = "/tmp/foobar", start = "/tmp/foo" -> rel_path = "bar" common_root = self.dirname(common_root) dot_dot += '..' + self.sep rel_path = path[len(common_root) + 1:] return dot_dot + rel_path
def relpath(self, path, start="."): # Since os.path.relpath() calls os.path.normpath() # (see http://docs.python.org/library/os.path.html#os.path.abspath ) # it also removes trailing slashes and converts forward and backward # slashes to the preferred slash os.sep. start = self.abspath(start) path = self.abspath(path) common_root = start dot_dot = "" while not common_root == "": if path.startswith(common_root): break common_root = self.dirname(common_root) dot_dot += ".." + self.sep rel_path = path[len(common_root) :] if not rel_path: return "." if rel_path[0] == self.sep: # It is probably sufficient to remove just the first character # since os.path.normpath() collapses separators, but we use # lstrip() just to be sure. rel_path = rel_path.lstrip(self.sep) elif not common_root == "/": # We are in the case typified by the following example: # path = "/tmp/foobar", start = "/tmp/foo" -> rel_path = "bar" common_root = self.dirname(common_root) dot_dot += ".." + self.sep rel_path = path[len(common_root) + 1 :] return dot_dot + rel_path
def is_secure_path(self, path): return path.startswith("ssl") or ".https." in path
def isabs(self, path): return path.startswith(self.sep)
def http_test_path_to_uri(self, path): return "https://127.0.0.1:8443/" + path if path.startswith( "ssl") or ".https." in path else "http://127.0.0.1:8000/" + path