Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/ntpath.py

    r2 r391  
    311311#       - %varname% is accepted.
    312312#       - varnames can be made out of letters, digits and the characters '_-'
    313 #         (though is not verifed in the ${varname} and %varname% cases)
     313#         (though is not verified in the ${varname} and %varname% cases)
    314314# XXX With COMMAND.COM you can use any characters in a variable name,
    315315# XXX except '^|<>='.
     
    400400    # Preserve unicode (if path is unicode)
    401401    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
    402408    path = path.replace("/", "\\")
    403409    prefix, path = splitdrive(path)
     
    478484                              sys.getwindowsversion()[3] >= 2)
    479485
     486def _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
    480494def relpath(path, start=curdir):
    481495    """Return a relative version of a path"""
     
    483497    if not path:
    484498        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))
    493510        else:
    494511            raise ValueError("path is on drive %s, start on drive %s"
    495                                                 % (path_list[0], start_list[0]))
     512                                                % (path_prefix, start_prefix))
    496513    # 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():
    499517            break
    500     else:
    501518        i += 1
    502519
     
    505522        return curdir
    506523    return join(*rel_list)
     524
     525try:
     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
     531except ImportError:
     532    # Use genericpath.isdir as imported above.
     533    pass
Note: See TracChangeset for help on using the changeset viewer.