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

Class _Info

Lib/pathlib/__init__.py:617–757  ·  view source on GitHub ↗

Implementation of pathlib.types.PathInfo that provides status information by querying a wrapped os.stat_result object. Don't try to construct it yourself.

Source from the content-addressed store, hash-verified

615
616
617class _Info:
618 """Implementation of pathlib.types.PathInfo that provides status
619 information by querying a wrapped os.stat_result object. Don't try to
620 construct it yourself."""
621 __slots__ = ('_path', '_entry', '_stat_result', '_lstat_result')
622
623 def __init__(self, path, entry=None):
624 self._path = path
625 self._entry = entry
626 self._stat_result = None
627 self._lstat_result = None
628
629 def __repr__(self):
630 path_type = "WindowsPath" if os.name == "nt" else "PosixPath"
631 return f"<{path_type}.info>"
632
633 def _stat(self, *, follow_symlinks=True):
634 """Return the status as an os.stat_result."""
635 if self._entry:
636 return self._entry.stat(follow_symlinks=follow_symlinks)
637 if follow_symlinks:
638 if not self._stat_result:
639 try:
640 self._stat_result = os.stat(self._path)
641 except (OSError, ValueError):
642 self._stat_result = _STAT_RESULT_ERROR
643 raise
644 return self._stat_result
645 else:
646 if not self._lstat_result:
647 try:
648 self._lstat_result = os.lstat(self._path)
649 except (OSError, ValueError):
650 self._lstat_result = _STAT_RESULT_ERROR
651 raise
652 return self._lstat_result
653
654 def exists(self, *, follow_symlinks=True):
655 """Whether this path exists."""
656 if self._entry:
657 if not follow_symlinks:
658 return True
659 if follow_symlinks:
660 if self._stat_result is _STAT_RESULT_ERROR:
661 return False
662 else:
663 if self._lstat_result is _STAT_RESULT_ERROR:
664 return False
665 try:
666 self._stat(follow_symlinks=follow_symlinks)
667 except (OSError, ValueError):
668 return False
669 return True
670
671 def is_dir(self, *, follow_symlinks=True):
672 """Whether this path is a directory."""
673 if self._entry:
674 try:

Callers 2

infoMethod · 0.70
_from_dir_entryMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…