Test whether a path is absolute
(s)
| 85 | # starts with a slash or backslash. |
| 86 | |
| 87 | def isabs(s): |
| 88 | """Test whether a path is absolute""" |
| 89 | s = os.fspath(s) |
| 90 | if isinstance(s, bytes): |
| 91 | sep = b'\\' |
| 92 | altsep = b'/' |
| 93 | colon_sep = b':\\' |
| 94 | else: |
| 95 | sep = '\\' |
| 96 | altsep = '/' |
| 97 | colon_sep = ':\\' |
| 98 | s = s[:3].replace(altsep, sep) |
| 99 | # Absolute: UNC, device, and paths with a drive and root. |
| 100 | # LEGACY BUG: isabs("/x") should be false since the path has no drive. |
| 101 | if s.startswith(sep) or s.startswith(colon_sep, 1): |
| 102 | return True |
| 103 | return False |
| 104 | |
| 105 | |
| 106 | # Join two (or more) paths. |
no test coverage detected