@@ -613,41 +613,44 @@ class PureWindowsPath(PurePath):
613
613
__slots__ = ()
614
614
615
615
616
- class _Info :
616
+ class Info :
617
+ """Implementation of pathlib.types.PathInfo that provides cached
618
+ information about a local filesystem path. Don't try to construct it
619
+ yourself.
620
+ """
617
621
__slots__ = ('_path' ,)
618
622
619
623
def __init__ (self , path ):
624
+ if type (self ) is Info :
625
+ raise TypeError ('Info cannot be directly instantiated; '
626
+ 'use Path.info instead.' )
620
627
self ._path = path
621
628
622
- def __repr__ (self ):
623
- path_type = "WindowsPath" if os .name == "nt" else "PosixPath"
624
- return f"<{ path_type } .info>"
625
-
626
- def _stat (self , * , follow_symlinks = True ):
629
+ def stat (self , * , follow_symlinks = True ):
627
630
"""Return the status as an os.stat_result."""
628
631
raise NotImplementedError
629
632
630
633
def _posix_permissions (self , * , follow_symlinks = True ):
631
634
"""Return the POSIX file permissions."""
632
- return S_IMODE (self ._stat (follow_symlinks = follow_symlinks ).st_mode )
635
+ return S_IMODE (self .stat (follow_symlinks = follow_symlinks ).st_mode )
633
636
634
637
def _file_id (self , * , follow_symlinks = True ):
635
638
"""Returns the identifier of the file."""
636
- st = self ._stat (follow_symlinks = follow_symlinks )
639
+ st = self .stat (follow_symlinks = follow_symlinks )
637
640
return st .st_dev , st .st_ino
638
641
639
642
def _access_time_ns (self , * , follow_symlinks = True ):
640
643
"""Return the access time in nanoseconds."""
641
- return self ._stat (follow_symlinks = follow_symlinks ).st_atime_ns
644
+ return self .stat (follow_symlinks = follow_symlinks ).st_atime_ns
642
645
643
646
def _mod_time_ns (self , * , follow_symlinks = True ):
644
647
"""Return the modify time in nanoseconds."""
645
- return self ._stat (follow_symlinks = follow_symlinks ).st_mtime_ns
648
+ return self .stat (follow_symlinks = follow_symlinks ).st_mtime_ns
646
649
647
650
if hasattr (os .stat_result , 'st_flags' ):
648
651
def _bsd_flags (self , * , follow_symlinks = True ):
649
652
"""Return the flags."""
650
- return self ._stat (follow_symlinks = follow_symlinks ).st_flags
653
+ return self .stat (follow_symlinks = follow_symlinks ).st_flags
651
654
652
655
if hasattr (os , 'listxattr' ):
653
656
def _xattrs (self , * , follow_symlinks = True ):
@@ -666,7 +669,7 @@ def _xattrs(self, *, follow_symlinks=True):
666
669
_STAT_RESULT_ERROR = [] # falsy sentinel indicating stat() failed.
667
670
668
671
669
- class _StatResultInfo (_Info ):
672
+ class _StatResultInfo (Info ):
670
673
"""Implementation of pathlib.types.PathInfo that provides status
671
674
information by querying a wrapped os.stat_result object. Don't try to
672
675
construct it yourself."""
@@ -677,7 +680,7 @@ def __init__(self, path):
677
680
self ._stat_result = None
678
681
self ._lstat_result = None
679
682
680
- def _stat (self , * , follow_symlinks = True ):
683
+ def stat (self , * , follow_symlinks = True ):
681
684
"""Return the status as an os.stat_result."""
682
685
if follow_symlinks :
683
686
if not self ._stat_result :
@@ -705,7 +708,7 @@ def exists(self, *, follow_symlinks=True):
705
708
if self ._lstat_result is _STAT_RESULT_ERROR :
706
709
return False
707
710
try :
708
- self ._stat (follow_symlinks = follow_symlinks )
711
+ self .stat (follow_symlinks = follow_symlinks )
709
712
except (OSError , ValueError ):
710
713
return False
711
714
return True
@@ -719,7 +722,7 @@ def is_dir(self, *, follow_symlinks=True):
719
722
if self ._lstat_result is _STAT_RESULT_ERROR :
720
723
return False
721
724
try :
722
- st = self ._stat (follow_symlinks = follow_symlinks )
725
+ st = self .stat (follow_symlinks = follow_symlinks )
723
726
except (OSError , ValueError ):
724
727
return False
725
728
return S_ISDIR (st .st_mode )
@@ -733,7 +736,7 @@ def is_file(self, *, follow_symlinks=True):
733
736
if self ._lstat_result is _STAT_RESULT_ERROR :
734
737
return False
735
738
try :
736
- st = self ._stat (follow_symlinks = follow_symlinks )
739
+ st = self .stat (follow_symlinks = follow_symlinks )
737
740
except (OSError , ValueError ):
738
741
return False
739
742
return S_ISREG (st .st_mode )
@@ -743,13 +746,13 @@ def is_symlink(self):
743
746
if self ._lstat_result is _STAT_RESULT_ERROR :
744
747
return False
745
748
try :
746
- st = self ._stat (follow_symlinks = False )
749
+ st = self .stat (follow_symlinks = False )
747
750
except (OSError , ValueError ):
748
751
return False
749
752
return S_ISLNK (st .st_mode )
750
753
751
754
752
- class _DirEntryInfo (_Info ):
755
+ class _DirEntryInfo (Info ):
753
756
"""Implementation of pathlib.types.PathInfo that provides status
754
757
information by querying a wrapped os.DirEntry object. Don't try to
755
758
construct it yourself."""
@@ -759,7 +762,7 @@ def __init__(self, entry):
759
762
super ().__init__ (entry .path )
760
763
self ._entry = entry
761
764
762
- def _stat (self , * , follow_symlinks = True ):
765
+ def stat (self , * , follow_symlinks = True ):
763
766
"""Return the status as an os.stat_result."""
764
767
return self ._entry .stat (follow_symlinks = follow_symlinks )
765
768
@@ -768,7 +771,7 @@ def exists(self, *, follow_symlinks=True):
768
771
if not follow_symlinks :
769
772
return True
770
773
try :
771
- self ._stat (follow_symlinks = follow_symlinks )
774
+ self .stat (follow_symlinks = follow_symlinks )
772
775
except OSError :
773
776
return False
774
777
return True
0 commit comments