@@ -54,20 +54,11 @@ class _Flavour(object):
54
54
class _WindowsFlavour (_Flavour ):
55
55
# Reference for Windows paths can be found at
56
56
# http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx
57
-
58
- def casefold (self , s ):
59
- return s .lower ()
60
-
61
- def casefold_parts (self , parts ):
62
- return [p .lower () for p in parts ]
57
+ pass
63
58
64
59
65
60
class _PosixFlavour (_Flavour ):
66
- def casefold (self , s ):
67
- return s
68
-
69
- def casefold_parts (self , parts ):
70
- return parts
61
+ pass
71
62
72
63
73
64
_windows_flavour = _WindowsFlavour ()
@@ -465,14 +456,26 @@ def _join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
465
456
if not drv2 and drv :
466
457
return drv , root2 , [drv + root2 ] + parts2 [1 :]
467
458
elif drv2 :
468
- if drv2 == drv or self ._flavour . casefold (drv2 ) == self ._flavour . casefold (drv ):
459
+ if drv2 == drv or self ._casefold (drv2 ) == self ._casefold (drv ):
469
460
# Same drive => second path is relative to the first
470
461
return drv , root , parts + parts2 [1 :]
471
462
else :
472
463
# Second path is non-anchored (common case)
473
464
return drv , root , parts + parts2
474
465
return drv2 , root2 , parts2
475
466
467
+ @classmethod
468
+ def _casefold (cls , s ):
469
+ if cls ._case_insensitive :
470
+ return s .lower ()
471
+ return s
472
+
473
+ @classmethod
474
+ def _casefold_parts (cls , parts ):
475
+ if cls ._case_insensitive :
476
+ return [p .lower () for p in parts ]
477
+ return parts
478
+
476
479
def __str__ (self ):
477
480
"""Return the string representation of the path, suitable for
478
481
passing to system calls."""
@@ -509,7 +512,7 @@ def _cparts(self):
509
512
try :
510
513
return self ._cached_cparts
511
514
except AttributeError :
512
- self ._cached_cparts = self ._flavour . casefold_parts (self ._parts )
515
+ self ._cached_cparts = self ._casefold_parts (self ._parts )
513
516
return self ._cached_cparts
514
517
515
518
def __eq__ (self , other ):
@@ -665,7 +668,7 @@ def relative_to(self, *other):
665
668
else :
666
669
to_abs_parts = to_parts
667
670
n = len (to_abs_parts )
668
- cf = self ._flavour . casefold_parts
671
+ cf = self ._casefold_parts
669
672
if (root or drv ) if n == 0 else cf (abs_parts [:n ]) != cf (to_abs_parts ):
670
673
formatted = self ._format_parsed_parts (to_drv , to_root , to_parts )
671
674
raise ValueError ("{!r} is not in the subpath of {!r}"
@@ -744,7 +747,7 @@ def match(self, path_pattern):
744
747
"""
745
748
Return True if this path matches the given pattern.
746
749
"""
747
- cf = self ._flavour . casefold
750
+ cf = self ._casefold
748
751
path_pattern = cf (path_pattern )
749
752
drv , root , pat_parts = self ._parse_parts ((path_pattern ,))
750
753
if not pat_parts :
0 commit comments