@@ -103,9 +103,13 @@ def to_text(s, encoding="utf-8", errors="ignore"):
103103
104104# URL Parsing
105105try :
106+ # Python 3
106107 from urllib .parse import urlparse , urlunparse , unquote
108+ from urllib .request import url2pathname
107109except ImportError :
108- from urlparse import urlparse , urlunparse , unquote
110+ # Python 2
111+ from urlparse import urlparse , urlunparse
112+ from urllib import unquote , url2pathname
109113
110114# Windows-specific setup
111115if os .name == "nt" :
@@ -265,8 +269,8 @@ def get_default_threads():
265269 # os.cpu_count() might not be available in some environments
266270 return 1
267271
268- __upload_proto_support__ = "^(ftp|ftps|sftp|scp):\\ / \\ /"
269- __download_proto_support__ = "^(http|https|ftp|ftps|sftp|scp):\\ / \\ /"
272+ __upload_proto_support__ = "^(ftp|ftps|sftp|scp):/ /"
273+ __download_proto_support__ = "^(http|https|ftp|ftps|sftp|scp):/ /"
270274__use_pysftp__ = False
271275if (not havepysftp ):
272276 __use_pysftp__ = False
@@ -852,6 +856,9 @@ def RemoveWindowsPath(dpath):
852856 """
853857 if not dpath :
854858 return ""
859+ if (re .findall ("^(file):///" , dpath )):
860+ dparsed = urlparse (dpath )
861+ dpath = url2pathname (dparsed .path )
855862 # Accept bytes and decode safely
856863 if isinstance (dpath , (bytes , bytearray )):
857864 dpath = dpath .decode ("utf-8" , "ignore" )
@@ -867,6 +874,9 @@ def NormalizeRelativePath(inpath):
867874 """
868875 Ensures the path is relative unless it is absolute. Prepares consistent relative paths.
869876 """
877+ if (re .findall ("^(file):///" , inpath )):
878+ dparsed = urlparse (inpath )
879+ inpath = url2pathname (dparsed .path )
870880 inpath = RemoveWindowsPath (inpath )
871881 if os .path .isabs (inpath ):
872882 outpath = inpath
@@ -909,6 +919,9 @@ def ListDir(dirpath, followlink=False, duplicates=False, include_regex=None, exc
909919 Returns:
910920 list: A list of files and directories matching the criteria.
911921 """
922+ if (re .findall ("^(file):///" , dirpath )):
923+ dparsed = urlparse (dirpath )
924+ dirpath = url2pathname (dparsed .path )
912925 try :
913926 if os .stat not in os .supports_follow_symlinks and followlink :
914927 followlink = False
@@ -979,6 +992,9 @@ def ListDirAdvanced(dirpath, followlink=False, duplicates=False, include_regex=N
979992 Returns:
980993 list: A list of files and directories matching the criteria.
981994 """
995+ if (re .findall ("^(file):///" , dirpath )):
996+ dparsed = urlparse (dirpath )
997+ dirpath = url2pathname (dparsed .path )
982998 try :
983999 if os .stat not in os .supports_follow_symlinks and followlink :
9841000 followlink = False
0 commit comments