@@ -50,13 +50,10 @@ class _Flavour(object):
5050 """A flavour implements a particular (platform-specific) set of path
5151 semantics."""
5252
53- def __init__ (self ):
54- self .join = self .sep .join
55-
5653 def parse_parts (self , parts ):
5754 parsed = []
58- sep = self .sep
59- altsep = self .altsep
55+ sep = self .pathmod . sep
56+ altsep = self .pathmod . altsep
6057 drv = root = ''
6158 it = reversed (parts )
6259 for part in it :
@@ -113,8 +110,6 @@ class _WindowsFlavour(_Flavour):
113110 # Reference for Windows paths can be found at
114111 # http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx
115112
116- sep = '\\ '
117- altsep = '/'
118113 has_drv = True
119114 pathmod = ntpath
120115
@@ -129,7 +124,8 @@ class _WindowsFlavour(_Flavour):
129124 # - extended paths are always absolute; "relative" extended paths will
130125 # fail.
131126
132- def splitroot (self , part , sep = sep ):
127+ def splitroot (self , part ):
128+ sep = self .pathmod .sep
133129 first = part [0 :1 ]
134130 second = part [1 :2 ]
135131 if (second == sep and first == sep ):
@@ -189,14 +185,13 @@ def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
189185
190186
191187class _PosixFlavour (_Flavour ):
192- sep = '/'
193- altsep = ''
194188 has_drv = False
195189 pathmod = posixpath
196190
197191 is_supported = (os .name != 'nt' )
198192
199- def splitroot (self , part , sep = sep ):
193+ def splitroot (self , part ):
194+ sep = self .pathmod .sep
200195 if part and part [0 ] == sep :
201196 stripped_part = part .lstrip (sep )
202197 # According to POSIX path resolution:
@@ -557,9 +552,9 @@ def _from_parsed_parts(cls, drv, root, parts):
557552 @classmethod
558553 def _format_parsed_parts (cls , drv , root , parts ):
559554 if drv or root :
560- return drv + root + cls ._flavour .join (parts [1 :])
555+ return drv + root + cls ._flavour .pathmod . sep . join (parts [1 :])
561556 else :
562- return cls ._flavour .join (parts )
557+ return cls ._flavour .pathmod . sep . join (parts )
563558
564559 def _make_child (self , args ):
565560 drv , root , parts = self ._parse_args (args )
@@ -584,7 +579,7 @@ def as_posix(self):
584579 """Return the string representation of the path with forward (/)
585580 slashes."""
586581 f = self ._flavour
587- return str (self ).replace (f .sep , '/' )
582+ return str (self ).replace (f .pathmod . sep , '/' )
588583
589584 def __bytes__ (self ):
590585 """Return the bytes representation of the path. This is only
@@ -704,7 +699,8 @@ def with_name(self, name):
704699 if not self .name :
705700 raise ValueError ("%r has an empty name" % (self ,))
706701 drv , root , parts = self ._flavour .parse_parts ((name ,))
707- if (not name or name [- 1 ] in [self ._flavour .sep , self ._flavour .altsep ]
702+ m = self ._flavour .pathmod
703+ if (not name or name [- 1 ] in [m .sep , m .altsep ]
708704 or drv or root or len (parts ) != 1 ):
709705 raise ValueError ("Invalid name %r" % (name ))
710706 return self ._from_parsed_parts (self ._drv , self ._root ,
@@ -719,8 +715,8 @@ def with_suffix(self, suffix):
719715 has no suffix, add given suffix. If the given suffix is an empty
720716 string, remove the suffix from the path.
721717 """
722- f = self ._flavour
723- if f .sep in suffix or f .altsep and f .altsep in suffix :
718+ m = self ._flavour . pathmod
719+ if m .sep in suffix or m .altsep and m .altsep in suffix :
724720 raise ValueError ("Invalid suffix %r" % (suffix ,))
725721 if suffix and not suffix .startswith ('.' ) or suffix == '.' :
726722 raise ValueError ("Invalid suffix %r" % (suffix ))
0 commit comments