diff options
author | Marc-André Lemburg <mal@egenix.com> | 2001-01-29 11:29:44 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2001-01-29 11:29:44 (GMT) |
commit | bf222c9f12c1078a5d41acf4f4ce77c1a976c67f (patch) | |
tree | 65b1986f23f545aa9553b0e2e4fec97433d4a153 /Lib | |
parent | fde66e1bcc4431a59f36bad0ca0dd7a848ce794b (diff) | |
download | cpython-bf222c9f12c1078a5d41acf4f4ce77c1a976c67f.zip cpython-bf222c9f12c1078a5d41acf4f4ce77c1a976c67f.tar.gz cpython-bf222c9f12c1078a5d41acf4f4ce77c1a976c67f.tar.bz2 |
Fixed posixpath.normpath() to respect two leading slashes, but
turn three or more into a single slash. (This is in sync with POSIX
susv2 according to Fredrik.)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/posixpath.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index fd870b7..31b3315 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -343,21 +343,26 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" if path == '': return '.' - initial_slash = (path[0] == '/') + initial_slashes = path.startswith('/') + # POSIX allows one or two initial slashes, but treats three or more + # as single slash. + if (initial_slashes and + path.startswith('//') and not path.startswith('///')): + initial_slashes = 2 comps = path.split('/') new_comps = [] for comp in comps: if comp in ('', '.'): continue - if (comp != '..' or (not initial_slash and not new_comps) or + if (comp != '..' or (not initial_slashes and not new_comps) or (new_comps and new_comps[-1] == '..')): new_comps.append(comp) elif new_comps: new_comps.pop() comps = new_comps path = '/'.join(comps) - if initial_slash: - path = '/' + path + if initial_slashes: + path = '/'*initial_slashes + path return path or '.' |