MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / splitroot

Method splitroot

tools/python-3.11.9-amd64/Lib/pathlib.py:147–184  ·  view source on GitHub ↗
(self, part, sep=sep)

Source from the content-addressed store, hash-verified

145 # even with the '\\?\' prefix.
146
147 def splitroot(self, part, sep=sep):
148 first = part[0:1]
149 second = part[1:2]
150 if (second == sep and first == sep):
151 # XXX extended paths should also disable the collapsing of "."
152 # components (according to MSDN docs).
153 prefix, part = self._split_extended_path(part)
154 first = part[0:1]
155 second = part[1:2]
156 else:
157 prefix = ''
158 third = part[2:3]
159 if (second == sep and first == sep and third != sep):
160 # is a UNC path:
161 # vvvvvvvvvvvvvvvvvvvvv root
162 # \\machine\mountpoint\directory\etc\...
163 # directory ^^^^^^^^^^^^^^
164 index = part.find(sep, 2)
165 if index != -1:
166 index2 = part.find(sep, index + 1)
167 # a UNC path can't have two slashes in a row
168 # (after the initial two)
169 if index2 != index + 1:
170 if index2 == -1:
171 index2 = len(part)
172 if prefix:
173 return prefix + part[1:index2], sep, part[index2+1:]
174 else:
175 return part[:index2], sep, part[index2+1:]
176 drv = root = ''
177 if second == ':' and first in self.drive_letters:
178 drv = part[:2]
179 part = part[2:]
180 first = third
181 if first == sep:
182 root = first
183 part = part.lstrip(sep)
184 return prefix + drv, root, part
185
186 def casefold(self, s):
187 return s.lower()

Callers

nothing calls this directly

Calls 3

_split_extended_pathMethod · 0.95
lstripMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected