Convert a path for use by the operating system. In particular, paths on Windows must receive a magic prefix and must be converted to Unicode before they are sent to the OS. To disable the magic prefix on Windows, set `prefix` to False---but only do this if you *really* know what you'
(path: PathLike, prefix: bool = True)
| 421 | |
| 422 | |
| 423 | def syspath(path: PathLike, prefix: bool = True) -> str: |
| 424 | """Convert a path for use by the operating system. In particular, |
| 425 | paths on Windows must receive a magic prefix and must be converted |
| 426 | to Unicode before they are sent to the OS. To disable the magic |
| 427 | prefix on Windows, set `prefix` to False---but only do this if you |
| 428 | *really* know what you're doing. |
| 429 | """ |
| 430 | str_path = os.fsdecode(path) |
| 431 | # Don't do anything if we're not on windows |
| 432 | if os.path.__name__ != "ntpath": |
| 433 | return str_path |
| 434 | |
| 435 | # Add the magic prefix if it isn't already there. |
| 436 | # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx |
| 437 | if prefix and not str_path.startswith(WINDOWS_MAGIC_PREFIX): |
| 438 | if str_path.startswith("\\\\"): |
| 439 | # UNC path. Final path should look like \\?\UNC\... |
| 440 | str_path = f"UNC{str_path[1:]}" |
| 441 | str_path = f"{WINDOWS_MAGIC_PREFIX}{str_path}" |
| 442 | |
| 443 | return str_path |
| 444 | |
| 445 | |
| 446 | def samefile(p1: bytes, p2: bytes) -> bool: |
no outgoing calls