MCPcopy Index your code
hub / github.com/python/cpython / splitroot

Function splitroot

Lib/posixpath.py:142–162  ·  view source on GitHub ↗

Split a pathname into drive, root and tail. The tail contains anything after the root.

(p, /)

Source from the content-addressed store, hash-verified

140 from posix import _path_splitroot_ex as splitroot
141except 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].

Callers 1

normpathFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…