@@ -70,7 +70,7 @@ def isabs(s):
7070 if s .replace ('/' , '\\ ' ).startswith ('\\ \\ ?\\ ' ):
7171 return True
7272 s = splitdrive (s )[1 ]
73- return len (s ) > 0 and s [0 ] in _get_bothseps (s )
73+ return len (s ) > 0 and s [0 ] and s [ 0 ] in _get_bothseps (s )
7474
7575
7676# Join two (or more) paths.
@@ -268,11 +268,13 @@ def ismount(path):
268268 root , rest = splitdrive (path )
269269 if root and root [0 ] in seps :
270270 return (not rest ) or (rest in seps )
271- if rest in seps :
271+ if rest and rest in seps :
272272 return True
273273
274274 if _getvolumepathname :
275- return path .rstrip (seps ) == _getvolumepathname (path ).rstrip (seps )
275+ x = path .rstrip (seps )
276+ y = _getvolumepathname (path ).rstrip (seps )
277+ return x .casefold () == y .casefold ()
276278 else :
277279 return False
278280
@@ -459,56 +461,68 @@ def expandvars(path):
459461# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
460462# Previously, this function also truncated pathnames to 8+3 format,
461463# but as this module is called "ntpath", that's obviously wrong!
464+ try :
465+ from nt import _path_normpath
462466
463- def normpath (path ):
464- """Normalize path, eliminating double slashes, etc."""
465- path = os .fspath (path )
466- if isinstance (path , bytes ):
467- sep = b'\\ '
468- altsep = b'/'
469- curdir = b'.'
470- pardir = b'..'
471- special_prefixes = (b'\\ \\ .\\ ' , b'\\ \\ ?\\ ' )
472- else :
473- sep = '\\ '
474- altsep = '/'
475- curdir = '.'
476- pardir = '..'
477- special_prefixes = ('\\ \\ .\\ ' , '\\ \\ ?\\ ' )
478- if path .startswith (special_prefixes ):
479- # in the case of paths with these prefixes:
480- # \\.\ -> device names
481- # \\?\ -> literal paths
482- # do not do any normalization, but return the path
483- # unchanged apart from the call to os.fspath()
484- return path
485- path = path .replace (altsep , sep )
486- prefix , path = splitdrive (path )
487-
488- # collapse initial backslashes
489- if path .startswith (sep ):
490- prefix += sep
491- path = path .lstrip (sep )
492-
493- comps = path .split (sep )
494- i = 0
495- while i < len (comps ):
496- if not comps [i ] or comps [i ] == curdir :
497- del comps [i ]
498- elif comps [i ] == pardir :
499- if i > 0 and comps [i - 1 ] != pardir :
500- del comps [i - 1 :i + 1 ]
501- i -= 1
502- elif i == 0 and prefix .endswith (sep ):
467+ except ImportError :
468+ def normpath (path ):
469+ """Normalize path, eliminating double slashes, etc."""
470+ path = os .fspath (path )
471+ if isinstance (path , bytes ):
472+ sep = b'\\ '
473+ altsep = b'/'
474+ curdir = b'.'
475+ pardir = b'..'
476+ special_prefixes = (b'\\ \\ .\\ ' , b'\\ \\ ?\\ ' )
477+ else :
478+ sep = '\\ '
479+ altsep = '/'
480+ curdir = '.'
481+ pardir = '..'
482+ special_prefixes = ('\\ \\ .\\ ' , '\\ \\ ?\\ ' )
483+ if path .startswith (special_prefixes ):
484+ # in the case of paths with these prefixes:
485+ # \\.\ -> device names
486+ # \\?\ -> literal paths
487+ # do not do any normalization, but return the path
488+ # unchanged apart from the call to os.fspath()
489+ return path
490+ path = path .replace (altsep , sep )
491+ prefix , path = splitdrive (path )
492+
493+ # collapse initial backslashes
494+ if path .startswith (sep ):
495+ prefix += sep
496+ path = path .lstrip (sep )
497+
498+ comps = path .split (sep )
499+ i = 0
500+ while i < len (comps ):
501+ if not comps [i ] or comps [i ] == curdir :
503502 del comps [i ]
503+ elif comps [i ] == pardir :
504+ if i > 0 and comps [i - 1 ] != pardir :
505+ del comps [i - 1 :i + 1 ]
506+ i -= 1
507+ elif i == 0 and prefix .endswith (sep ):
508+ del comps [i ]
509+ else :
510+ i += 1
504511 else :
505512 i += 1
506- else :
507- i += 1
508- # If the path is now empty, substitute '.'
509- if not prefix and not comps :
510- comps .append (curdir )
511- return prefix + sep .join (comps )
513+ # If the path is now empty, substitute '.'
514+ if not prefix and not comps :
515+ comps .append (curdir )
516+ return prefix + sep .join (comps )
517+
518+ else :
519+ def normpath (path ):
520+ """Normalize path, eliminating double slashes, etc."""
521+ path = os .fspath (path )
522+ if isinstance (path , bytes ):
523+ return os .fsencode (_path_normpath (os .fsdecode (path ))) or b"."
524+ return _path_normpath (path ) or "."
525+
512526
513527def _abspath_fallback (path ):
514528 """Return the absolute version of a path as a fallback function in case
0 commit comments