Skip to content

Commit 59e8e42

Browse files
authored
Add files via upload
1 parent 4cc6eac commit 59e8e42

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

pyfoxfile.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ def to_text(s, encoding="utf-8", errors="ignore"):
103103

104104
# URL Parsing
105105
try:
106+
# Python 3
106107
from urllib.parse import urlparse, urlunparse, unquote
108+
from urllib.request import url2pathname
107109
except 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
111115
if os.name == "nt":
@@ -267,8 +271,8 @@ def get_default_threads():
267271

268272

269273
__use_pysftp__ = False
270-
__upload_proto_support__ = "^(ftp|ftps|sftp|scp):\\/\\/"
271-
__download_proto_support__ = "^(http|https|ftp|ftps|sftp|scp):\\/\\/"
274+
__upload_proto_support__ = "^(ftp|ftps|sftp|scp)://"
275+
__download_proto_support__ = "^(http|https|ftp|ftps|sftp|scp)://"
272276
if(not havepysftp):
273277
__use_pysftp__ = False
274278
__use_http_lib__ = "httpx"
@@ -864,6 +868,9 @@ def RemoveWindowsPath(dpath):
864868
"""
865869
if not dpath:
866870
return ""
871+
if(re.findall("^(file):///", dpath)):
872+
dparsed = urlparse(dpath)
873+
dpath = url2pathname(dparsed.path)
867874
# Accept bytes and decode safely
868875
if isinstance(dpath, (bytes, bytearray)):
869876
dpath = dpath.decode("utf-8", "ignore")
@@ -879,6 +886,9 @@ def NormalizeRelativePath(inpath):
879886
"""
880887
Ensures the path is relative unless it is absolute. Prepares consistent relative paths.
881888
"""
889+
if(re.findall("^(file):///", inpath)):
890+
dparsed = urlparse(inpath)
891+
inpath = url2pathname(dparsed.path)
882892
inpath = RemoveWindowsPath(inpath)
883893
if os.path.isabs(inpath):
884894
outpath = inpath
@@ -921,6 +931,9 @@ def ListDir(dirpath, followlink=False, duplicates=False, include_regex=None, exc
921931
Returns:
922932
list: A list of files and directories matching the criteria.
923933
"""
934+
if(re.findall("^(file):///", dirpath)):
935+
dparsed = urlparse(dirpath)
936+
dirpath = url2pathname(dparsed.path)
924937
try:
925938
if os.stat not in os.supports_follow_symlinks and followlink:
926939
followlink = False
@@ -991,6 +1004,9 @@ def ListDirAdvanced(dirpath, followlink=False, duplicates=False, include_regex=N
9911004
Returns:
9921005
list: A list of files and directories matching the criteria.
9931006
"""
1007+
if(re.findall("^(file):///", dirpath)):
1008+
dparsed = urlparse(dirpath)
1009+
dirpath = url2pathname(dparsed.path)
9941010
try:
9951011
if os.stat not in os.supports_follow_symlinks and followlink:
9961012
followlink = False

0 commit comments

Comments
 (0)