OLD | NEW |
1 import os | 1 import os |
2 import sys | 2 import sys |
3 | 3 |
4 try: | 4 try: |
5 from functools import wraps | 5 from functools import wraps |
6 except ImportError: | 6 except ImportError: |
7 # only needed for Python 2.4 | 7 # only needed for Python 2.4 |
8 def wraps(_): | 8 def wraps(_): |
9 def _wraps(func): | 9 def _wraps(func): |
10 return func | 10 return func |
(...skipping 28 matching lines...) Expand all Loading... |
39 if not rel_list: | 39 if not rel_list: |
40 return os.path.curdir | 40 return os.path.curdir |
41 return os.path.join(*rel_list) | 41 return os.path.join(*rel_list) |
42 | 42 |
43 # default to posixpath definition | 43 # default to posixpath definition |
44 def _relpath_posix(path, start=os.path.curdir): | 44 def _relpath_posix(path, start=os.path.curdir): |
45 """Return a relative version of a path""" | 45 """Return a relative version of a path""" |
46 | 46 |
47 if not path: | 47 if not path: |
48 raise ValueError("no path specified") | 48 raise ValueError("no path specified") |
49 | 49 |
50 start_list = os.path.abspath(start).split(os.path.sep) | 50 start_list = os.path.abspath(start).split(os.path.sep) |
51 path_list = os.path.abspath(path).split(os.path.sep) | 51 path_list = os.path.abspath(path).split(os.path.sep) |
52 | 52 |
53 # Work out how much of the filepath is shared by start and path. | 53 # Work out how much of the filepath is shared by start and path. |
54 i = len(os.path.commonprefix([start_list, path_list])) | 54 i = len(os.path.commonprefix([start_list, path_list])) |
55 | 55 |
56 rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] | 56 rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] |
57 if not rel_list: | 57 if not rel_list: |
58 return os.path.curdir | 58 return os.path.curdir |
59 return os.path.join(*rel_list) | 59 return os.path.join(*rel_list) |
60 | 60 |
61 if os.path is sys.modules.get('ntpath'): | 61 if os.path is sys.modules.get('ntpath'): |
62 relpath = _relpath_nt | 62 relpath = _relpath_nt |
63 else: | 63 else: |
64 relpath = _relpath_posix | 64 relpath = _relpath_posix |
OLD | NEW |