Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-101000: Add os.path.splitroot()#101002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
21c0ba9836b85dbc2d1f9ecdc40d6592b2778f42279726ca47a6613c26a8dba0c237d411ed3eb2c9eed88299e9627ffe379beff2abacdee14ebe5452927afeb0aa73e19777d632e212e37cded35a8dfce0e75a553663237053729d694f093e99e3cdf618a001c522c9df17269File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -117,19 +117,21 @@ def join(path, *paths): | ||
| try: | ||
| if not paths: | ||
| path[:0] + sep #23780: Ensure compatible data type even if p is null. | ||
| result_drive,result_root,result_path =splitroot(path) | ||
| for p in map(os.fspath, paths): | ||
| p_drive,p_root,p_path =splitroot(p) | ||
| ifp_root: | ||
| # Second path is absolute | ||
| if p_drive or not result_drive: | ||
| result_drive = p_drive | ||
| result_root = p_root | ||
| result_path = p_path | ||
| continue | ||
| elif p_drive and p_drive != result_drive: | ||
| if p_drive.lower() != result_drive.lower(): | ||
| # Different drives => ignore the first path entirely | ||
| result_drive = p_drive | ||
| result_root = p_root | ||
| result_path = p_path | ||
| continue | ||
| # Same drive in different case | ||
| @@ -139,10 +141,10 @@ def join(path, *paths): | ||
| result_path = result_path + sep | ||
| result_path = result_path + p_path | ||
| ## add separator between UNC and non-absolute path | ||
| if (result_path and notresult_root and | ||
| result_drive and result_drive[-1:] != colon): | ||
| return result_drive + sep + result_path | ||
| return result_drive +result_root +result_path | ||
| except (TypeError, AttributeError, BytesWarning): | ||
| genericpath._check_arg_types('join', path, *paths) | ||
| raise | ||
| @@ -235,15 +237,13 @@ def split(p): | ||
| Either part may be empty.""" | ||
| p = os.fspath(p) | ||
| seps = _get_bothseps(p) | ||
| d,r,p =splitroot(p) | ||
| # set i to index beyond p's last slash | ||
| i = len(p) | ||
| while i and p[i-1] not in seps: | ||
| i -= 1 | ||
| head, tail = p[:i], p[i:] # now tail has no slashes | ||
| return d + r + head.rstrip(seps), tail | ||
barneygale marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| # Split a path in root and extension. | ||
| @@ -334,10 +334,10 @@ def ismount(path): | ||
| path = os.fspath(path) | ||
| seps = _get_bothseps(path) | ||
| path = abspath(path) | ||
| drive,root, rest =splitroot(path) | ||
| ifdrive anddrive[0] in seps: | ||
| return not rest | ||
| ifroot andnot rest: | ||
| return True | ||
| if _getvolumepathname: | ||
| @@ -548,14 +548,9 @@ def normpath(path): | ||
| curdir = '.' | ||
| pardir = '..' | ||
| path = path.replace(altsep, sep) | ||
| drive, root,path =splitroot(path) | ||
| comps = path.lstrip(sep).split(sep) | ||
barneygale marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| i = 0 | ||
| while i < len(comps): | ||
| if not comps[i] or comps[i] == curdir: | ||
| @@ -564,16 +559,16 @@ def normpath(path): | ||
| if i > 0 and comps[i-1] != pardir: | ||
| del comps[i-1:i+1] | ||
| i -= 1 | ||
| elif i == 0 androot: | ||
| del comps[i] | ||
| else: | ||
| i += 1 | ||
| else: | ||
| i += 1 | ||
| # If the path is now empty, substitute '.' | ||
| if notdrive and not root and not comps: | ||
| comps.append(curdir) | ||
| returndrive + root + sep.join(comps) | ||
| else: | ||
| def normpath(path): | ||
| @@ -788,8 +783,8 @@ def relpath(path, start=None): | ||
| try: | ||
| start_abs = abspath(normpath(start)) | ||
| path_abs = abspath(normpath(path)) | ||
| start_drive,_,start_rest =splitroot(start_abs) | ||
| path_drive,_,path_rest =splitroot(path_abs) | ||
barneygale marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if normcase(start_drive) != normcase(path_drive): | ||
| raise ValueError("path is on mount %r, start on mount %r" % ( | ||
| path_drive, start_drive)) | ||
| @@ -839,21 +834,21 @@ def commonpath(paths): | ||
| curdir = '.' | ||
| try: | ||
| drivesplits = [splitroot(p.replace(altsep, sep).lower()) for p in paths] | ||
| split_paths = [p.split(sep) for d,r,p in drivesplits] | ||
| try: | ||
| isabs, = set(rfor d, r, p in drivesplits) | ||
| except ValueError: | ||
| raise ValueError("Can't mix absolute and relative paths") from None | ||
| # Check that all drive letters or UNC paths match. The check is made only | ||
| # now otherwise type errors for mixing strings and bytes would not be | ||
| # caught. | ||
| if len(set(d for d,r,p in drivesplits)) != 1: | ||
barneygale marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| raise ValueError("Paths don't have the same drive") | ||
| drive,root,path =splitroot(paths[0].replace(altsep, sep)) | ||
| common = path.split(sep) | ||
| common = [c for c in common if c and c != curdir] | ||
| @@ -867,8 +862,7 @@ def commonpath(paths): | ||
| else: | ||
| common = common[:len(s1)] | ||
| return drive + root + sep.join(common) | ||
| except (TypeError, AttributeError): | ||
| genericpath._check_arg_types('commonpath', *paths) | ||
| raise | ||