Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.
(a, /, *p)
| 71 | # Insert a '/' unless the first part is empty or already ends in '/'. |
| 72 | |
| 73 | def join(a, /, *p): |
| 74 | """Join two or more pathname components, inserting '/' as needed. |
| 75 | If any component is an absolute path, all previous path components |
| 76 | will be discarded. An empty last part will result in a path that |
| 77 | ends with a separator.""" |
| 78 | a = os.fspath(a) |
| 79 | sep = _get_sep(a) |
| 80 | path = a |
| 81 | try: |
| 82 | for b in p: |
| 83 | b = os.fspath(b) |
| 84 | if b.startswith(sep) or not path: |
| 85 | path = b |
| 86 | elif path.endswith(sep): |
| 87 | path += b |
| 88 | else: |
| 89 | path += sep + b |
| 90 | except (TypeError, AttributeError, BytesWarning): |
| 91 | genericpath._check_arg_types('join', a, *p) |
| 92 | raise |
| 93 | return path |
| 94 | |
| 95 | |
| 96 | # Split a path in head (everything up to the last '/') and tail (the |
no test coverage detected
searching dependent graphs…