~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/util.py

  • Committer: Matt Giuca
  • Date: 2009-05-12 15:21:57 UTC
  • mto: This revision was merged to the branch mainline in revision 1247.
  • Revision ID: matt.giuca@gmail.com-20090512152157-ueya8fkemrjbo9ju
ivle.util: Backported os.path.relpath from Python2.6 (required).
ivle-fetchsubmissions: Use ivle.util.relpath not os.path.relpath (not
    available pre 2.6).

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
    else:
97
97
        return tuple(splitpath)
98
98
 
 
99
def relpath(path, start=os.path.curdir):
 
100
    """Return a relative version of a path.
 
101
    XXX Backported from Python 2.6 posixpath.py.
 
102
    """
 
103
 
 
104
    if not path:
 
105
        raise ValueError("no path specified")
 
106
 
 
107
    start_list = os.path.abspath(start).split(os.path.sep)
 
108
    path_list = os.path.abspath(path).split(os.path.sep)
 
109
 
 
110
    # Work out how much of the filepath is shared by start and path.
 
111
    i = len(os.path.commonprefix([start_list, path_list]))
 
112
 
 
113
    rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
 
114
    if not rel_list:
 
115
        return os.path.curdir
 
116
    return os.path.join(*rel_list)
 
117
 
99
118
def incomplete_utf8_sequence(byteseq):
100
119
    """Calculate the completeness of a UTF-8 encoded string.
101
120