MCPcopy Index your code
hub / github.com/RustPython/RustPython / _parse_pattern

Method _parse_pattern

Lib/pathlib/__init__.py:301–323  ·  view source on GitHub ↗

Parse a glob pattern to a list of parts. This is much like _parse_path, except: - Rather than normalizing and returning the drive and root, we raise NotImplementedError if either are present. - If the path has no real parts, we raise ValueError. - If the pa

(cls, pattern)

Source from the content-addressed store, hash-verified

299
300 @classmethod
301 def _parse_pattern(cls, pattern):
302 """Parse a glob pattern to a list of parts. This is much like
303 _parse_path, except:
304
305 - Rather than normalizing and returning the drive and root, we raise
306 NotImplementedError if either are present.
307 - If the path has no real parts, we raise ValueError.
308 - If the path ends in a slash, then a final empty part is added.
309 """
310 drv, root, rel = cls.parser.splitroot(pattern)
311 if root or drv:
312 raise NotImplementedError("Non-relative patterns are unsupported")
313 sep = cls.parser.sep
314 altsep = cls.parser.altsep
315 if altsep:
316 rel = rel.replace(altsep, sep)
317 parts = [x for x in rel.split(sep) if x and x != '.']
318 if not parts:
319 raise ValueError(f"Unacceptable pattern: {str(pattern)!r}")
320 elif rel.endswith(sep):
321 # GH-65238: preserve trailing slash in glob patterns.
322 parts.append('')
323 return parts
324
325 def as_posix(self):
326 """Return the string representation of the path with forward (/)

Callers 1

globMethod · 0.80

Calls 5

strFunction · 0.85
replaceMethod · 0.45
splitMethod · 0.45
endswithMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected