Replacement for os.path.join().
(*path_parts)
| 99 | |
| 100 | if _MS_WINDOWS: |
| 101 | def _path_join(*path_parts): |
| 102 | """Replacement for os.path.join().""" |
| 103 | if not path_parts: |
| 104 | return "" |
| 105 | if len(path_parts) == 1: |
| 106 | return path_parts[0] |
| 107 | root = "" |
| 108 | path = [] |
| 109 | for new_root, tail in map(_os._path_splitroot, path_parts): |
| 110 | if new_root.startswith(path_sep_tuple) or new_root.endswith(path_sep_tuple): |
| 111 | root = new_root.rstrip(path_separators) or root |
| 112 | path = [path_sep + tail] |
| 113 | elif new_root.endswith(':'): |
| 114 | if root.casefold() != new_root.casefold(): |
| 115 | # Drive relative paths have to be resolved by the OS, so we reset the |
| 116 | # tail but do not add a path_sep prefix. |
| 117 | root = new_root |
| 118 | path = [tail] |
| 119 | else: |
| 120 | path.append(tail) |
| 121 | else: |
| 122 | root = new_root or root |
| 123 | path.append(tail) |
| 124 | path = [p.rstrip(path_separators) for p in path if p] |
| 125 | if len(path) == 1 and not path[0]: |
| 126 | # Avoid losing the root's trailing separator when joining with nothing |
| 127 | return root + path_sep |
| 128 | return root + path_sep.join(path) |
| 129 | |
| 130 | else: |
| 131 | def _path_join(*path_parts): |
searching dependent graphs…