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

Class PurePath

tools/python-3.11.9-amd64/Lib/pathlib.py:455–827  ·  view source on GitHub ↗

Base class for manipulating paths without I/O. PurePath represents a filesystem path and offers operations which don't imply any actual filesystem I/O. Depending on your system, instantiating a PurePath will return either a PurePosixPath or a PureWindowsPath object. You can a

Source from the content-addressed store, hash-verified

453
454
455class PurePath(object):
456 """Base class for manipulating paths without I/O.
457
458 PurePath represents a filesystem path and offers operations which
459 don't imply any actual filesystem I/O. Depending on your system,
460 instantiating a PurePath will return either a PurePosixPath or a
461 PureWindowsPath object. You can also instantiate either of these classes
462 directly, regardless of your system.
463 """
464 __slots__ = (
465 '_drv', '_root', '_parts',
466 '_str', '_hash', '_pparts', '_cached_cparts',
467 )
468
469 def __new__(cls, *args):
470 """Construct a PurePath from one or several strings and or existing
471 PurePath objects. The strings and path objects are combined so as
472 to yield a canonicalized path, which is incorporated into the
473 new PurePath object.
474 """
475 if cls is PurePath:
476 cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
477 return cls._from_parts(args)
478
479 def __reduce__(self):
480 # Using the parts tuple helps share interned path parts
481 # when pickling related paths.
482 return (self.__class__, tuple(self._parts))
483
484 @classmethod
485 def _parse_args(cls, args):
486 # This is useful when you don't want to create an instance, just
487 # canonicalize some constructor arguments.
488 parts = []
489 for a in args:
490 if isinstance(a, PurePath):
491 parts += a._parts
492 else:
493 a = os.fspath(a)
494 if isinstance(a, str):
495 # Force-cast str subclasses to str (issue #21127)
496 parts.append(str(a))
497 else:
498 raise TypeError(
499 "argument should be a str object or an os.PathLike "
500 "object returning str, not %r"
501 % type(a))
502 return cls._flavour.parse_parts(parts)
503
504 @classmethod
505 def _from_parts(cls, args):
506 # We need to call _parse_args on the instance, so as to get the
507 # right flavour.
508 self = object.__new__(cls)
509 drv, root, parts = self._parse_args(args)
510 self._drv = drv
511 self._root = root
512 self._parts = parts

Callers

nothing calls this directly

Calls 2

attrgetterClass · 0.90
propertyClass · 0.85

Tested by

no test coverage detected