diff options
author | Georg Brandl <georg@python.org> | 2010-07-31 21:40:15 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-07-31 21:40:15 (GMT) |
commit | cfb68218b701e1bf73bb82e51dfc8446ab65452a (patch) | |
tree | 85088cd11d198eef87c824046d8fb41e1e77c588 /Lib/ntpath.py | |
parent | a8867b4173d03e7c321e9de8be529f3dd7e67abe (diff) | |
download | cpython-cfb68218b701e1bf73bb82e51dfc8446ab65452a.zip cpython-cfb68218b701e1bf73bb82e51dfc8446ab65452a.tar.gz cpython-cfb68218b701e1bf73bb82e51dfc8446ab65452a.tar.bz2 |
#7909: the prefixes \\.\ and \\?\ indicate special Windows paths, do not try to manipulate them. See http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx for details.
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r-- | Lib/ntpath.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index a6bcca4..ee7ac67 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -71,6 +71,12 @@ def _get_colon(path): else: return ':' +def _get_special(path): + if isinstance(path, bytes): + return (b'\\\\.\\', b'\\\\?\\') + else: + return ('\\\\.\\', '\\\\?\\') + # Normalize the case of a pathname and map slashes to backslashes. # Other normalizations (such as optimizing '../' away) are not done # (this is done by normpath). @@ -524,6 +530,13 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" sep = _get_sep(path) dotdot = _get_dot(path) * 2 + special_prefixes = _get_special(path) + if path.startswith(special_prefixes): + # in the case of paths with these prefixes: + # \\.\ -> device names + # \\?\ -> literal paths + # do not do any normalization, but return the path unchanged + return path path = path.replace(_get_altsep(path), sep) prefix, path = splitdrive(path) |