Fix T47986: OBJ Import fails w/ imagepath encoding

This commit is contained in:
2016-03-29 18:22:35 +11:00
parent b1f918bcc5
commit 2fae1719f8
2 changed files with 31 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ __all__ = (
"extensions_audio",
"is_subdir",
"module_names",
"native_pathsep",
"reduce_dirs",
"relpath",
"resolve_ncase",
@@ -349,6 +350,28 @@ def basename(path):
return _os.path.basename(path[2:] if path[:2] in {"//", b"//"} else path)
def native_pathsep(path):
"""
Replace the path separator with the systems native ``os.sep``.
"""
if type(path) is str:
if _os.sep == "/":
return path.replace("\\", "/")
else:
if path.startswith("//"):
return "//" + path[2:].replace("/", "\\")
else:
return path.replace("/", "\\")
else: # bytes
if _os.sep == "/":
return path.replace(b"\\", b"/")
else:
if path.startswith(b"//"):
return b"//" + path[2:].replace(b"/", b"\\")
else:
return path.replace(b"/", b"\\")
def reduce_dirs(dirs):
"""
Given a sequence of directories, remove duplicates and