def get_link_path(target, base): """Returns a relative path to ``target`` from ``base``. If ``base`` is an existing file, then its parent directory is considered to be the base. Otherwise ``base`` is assumed to be a directory. The returned path is URL encoded. On Windows returns an absolute path with ``file:`` prefix if the target is on a different drive. """ path = _get_link_path(target, base) url = path_to_url(path) if os.path.isabs(path): url = 'file:' + url return url
def get_link_path(target, base): """Returns a relative path to a target from a base. If base is an existing file, then its parent directory is considered. Otherwise, base is assumed to be a directory. Rationale: os.path.relpath is not available before Python 2.6 """ path = _get_pathname(target, base) url = path_to_url(path) if os.path.isabs(path): url = 'file:' + url # At least Jython seems to use 'C|/Path' and not 'C:/Path' if os.sep == '\\' and '|/' in url: url = url.replace('|/', ':/', 1) return url.replace('%5C', '/').replace('%3A', ':').replace('|', ':')