Changeset 391 for python/trunk/Lib/ntpath.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/ntpath.py
r2 r391 311 311 # - %varname% is accepted. 312 312 # - varnames can be made out of letters, digits and the characters '_-' 313 # (though is not verif ed in the ${varname} and %varname% cases)313 # (though is not verified in the ${varname} and %varname% cases) 314 314 # XXX With COMMAND.COM you can use any characters in a variable name, 315 315 # XXX except '^|<>='. … … 400 400 # Preserve unicode (if path is unicode) 401 401 backslash, dot = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.') 402 if path.startswith(('\\\\.\\', '\\\\?\\')): 403 # in the case of paths with these prefixes: 404 # \\.\ -> device names 405 # \\?\ -> literal paths 406 # do not do any normalization, but return the path unchanged 407 return path 402 408 path = path.replace("/", "\\") 403 409 prefix, path = splitdrive(path) … … 478 484 sys.getwindowsversion()[3] >= 2) 479 485 486 def _abspath_split(path): 487 abs = abspath(normpath(path)) 488 prefix, rest = splitunc(abs) 489 is_unc = bool(prefix) 490 if not is_unc: 491 prefix, rest = splitdrive(abs) 492 return is_unc, prefix, [x for x in rest.split(sep) if x] 493 480 494 def relpath(path, start=curdir): 481 495 """Return a relative version of a path""" … … 483 497 if not path: 484 498 raise ValueError("no path specified") 485 start_list = abspath(start).split(sep) 486 path_list = abspath(path).split(sep) 487 if start_list[0].lower() != path_list[0].lower(): 488 unc_path, rest = splitunc(path) 489 unc_start, rest = splitunc(start) 490 if bool(unc_path) ^ bool(unc_start): 491 raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)" 492 % (path, start)) 499 500 start_is_unc, start_prefix, start_list = _abspath_split(start) 501 path_is_unc, path_prefix, path_list = _abspath_split(path) 502 503 if path_is_unc ^ start_is_unc: 504 raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)" 505 % (path, start)) 506 if path_prefix.lower() != start_prefix.lower(): 507 if path_is_unc: 508 raise ValueError("path is on UNC root %s, start on UNC root %s" 509 % (path_prefix, start_prefix)) 493 510 else: 494 511 raise ValueError("path is on drive %s, start on drive %s" 495 % (path_ list[0], start_list[0]))512 % (path_prefix, start_prefix)) 496 513 # Work out how much of the filepath is shared by start and path. 497 for i in range(min(len(start_list), len(path_list))): 498 if start_list[i].lower() != path_list[i].lower(): 514 i = 0 515 for e1, e2 in zip(start_list, path_list): 516 if e1.lower() != e2.lower(): 499 517 break 500 else:501 518 i += 1 502 519 … … 505 522 return curdir 506 523 return join(*rel_list) 524 525 try: 526 # The genericpath.isdir implementation uses os.stat and checks the mode 527 # attribute to tell whether or not the path is a directory. 528 # This is overkill on Windows - just pass the path to GetFileAttributes 529 # and check the attribute from there. 530 from nt import _isdir as isdir 531 except ImportError: 532 # Use genericpath.isdir as imported above. 533 pass
Note:
See TracChangeset
for help on using the changeset viewer.