Split a pathname into drive, root and tail. The tail contains anything after the root.
(p, /)
| 140 | from posix import _path_splitroot_ex as splitroot |
| 141 | except ImportError: |
| 142 | def splitroot(p, /): |
| 143 | """Split a pathname into drive, root and tail. |
| 144 | |
| 145 | The tail contains anything after the root.""" |
| 146 | p = os.fspath(p) |
| 147 | if isinstance(p, bytes): |
| 148 | sep = b'/' |
| 149 | empty = b'' |
| 150 | else: |
| 151 | sep = '/' |
| 152 | empty = '' |
| 153 | if p[:1] != sep: |
| 154 | # Relative path, e.g.: 'foo' |
| 155 | return empty, empty, p |
| 156 | elif p[1:2] != sep or p[2:3] == sep: |
| 157 | # Absolute path, e.g.: '/foo', '///foo', '////foo', etc. |
| 158 | return empty, sep, p[1:] |
| 159 | else: |
| 160 | # Precisely two leading slashes, e.g.: '//foo'. Implementation defined per POSIX, see |
| 161 | # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 |
| 162 | return empty, p[:2], p[2:] |
| 163 | |
| 164 | |
| 165 | # Return the tail (basename) part of a path, same as split(path)[1]. |
no outgoing calls
no test coverage detected
searching dependent graphs…