@@ -56,8 +56,8 @@ def _ignore_error(exception):
56
56
57
57
58
58
@functools .cache
59
- def _is_case_sensitive (flavour ):
60
- return flavour .normcase ('Aa' ) == 'Aa'
59
+ def _is_case_sensitive (pathmod ):
60
+ return pathmod .normcase ('Aa' ) == 'Aa'
61
61
62
62
#
63
63
# Globbing helpers
@@ -293,7 +293,7 @@ class PurePath:
293
293
# path. It's set when `__hash__()` is called for the first time.
294
294
'_hash' ,
295
295
)
296
- _flavour = os .path
296
+ pathmod = os .path
297
297
298
298
def __new__ (cls , * args , ** kwargs ):
299
299
"""Construct a PurePath from one or several strings and or existing
@@ -314,7 +314,7 @@ def __init__(self, *args):
314
314
paths = []
315
315
for arg in args :
316
316
if isinstance (arg , PurePath ):
317
- if arg ._flavour is ntpath and self ._flavour is posixpath :
317
+ if arg .pathmod is ntpath and self .pathmod is posixpath :
318
318
# GH-103631: Convert separators for backwards compatibility.
319
319
paths .extend (path .replace ('\\ ' , '/' ) for path in arg ._raw_paths )
320
320
else :
@@ -343,11 +343,11 @@ def with_segments(self, *pathsegments):
343
343
def _parse_path (cls , path ):
344
344
if not path :
345
345
return '' , '' , []
346
- sep = cls ._flavour .sep
347
- altsep = cls ._flavour .altsep
346
+ sep = cls .pathmod .sep
347
+ altsep = cls .pathmod .altsep
348
348
if altsep :
349
349
path = path .replace (altsep , sep )
350
- drv , root , rel = cls ._flavour .splitroot (path )
350
+ drv , root , rel = cls .pathmod .splitroot (path )
351
351
if not root and drv .startswith (sep ) and not drv .endswith (sep ):
352
352
drv_parts = drv .split (sep )
353
353
if len (drv_parts ) == 4 and drv_parts [2 ] not in '?.' :
@@ -366,7 +366,7 @@ def _load_parts(self):
366
366
elif len (paths ) == 1 :
367
367
path = paths [0 ]
368
368
else :
369
- path = self ._flavour .join (* paths )
369
+ path = self .pathmod .join (* paths )
370
370
drv , root , tail = self ._parse_path (path )
371
371
self ._drv = drv
372
372
self ._root = root
@@ -384,10 +384,10 @@ def _from_parsed_parts(self, drv, root, tail):
384
384
@classmethod
385
385
def _format_parsed_parts (cls , drv , root , tail ):
386
386
if drv or root :
387
- return drv + root + cls ._flavour .sep .join (tail )
388
- elif tail and cls ._flavour .splitdrive (tail [0 ])[0 ]:
387
+ return drv + root + cls .pathmod .sep .join (tail )
388
+ elif tail and cls .pathmod .splitdrive (tail [0 ])[0 ]:
389
389
tail = ['.' ] + tail
390
- return cls ._flavour .sep .join (tail )
390
+ return cls .pathmod .sep .join (tail )
391
391
392
392
def __str__ (self ):
393
393
"""Return the string representation of the path, suitable for
@@ -405,8 +405,7 @@ def __fspath__(self):
405
405
def as_posix (self ):
406
406
"""Return the string representation of the path with forward (/)
407
407
slashes."""
408
- f = self ._flavour
409
- return str (self ).replace (f .sep , '/' )
408
+ return str (self ).replace (self .pathmod .sep , '/' )
410
409
411
410
def __bytes__ (self ):
412
411
"""Return the bytes representation of the path. This is only
@@ -442,7 +441,7 @@ def _str_normcase(self):
442
441
try :
443
442
return self ._str_normcase_cached
444
443
except AttributeError :
445
- if _is_case_sensitive (self ._flavour ):
444
+ if _is_case_sensitive (self .pathmod ):
446
445
self ._str_normcase_cached = str (self )
447
446
else :
448
447
self ._str_normcase_cached = str (self ).lower ()
@@ -454,7 +453,7 @@ def _parts_normcase(self):
454
453
try :
455
454
return self ._parts_normcase_cached
456
455
except AttributeError :
457
- self ._parts_normcase_cached = self ._str_normcase .split (self ._flavour .sep )
456
+ self ._parts_normcase_cached = self ._str_normcase .split (self .pathmod .sep )
458
457
return self ._parts_normcase_cached
459
458
460
459
@property
@@ -467,14 +466,14 @@ def _lines(self):
467
466
if path_str == '.' :
468
467
self ._lines_cached = ''
469
468
else :
470
- trans = _SWAP_SEP_AND_NEWLINE [self ._flavour .sep ]
469
+ trans = _SWAP_SEP_AND_NEWLINE [self .pathmod .sep ]
471
470
self ._lines_cached = path_str .translate (trans )
472
471
return self ._lines_cached
473
472
474
473
def __eq__ (self , other ):
475
474
if not isinstance (other , PurePath ):
476
475
return NotImplemented
477
- return self ._str_normcase == other ._str_normcase and self ._flavour is other ._flavour
476
+ return self ._str_normcase == other ._str_normcase and self .pathmod is other .pathmod
478
477
479
478
def __hash__ (self ):
480
479
try :
@@ -484,22 +483,22 @@ def __hash__(self):
484
483
return self ._hash
485
484
486
485
def __lt__ (self , other ):
487
- if not isinstance (other , PurePath ) or self ._flavour is not other ._flavour :
486
+ if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
488
487
return NotImplemented
489
488
return self ._parts_normcase < other ._parts_normcase
490
489
491
490
def __le__ (self , other ):
492
- if not isinstance (other , PurePath ) or self ._flavour is not other ._flavour :
491
+ if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
493
492
return NotImplemented
494
493
return self ._parts_normcase <= other ._parts_normcase
495
494
496
495
def __gt__ (self , other ):
497
- if not isinstance (other , PurePath ) or self ._flavour is not other ._flavour :
496
+ if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
498
497
return NotImplemented
499
498
return self ._parts_normcase > other ._parts_normcase
500
499
501
500
def __ge__ (self , other ):
502
- if not isinstance (other , PurePath ) or self ._flavour is not other ._flavour :
501
+ if not isinstance (other , PurePath ) or self .pathmod is not other .pathmod :
503
502
return NotImplemented
504
503
return self ._parts_normcase >= other ._parts_normcase
505
504
@@ -584,9 +583,9 @@ def with_name(self, name):
584
583
"""Return a new path with the file name changed."""
585
584
if not self .name :
586
585
raise ValueError ("%r has an empty name" % (self ,))
587
- f = self ._flavour
588
- drv , root , tail = f .splitroot (name )
589
- if drv or root or not tail or f .sep in tail or (f .altsep and f .altsep in tail ):
586
+ m = self .pathmod
587
+ drv , root , tail = m .splitroot (name )
588
+ if drv or root or not tail or m .sep in tail or (m .altsep and m .altsep in tail ):
590
589
raise ValueError ("Invalid name %r" % (name ))
591
590
return self ._from_parsed_parts (self .drive , self .root ,
592
591
self ._tail [:- 1 ] + [name ])
@@ -600,8 +599,8 @@ def with_suffix(self, suffix):
600
599
has no suffix, add given suffix. If the given suffix is an empty
601
600
string, remove the suffix from the path.
602
601
"""
603
- f = self ._flavour
604
- if f .sep in suffix or f .altsep and f .altsep in suffix :
602
+ m = self .pathmod
603
+ if m .sep in suffix or m .altsep and m .altsep in suffix :
605
604
raise ValueError ("Invalid suffix %r" % (suffix ,))
606
605
if suffix and not suffix .startswith ('.' ) or suffix == '.' :
607
606
raise ValueError ("Invalid suffix %r" % (suffix ))
@@ -702,22 +701,22 @@ def parents(self):
702
701
def is_absolute (self ):
703
702
"""True if the path is absolute (has both a root and, if applicable,
704
703
a drive)."""
705
- if self ._flavour is ntpath :
704
+ if self .pathmod is ntpath :
706
705
# ntpath.isabs() is defective - see GH-44626.
707
706
return bool (self .drive and self .root )
708
- elif self ._flavour is posixpath :
707
+ elif self .pathmod is posixpath :
709
708
# Optimization: work with raw paths on POSIX.
710
709
for path in self ._raw_paths :
711
710
if path .startswith ('/' ):
712
711
return True
713
712
return False
714
713
else :
715
- return self ._flavour .isabs (str (self ))
714
+ return self .pathmod .isabs (str (self ))
716
715
717
716
def is_reserved (self ):
718
717
"""Return True if the path contains one of the special names reserved
719
718
by the system, if any."""
720
- if self ._flavour is posixpath or not self ._tail :
719
+ if self .pathmod is posixpath or not self ._tail :
721
720
return False
722
721
723
722
# NOTE: the rules for reserved names seem somewhat complicated
@@ -737,7 +736,7 @@ def match(self, path_pattern, *, case_sensitive=None):
737
736
if not isinstance (path_pattern , PurePath ):
738
737
path_pattern = self .with_segments (path_pattern )
739
738
if case_sensitive is None :
740
- case_sensitive = _is_case_sensitive (self ._flavour )
739
+ case_sensitive = _is_case_sensitive (self .pathmod )
741
740
pattern = _compile_pattern_lines (path_pattern ._lines , case_sensitive )
742
741
if path_pattern .drive or path_pattern .root :
743
742
return pattern .match (self ._lines ) is not None
@@ -758,7 +757,7 @@ class PurePosixPath(PurePath):
758
757
On a POSIX system, instantiating a PurePath should return this object.
759
758
However, you can also instantiate it directly on any system.
760
759
"""
761
- _flavour = posixpath
760
+ pathmod = posixpath
762
761
__slots__ = ()
763
762
764
763
@@ -768,7 +767,7 @@ class PureWindowsPath(PurePath):
768
767
On a Windows system, instantiating a PurePath should return this object.
769
768
However, you can also instantiate it directly on any system.
770
769
"""
771
- _flavour = ntpath
770
+ pathmod = ntpath
772
771
__slots__ = ()
773
772
774
773
@@ -858,7 +857,7 @@ def is_mount(self):
858
857
"""
859
858
Check if this path is a mount point
860
859
"""
861
- return self . _flavour .ismount (self )
860
+ return os . path .ismount (self )
862
861
863
862
def is_symlink (self ):
864
863
"""
@@ -879,7 +878,7 @@ def is_junction(self):
879
878
"""
880
879
Whether this path is a junction.
881
880
"""
882
- return self . _flavour .isjunction (self )
881
+ return os . path .isjunction (self )
883
882
884
883
def is_block_device (self ):
885
884
"""
@@ -954,7 +953,8 @@ def samefile(self, other_path):
954
953
other_st = other_path .stat ()
955
954
except AttributeError :
956
955
other_st = self .with_segments (other_path ).stat ()
957
- return self ._flavour .samestat (st , other_st )
956
+ return (st .st_ino == other_st .st_ino and
957
+ st .st_dev == other_st .st_dev )
958
958
959
959
def open (self , mode = 'r' , buffering = - 1 , encoding = None ,
960
960
errors = None , newline = None ):
@@ -1017,7 +1017,7 @@ def _scandir(self):
1017
1017
return os .scandir (self )
1018
1018
1019
1019
def _make_child_relpath (self , name ):
1020
- sep = self ._flavour .sep
1020
+ sep = self .pathmod .sep
1021
1021
lines_name = name .replace ('\n ' , sep )
1022
1022
lines_str = self ._lines
1023
1023
path_str = str (self )
@@ -1062,7 +1062,7 @@ def _glob(self, pattern, case_sensitive, follow_symlinks):
1062
1062
raise ValueError ("Unacceptable pattern: {!r}" .format (pattern ))
1063
1063
1064
1064
pattern_parts = list (path_pattern ._tail )
1065
- if pattern [- 1 ] in (self ._flavour .sep , self ._flavour .altsep ):
1065
+ if pattern [- 1 ] in (self .pathmod .sep , self .pathmod .altsep ):
1066
1066
# GH-65238: pathlib doesn't preserve trailing slash. Add it back.
1067
1067
pattern_parts .append ('' )
1068
1068
if pattern_parts [- 1 ] == '**' :
@@ -1071,7 +1071,7 @@ def _glob(self, pattern, case_sensitive, follow_symlinks):
1071
1071
1072
1072
if case_sensitive is None :
1073
1073
# TODO: evaluate case-sensitivity of each directory in _select_children().
1074
- case_sensitive = _is_case_sensitive (self ._flavour )
1074
+ case_sensitive = _is_case_sensitive (self .pathmod )
1075
1075
1076
1076
# If symlinks are handled consistently, and the pattern does not
1077
1077
# contain '..' components, then we can use a 'walk-and-match' strategy
@@ -1204,7 +1204,7 @@ def absolute(self):
1204
1204
return self
1205
1205
elif self .drive :
1206
1206
# There is a CWD on each drive-letter drive.
1207
- cwd = self . _flavour .abspath (self .drive )
1207
+ cwd = os . path .abspath (self .drive )
1208
1208
else :
1209
1209
cwd = os .getcwd ()
1210
1210
# Fast path for "empty" paths, e.g. Path("."), Path("") or Path().
@@ -1230,7 +1230,7 @@ def check_eloop(e):
1230
1230
raise RuntimeError ("Symlink loop from %r" % e .filename )
1231
1231
1232
1232
try :
1233
- s = self . _flavour .realpath (self , strict = strict )
1233
+ s = os . path .realpath (self , strict = strict )
1234
1234
except OSError as e :
1235
1235
check_eloop (e )
1236
1236
raise
@@ -1394,7 +1394,7 @@ def expanduser(self):
1394
1394
"""
1395
1395
if (not (self .drive or self .root ) and
1396
1396
self ._tail and self ._tail [0 ][:1 ] == '~' ):
1397
- homedir = self . _flavour .expanduser (self ._tail [0 ])
1397
+ homedir = os . path .expanduser (self ._tail [0 ])
1398
1398
if homedir [:1 ] == "~" :
1399
1399
raise RuntimeError ("Could not determine home directory." )
1400
1400
drv , root , tail = self ._parse_path (homedir )
0 commit comments