Skip to content

Commit f6b2509

Browse files
committed
Small update
1 parent e94960e commit f6b2509

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

pycatfile/pyfile.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
import hashlib
1717
import inspect
1818
import tempfile
19-
from .pywwwget import upload_file_to_internet_file, download_file_from_internet_file
19+
pywwwget = False
20+
try:
21+
from .pywwwget import upload_file_to_internet_file, download_file_from_internet_file
22+
pywwwget = True
23+
except ImportError:
24+
pywwwget = False
2025
from io import open
2126

2227
# RAR file support
@@ -4399,7 +4404,7 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", filestart=0, seekstart=
43994404
outfsize = fp.tell()
44004405
fp.seek(filestart, 0)
44014406
currentfilepos = fp.tell()
4402-
elif(re.findall(__download_proto_support__, infile)):
4407+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
44034408
fp = download_file_from_internet_file(infile)
44044409
try:
44054410
fp.seek(0, 2)
@@ -4516,7 +4521,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", filestart=0, seekstart=0
45164521
outfsize = fp.tell()
45174522
fp.seek(filestart, 0)
45184523
currentfilepos = fp.tell()
4519-
elif(re.findall(__download_proto_support__, infile)):
4524+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
45204525
fp = download_file_from_internet_file(infile)
45214526
try:
45224527
fp.seek(0, 2)
@@ -4781,7 +4786,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
47814786
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
47824787
fp = outfile
47834788
return MakeEmptyFilePointer(fp, fmttype, checksumtype, formatspecs, saltkey)
4784-
elif(re.findall(__upload_proto_support__, outfile)):
4789+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
47854790
fp = MkTempFile()
47864791
else:
47874792
fbasename = os.path.splitext(outfile)[0]
@@ -4810,7 +4815,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
48104815
outvar = fp.read()
48114816
fp.close()
48124817
return outvar
4813-
elif(re.findall(__upload_proto_support__, outfile)):
4818+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
48144819
fp = CompressOpenFileAlt(
48154820
fp, compression, compressionlevel, compressionuselist, formatspecs)
48164821
fp.seek(0, 0)
@@ -5277,7 +5282,7 @@ def AppendFilesWithContentFromTarFileToList(infile, extradata=[], jsondata={}, c
52775282
if(not infile):
52785283
return False
52795284
infile.seek(0, 0)
5280-
elif(re.findall(__download_proto_support__, infile)):
5285+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
52815286
infile = download_file_from_internet_file(infile)
52825287
infile.seek(0, 0)
52835288
if(not infile):
@@ -5505,7 +5510,7 @@ def AppendFilesWithContentFromZipFileToList(infile, extradata=[], jsondata={}, c
55055510
if(not infile):
55065511
return False
55075512
infile.seek(0, 0)
5508-
elif(re.findall(__download_proto_support__, infile)):
5513+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
55095514
infile = download_file_from_internet_file(infile)
55105515
infile.seek(0, 0)
55115516
if(not infile):
@@ -6314,7 +6319,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
63146319
fp = MkTempFile()
63156320
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
63166321
fp = outfile
6317-
elif(re.findall(__upload_proto_support__, outfile)):
6322+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
63186323
fp = MkTempFile()
63196324
else:
63206325
fbasename = os.path.splitext(outfile)[0]
@@ -6343,7 +6348,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
63436348
outvar = fp.read()
63446349
fp.close()
63456350
return outvar
6346-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6351+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
63476352
fp = CompressOpenFileAlt(
63486353
fp, compression, compressionlevel, compressionuselist, formatspecs)
63496354
fp.seek(0, 0)
@@ -6399,7 +6404,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
63996404
fp = MkTempFile()
64006405
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
64016406
fp = outfile
6402-
elif(re.findall(__upload_proto_support__, outfile)):
6407+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
64036408
fp = MkTempFile()
64046409
else:
64056410
fbasename = os.path.splitext(outfile)[0]
@@ -6428,7 +6433,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
64286433
outvar = fp.read()
64296434
fp.close()
64306435
return outvar
6431-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6436+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
64326437
fp = CompressOpenFileAlt(
64336438
fp, compression, compressionlevel, compressionuselist, formatspecs)
64346439
fp.seek(0, 0)
@@ -6504,7 +6509,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr
65046509
fp = MkTempFile()
65056510
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
65066511
fp = outfile
6507-
elif(re.findall(__upload_proto_support__, outfile)):
6512+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
65086513
fp = MkTempFile()
65096514
else:
65106515
fbasename = os.path.splitext(outfile)[0]
@@ -6533,7 +6538,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr
65336538
outvar = fp.read()
65346539
fp.close()
65356540
return outvar
6536-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6541+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
65376542
fp = CompressOpenFileAlt(
65386543
fp, compression, compressionlevel, compressionuselist, formatspecs)
65396544
fp.seek(0, 0)
@@ -6591,7 +6596,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto",
65916596
fp = MkTempFile()
65926597
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
65936598
fp = outfile
6594-
elif(re.findall(__upload_proto_support__, outfile)):
6599+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
65956600
fp = MkTempFile()
65966601
else:
65976602
fbasename = os.path.splitext(outfile)[0]
@@ -6620,7 +6625,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto",
66206625
outvar = fp.read()
66216626
fp.close()
66226627
return outvar
6623-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6628+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
66246629
fp = CompressOpenFileAlt(
66256630
fp, compression, compressionlevel, compressionuselist, formatspecs)
66266631
fp.seek(0, 0)
@@ -6678,7 +6683,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto",
66786683
fp = MkTempFile()
66796684
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
66806685
fp = outfile
6681-
elif(re.findall(__upload_proto_support__, outfile)):
6686+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
66826687
fp = MkTempFile()
66836688
else:
66846689
fbasename = os.path.splitext(outfile)[0]
@@ -6707,7 +6712,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto",
67076712
outvar = fp.read()
67086713
fp.close()
67096714
return outvar
6710-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6715+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
67116716
fp = CompressOpenFileAlt(
67126717
fp, compression, compressionlevel, compressionuselist, formatspecs)
67136718
fp.seek(0, 0)
@@ -6769,7 +6774,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto",
67696774
fp = MkTempFile()
67706775
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
67716776
fp = outfile
6772-
elif(re.findall(__upload_proto_support__, outfile)):
6777+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
67736778
fp = MkTempFile()
67746779
else:
67756780
fbasename = os.path.splitext(outfile)[0]
@@ -6798,7 +6803,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto",
67986803
outvar = fp.read()
67996804
fp.close()
68006805
return outvar
6801-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6806+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
68026807
fp = CompressOpenFileAlt(
68036808
fp, compression, compressionlevel, compressionuselist, formatspecs)
68046809
fp.seek(0, 0)
@@ -6860,7 +6865,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a
68606865
fp = MkTempFile()
68616866
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
68626867
fp = outfile
6863-
elif(re.findall(__upload_proto_support__, outfile)):
6868+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
68646869
fp = MkTempFile()
68656870
else:
68666871
fbasename = os.path.splitext(outfile)[0]
@@ -6889,7 +6894,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a
68896894
outvar = fp.read()
68906895
fp.close()
68916896
return outvar
6892-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6897+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
68936898
fp = CompressOpenFileAlt(
68946899
fp, compression, compressionlevel, compressionuselist, formatspecs)
68956900
fp.seek(0, 0)
@@ -7134,7 +7139,7 @@ def CatFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_form
71347139
if(not fp):
71357140
return False
71367141
fp.seek(filestart, 0)
7137-
elif(re.findall(__download_proto_support__, infile)):
7142+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
71387143
fp = download_file_from_internet_file(infile)
71397144
fp = UncompressFileAlt(fp, formatspecs, filestart)
71407145
compresscheck = CheckCompressionType(fp, formatspecs, 0, False)
@@ -8071,7 +8076,7 @@ def RePackCatFile(infile, outfile, fmttype="auto", compression="auto", compressw
80718076
pass
80728077
return outvar
80738078
elif ((not hasattr(outfile, "read") and not hasattr(outfile, "write"))
8074-
and re.findall(__upload_proto_support__, outfile)):
8079+
and re.findall(__upload_proto_support__, outfile) and pywwwget):
80758080
fp = CompressOpenFileAlt(fp, compression, compressionlevel, compressionuselist, formatspecs)
80768081
fp.seek(0, 0)
80778082
upload_file_to_internet_file(fp, outfile)
@@ -8514,7 +8519,7 @@ def TarFileListFiles(infile, formatspecs=__file_format_multi_dict__, verbose=Fal
85148519
if(not infile):
85158520
return False
85168521
infile.seek(0, 0)
8517-
elif(re.findall(__download_proto_support__, infile)):
8522+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
85188523
infile = download_file_from_internet_file(infile)
85198524
infile.seek(0, 0)
85208525
if(not infile):
@@ -8636,7 +8641,7 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
86368641
if(not infile):
86378642
return False
86388643
infile.seek(0, 0)
8639-
elif(re.findall(__download_proto_support__, infile)):
8644+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
86408645
infile = download_file_from_internet_file(infile)
86418646
infile.seek(0, 0)
86428647
if(not infile):

0 commit comments

Comments
 (0)