Skip to content

Commit f9f5887

Browse files
authored
Add files via upload
1 parent d9f8f38 commit f9f5887

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

pycatfile.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"
@@ -865,6 +869,9 @@ def RemoveWindowsPath(dpath):
865869
"""
866870
if not dpath:
867871
return ""
872+
if(re.findall("^(file):///", dpath)):
873+
dparsed = urlparse(dpath)
874+
dpath = url2pathname(dparsed.path)
868875
# Accept bytes and decode safely
869876
if isinstance(dpath, (bytes, bytearray)):
870877
dpath = dpath.decode("utf-8", "ignore")
@@ -880,6 +887,9 @@ def NormalizeRelativePath(inpath):
880887
"""
881888
Ensures the path is relative unless it is absolute. Prepares consistent relative paths.
882889
"""
890+
if(re.findall("^(file):///", inpath)):
891+
dparsed = urlparse(inpath)
892+
inpath = url2pathname(dparsed.path)
883893
inpath = RemoveWindowsPath(inpath)
884894
if os.path.isabs(inpath):
885895
outpath = inpath
@@ -922,6 +932,9 @@ def ListDir(dirpath, followlink=False, duplicates=False, include_regex=None, exc
922932
Returns:
923933
list: A list of files and directories matching the criteria.
924934
"""
935+
if(re.findall("^(file):///", dirpath)):
936+
dparsed = urlparse(dirpath)
937+
dirpath = url2pathname(dparsed.path)
925938
try:
926939
if os.stat not in os.supports_follow_symlinks and followlink:
927940
followlink = False
@@ -992,6 +1005,9 @@ def ListDirAdvanced(dirpath, followlink=False, duplicates=False, include_regex=N
9921005
Returns:
9931006
list: A list of files and directories matching the criteria.
9941007
"""
1008+
if(re.findall("^(file):///", dirpath)):
1009+
dparsed = urlparse(dirpath)
1010+
dirpath = url2pathname(dparsed.path)
9951011
try:
9961012
if os.stat not in os.supports_follow_symlinks and followlink:
9971013
followlink = False

0 commit comments

Comments
 (0)