kopia lustrzana https://github.com/micropython/micropython-lib
os.path: refactor: use sep instead of literal /
Signed-off-by: Michael Hirsch <michael@scivision.dev>pull/730/head
rodzic
e6b89eafa3
commit
0c1524e540
|
@ -13,28 +13,28 @@ def normpath(s):
|
||||||
|
|
||||||
|
|
||||||
def abspath(s):
|
def abspath(s):
|
||||||
if s[0] != "/":
|
if s[0] != sep:
|
||||||
return os.getcwd() + "/" + s
|
return os.getcwd() + sep + s
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def join(*args):
|
def join(*args):
|
||||||
# TODO: this is non-compliant
|
# TODO: this is non-compliant
|
||||||
if type(args[0]) is bytes:
|
if type(args[0]) is bytes:
|
||||||
return b"/".join(args)
|
return bytes(sep).join(args)
|
||||||
else:
|
else:
|
||||||
return "/".join(args)
|
return sep.join(args)
|
||||||
|
|
||||||
|
|
||||||
def split(path):
|
def split(path):
|
||||||
if path == "":
|
if path == "":
|
||||||
return ("", "")
|
return ("", "")
|
||||||
r = path.rsplit("/", 1)
|
r = path.rsplit(sep, 1)
|
||||||
if len(r) == 1:
|
if len(r) == 1:
|
||||||
return ("", path)
|
return ("", path)
|
||||||
head = r[0] # .rstrip("/")
|
head = r[0] # .rstrip("/")
|
||||||
if not head:
|
if not head:
|
||||||
head = "/"
|
head = sep
|
||||||
return (head, r[1])
|
return (head, r[1])
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ def isdir(path):
|
||||||
|
|
||||||
|
|
||||||
def expanduser(s):
|
def expanduser(s):
|
||||||
if s == "~" or s.startswith("~/"):
|
if s == "~" or s.startswith("~" + sep):
|
||||||
h = os.getenv("HOME")
|
h = os.getenv("HOME")
|
||||||
return h + s[1:]
|
return h + s[1:]
|
||||||
if s[0] == "~":
|
if s[0] == "~":
|
||||||
|
|
Ładowanie…
Reference in New Issue