-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重构path_lib以支持3.12 将AlistPath* 添加到 __init__.py 中。
- Loading branch information
Showing
7 changed files
with
1,930 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@File Name : alistpath.py | ||
@Author : LeeCQ | ||
@Date-Time : 2024/2/25 12:40 | ||
""" | ||
import os | ||
import posixpath | ||
|
||
from posixpath import * | ||
|
||
__all__ = [*posixpath.__all__, "splitroot"] | ||
|
||
|
||
def splitroot(p): | ||
"""Split a pathname into drive, root and tail. On Posix, drive is always | ||
empty; the root may be empty, a single slash, or two slashes. The tail | ||
contains anything after the root. For example: | ||
splitroot('foo/bar') == ('', '', 'foo/bar') | ||
splitroot('/foo/bar') == ('', '/', 'foo/bar') | ||
splitroot('//foo/bar') == ('', '//', 'foo/bar') | ||
splitroot('///foo/bar') == ('', '/', '//foo/bar') | ||
splitroot('http://server/path/to/file') == ('http://server', '/', 'path/to/file') | ||
""" | ||
p = os.fspath(p) | ||
if isinstance(p, bytes): | ||
sep = b"/" | ||
empty = b"" | ||
else: | ||
sep = "/" | ||
empty = "" | ||
|
||
if p.startswith("http://") or p.startswith("https://"): | ||
# Absolute path, e.g.: 'http://server/path/to/file' | ||
return "/".join(p.split("/", 3)[:3]), "/", p.split("/", 3)[-1] | ||
|
||
elif p[:1] != sep: | ||
# Relative path, e.g.: 'foo' | ||
return empty, empty, p | ||
|
||
elif p[1:2] != sep or p[2:3] == sep: | ||
# Absolute path, e.g.: '/foo', '///foo', '////foo', etc. | ||
return empty, sep, p[1:] | ||
|
||
else: | ||
# Precisely two leading slashes, e.g.: '//foo'. Implementation defined per POSIX, see | ||
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 | ||
return empty, p[:2], p[2:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.