Skip to content

Commit 61f4f03

Browse files
authored
Add files via upload
1 parent 23e4ef6 commit 61f4f03

1 file changed

Lines changed: 30 additions & 28 deletions

File tree

pycatfile.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ def get_default_threads():
266266

267267

268268
__use_pysftp__ = False
269+
__upload_proto_support__ = "^(ftp|ftps|sftp):\\/\\/"
270+
__download_proto_support__ = "^(http|https|ftp|ftps|sftp):\\/\\/"
269271
if(not havepysftp):
270272
__use_pysftp__ = False
271273
__use_http_lib__ = "httpx"
@@ -2997,7 +2999,7 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", seekstart=0, seekend=0,
29972999
if(not fp):
29983000
return False
29993001
fp.seek(0, 0)
3000-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
3002+
elif(re.findall(__download_proto_support__, infile)):
30013003
fp = download_file_from_internet_file(infile)
30023004
fp.seek(0, 0)
30033005
compresscheck = CheckCompressionType(fp, formatspecs, False)
@@ -3185,7 +3187,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", seekstart=0, seekend=0,
31853187
if(not fp):
31863188
return False
31873189
fp.seek(0, 0)
3188-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
3190+
elif(re.findall(__download_proto_support__, infile)):
31893191
fp = download_file_from_internet_file(infile)
31903192
fp.seek(0, 0)
31913193
compresscheck = CheckCompressionType(fp, formatspecs, False)
@@ -3406,7 +3408,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
34063408
fp = MkTempFile()
34073409
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
34083410
fp = outfile
3409-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3411+
elif(re.findall(__upload_proto_support__, outfile)):
34103412
fp = MkTempFile()
34113413
else:
34123414
fbasename = os.path.splitext(outfile)[0]
@@ -3442,7 +3444,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
34423444
outvar = fp.read()
34433445
fp.close()
34443446
return outvar
3445-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3447+
elif(re.findall(__upload_proto_support__, outfile)):
34463448
fp = CompressOpenFileAlt(
34473449
fp, compression, compressionlevel, compressionuselist, formatspecs)
34483450
fp.seek(0, 0)
@@ -3955,7 +3957,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
39553957
fp = MkTempFile()
39563958
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
39573959
fp = outfile
3958-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3960+
elif(re.findall(__upload_proto_support__, outfile)):
39593961
fp = MkTempFile()
39603962
else:
39613963
fbasename = os.path.splitext(outfile)[0]
@@ -3992,7 +3994,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
39923994
outvar = fp.read()
39933995
fp.close()
39943996
return outvar
3995-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
3997+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
39963998
fp = CompressOpenFileAlt(
39973999
fp, compression, compressionlevel, compressionuselist, formatspecs)
39984000
fp.seek(0, 0)
@@ -4035,7 +4037,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
40354037
fp = MkTempFile()
40364038
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
40374039
fp = outfile
4038-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
4040+
elif(re.findall(__upload_proto_support__, outfile)):
40394041
fp = MkTempFile()
40404042
else:
40414043
fbasename = os.path.splitext(outfile)[0]
@@ -4072,7 +4074,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
40724074
outvar = fp.read()
40734075
fp.close()
40744076
return outvar
4075-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
4077+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
40764078
fp = CompressOpenFileAlt(
40774079
fp, compression, compressionlevel, compressionuselist, formatspecs)
40784080
fp.seek(0, 0)
@@ -5006,7 +5008,7 @@ def PackCatFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
50065008
fp = MkTempFile()
50075009
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
50085010
fp = outfile
5009-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5011+
elif(re.findall(__upload_proto_support__, outfile)):
50105012
fp = MkTempFile()
50115013
else:
50125014
fbasename = os.path.splitext(outfile)[0]
@@ -5335,7 +5337,7 @@ def PackCatFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compress
53355337
outvar = fp.read()
53365338
fp.close()
53375339
return outvar
5338-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5340+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
53395341
fp = CompressOpenFileAlt(
53405342
fp, compression, compressionlevel, compressionuselist, formatspecs)
53415343
fp.seek(0, 0)
@@ -5390,7 +5392,7 @@ def PackCatFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
53905392
fp = MkTempFile()
53915393
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
53925394
fp = outfile
5393-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5395+
elif(re.findall(__upload_proto_support__, outfile)):
53945396
fp = MkTempFile()
53955397
else:
53965398
fbasename = os.path.splitext(outfile)[0]
@@ -5419,7 +5421,7 @@ def PackCatFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
54195421
if(not infile):
54205422
return False
54215423
infile.seek(0, 0)
5422-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
5424+
elif(re.findall(__download_proto_support__, infile)):
54235425
infile = download_file_from_internet_file(infile)
54245426
infile.seek(0, 0)
54255427
if(not infile):
@@ -5636,7 +5638,7 @@ def PackCatFileFromTarFile(infile, outfile, fmttype="auto", compression="auto",
56365638
outvar = fp.read()
56375639
fp.close()
56385640
return outvar
5639-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5641+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
56405642
fp = CompressOpenFileAlt(
56415643
fp, compression, compressionlevel, compressionuselist, formatspecs)
56425644
fp.seek(0, 0)
@@ -5687,7 +5689,7 @@ def PackCatFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
56875689
fp = MkTempFile()
56885690
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
56895691
fp = outfile
5690-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5692+
elif(re.findall(__upload_proto_support__, outfile)):
56915693
fp = MkTempFile()
56925694
else:
56935695
fbasename = os.path.splitext(outfile)[0]
@@ -5716,7 +5718,7 @@ def PackCatFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
57165718
if(not infile):
57175719
return False
57185720
infile.seek(0, 0)
5719-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
5721+
elif(re.findall(__download_proto_support__, infile)):
57205722
infile = download_file_from_internet_file(infile)
57215723
infile.seek(0, 0)
57225724
if(not infile):
@@ -5930,7 +5932,7 @@ def PackCatFileFromZipFile(infile, outfile, fmttype="auto", compression="auto",
59305932
outvar = fp.read()
59315933
fp.close()
59325934
return outvar
5933-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5935+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
59345936
fp = CompressOpenFileAlt(
59355937
fp, compression, compressionlevel, compressionuselist, formatspecs)
59365938
fp.seek(0, 0)
@@ -5986,7 +5988,7 @@ def PackCatFileFromRarFile(infile, outfile, fmttype="auto", compression="auto",
59865988
fp = MkTempFile()
59875989
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
59885990
fp = outfile
5989-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
5991+
elif(re.findall(__upload_proto_support__, outfile)):
59905992
fp = MkTempFile()
59915993
else:
59925994
fbasename = os.path.splitext(outfile)[0]
@@ -6250,7 +6252,7 @@ def PackCatFileFromRarFile(infile, outfile, fmttype="auto", compression="auto",
62506252
outvar = fp.read()
62516253
fp.close()
62526254
return outvar
6253-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
6255+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
62546256
fp = CompressOpenFileAlt(
62556257
fp, compression, compressionlevel, compressionuselist, formatspecs)
62566258
fp.seek(0, 0)
@@ -6306,7 +6308,7 @@ def PackCatFileFromSevenZipFile(infile, outfile, fmttype="auto", compression="au
63066308
fp = MkTempFile()
63076309
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
63086310
fp = outfile
6309-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
6311+
elif(re.findall(__upload_proto_support__, outfile)):
63106312
fp = MkTempFile()
63116313
else:
63126314
fbasename = os.path.splitext(outfile)[0]
@@ -6504,7 +6506,7 @@ def PackCatFileFromSevenZipFile(infile, outfile, fmttype="auto", compression="au
65046506
outvar = fp.read()
65056507
fp.close()
65066508
return outvar
6507-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
6509+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
65086510
fp = CompressOpenFileAlt(
65096511
fp, compression, compressionlevel, compressionuselist, formatspecs)
65106512
fp.seek(0, 0)
@@ -6592,7 +6594,7 @@ def CatFileSeekToFileNum(infile, fmttype="auto", seekto=0, listonly=False, conte
65926594
if(not fp):
65936595
return False
65946596
fp.seek(0, 0)
6595-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
6597+
elif(re.findall(__download_proto_support__, infile)):
65966598
fp = download_file_from_internet_file(infile)
65976599
fp = UncompressFileAlt(fp, formatspecs)
65986600
compresscheck = CheckCompressionType(fp, formatspecs, False)
@@ -6907,7 +6909,7 @@ def CatFileSeekToFileName(infile, fmttype="auto", seekfile=None, listonly=False,
69076909
if(not fp):
69086910
return False
69096911
fp.seek(0, 0)
6910-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
6912+
elif(re.findall(__download_proto_support__, infile)):
69116913
fp = download_file_from_internet_file(infile)
69126914
fp = UncompressFileAlt(fp, formatspecs)
69136915
compresscheck = CheckCompressionType(fp, formatspecs, False)
@@ -7228,7 +7230,7 @@ def CatFileValidate(infile, fmttype="auto", formatspecs=__file_format_multi_dict
72287230
if(not fp):
72297231
return False
72307232
fp.seek(0, 0)
7231-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
7233+
elif(re.findall(__download_proto_support__, infile)):
72327234
fp = download_file_from_internet_file(infile)
72337235
fp = UncompressFileAlt(fp, formatspecs)
72347236
compresscheck = CheckCompressionType(fp, formatspecs, False)
@@ -7580,7 +7582,7 @@ def CatFileToArray(infile, fmttype="auto", seekstart=0, seekend=0, listonly=Fals
75807582
if(not fp):
75817583
return False
75827584
fp.seek(0, 0)
7583-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
7585+
elif(re.findall(__download_proto_support__, infile)):
75847586
fp = download_file_from_internet_file(infile)
75857587
fp = UncompressFileAlt(fp, formatspecs)
75867588
compresscheck = CheckCompressionType(fp, formatspecs, False)
@@ -8199,7 +8201,7 @@ def RePackCatFile(infile, outfile, fmttype="auto", compression="auto", compressw
81998201
fp = MkTempFile()
82008202
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
82018203
fp = outfile
8202-
elif(re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
8204+
elif(re.findall(__upload_proto_support__, outfile)):
82038205
fp = MkTempFile()
82048206
else:
82058207
fbasename = os.path.splitext(outfile)[0]
@@ -8427,7 +8429,7 @@ def RePackCatFile(infile, outfile, fmttype="auto", compression="auto", compressw
84278429
outvar = fp.read()
84288430
fp.close()
84298431
return outvar
8430-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall("^(ftp|ftps|sftp):\\/\\/", outfile)):
8432+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
84318433
fp = CompressOpenFileAlt(
84328434
fp, compression, compressionlevel, compressionuselist, formatspecs)
84338435
fp.seek(0, 0)
@@ -8807,7 +8809,7 @@ def TarFileListFiles(infile, verbose=False, returnfp=False):
88078809
if(not infile):
88088810
return False
88098811
infile.seek(0, 0)
8810-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
8812+
elif(re.findall(__download_proto_support__, infile)):
88118813
infile = download_file_from_internet_file(infile)
88128814
infile.seek(0, 0)
88138815
if(not infile):
@@ -8932,7 +8934,7 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
89328934
if(not infile):
89338935
return False
89348936
infile.seek(0, 0)
8935-
elif(re.findall("^(http|https|ftp|ftps|sftp):\\/\\/", infile)):
8937+
elif(re.findall(__download_proto_support__, infile)):
89368938
infile = download_file_from_internet_file(infile)
89378939
infile.seek(0, 0)
89388940
if(not infile):

0 commit comments

Comments
 (0)