Skip to content

Commit 62bd963

Browse files
committed
Small update
1 parent b01be79 commit 62bd963

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

pyfoxfile/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
@@ -4400,7 +4405,7 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", filestart=0, seekstart=
44004405
outfsize = fp.tell()
44014406
fp.seek(filestart, 0)
44024407
currentfilepos = fp.tell()
4403-
elif(re.findall(__download_proto_support__, infile)):
4408+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
44044409
fp = download_file_from_internet_file(infile)
44054410
try:
44064411
fp.seek(0, 2)
@@ -4517,7 +4522,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", filestart=0, seekstart=0
45174522
outfsize = fp.tell()
45184523
fp.seek(filestart, 0)
45194524
currentfilepos = fp.tell()
4520-
elif(re.findall(__download_proto_support__, infile)):
4525+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
45214526
fp = download_file_from_internet_file(infile)
45224527
try:
45234528
fp.seek(0, 2)
@@ -4782,7 +4787,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
47824787
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
47834788
fp = outfile
47844789
return MakeEmptyFilePointer(fp, fmttype, checksumtype, formatspecs, saltkey)
4785-
elif(re.findall(__upload_proto_support__, outfile)):
4790+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
47864791
fp = MkTempFile()
47874792
else:
47884793
fbasename = os.path.splitext(outfile)[0]
@@ -4811,7 +4816,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
48114816
outvar = fp.read()
48124817
fp.close()
48134818
return outvar
4814-
elif(re.findall(__upload_proto_support__, outfile)):
4819+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
48154820
fp = CompressOpenFileAlt(
48164821
fp, compression, compressionlevel, compressionuselist, formatspecs)
48174822
fp.seek(0, 0)
@@ -5278,7 +5283,7 @@ def AppendFilesWithContentFromTarFileToList(infile, extradata=[], jsondata={}, c
52785283
if(not infile):
52795284
return False
52805285
infile.seek(0, 0)
5281-
elif(re.findall(__download_proto_support__, infile)):
5286+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
52825287
infile = download_file_from_internet_file(infile)
52835288
infile.seek(0, 0)
52845289
if(not infile):
@@ -5506,7 +5511,7 @@ def AppendFilesWithContentFromZipFileToList(infile, extradata=[], jsondata={}, c
55065511
if(not infile):
55075512
return False
55085513
infile.seek(0, 0)
5509-
elif(re.findall(__download_proto_support__, infile)):
5514+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
55105515
infile = download_file_from_internet_file(infile)
55115516
infile.seek(0, 0)
55125517
if(not infile):
@@ -6315,7 +6320,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
63156320
fp = MkTempFile()
63166321
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
63176322
fp = outfile
6318-
elif(re.findall(__upload_proto_support__, outfile)):
6323+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
63196324
fp = MkTempFile()
63206325
else:
63216326
fbasename = os.path.splitext(outfile)[0]
@@ -6344,7 +6349,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
63446349
outvar = fp.read()
63456350
fp.close()
63466351
return outvar
6347-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6352+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
63486353
fp = CompressOpenFileAlt(
63496354
fp, compression, compressionlevel, compressionuselist, formatspecs)
63506355
fp.seek(0, 0)
@@ -6400,7 +6405,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
64006405
fp = MkTempFile()
64016406
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
64026407
fp = outfile
6403-
elif(re.findall(__upload_proto_support__, outfile)):
6408+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
64046409
fp = MkTempFile()
64056410
else:
64066411
fbasename = os.path.splitext(outfile)[0]
@@ -6429,7 +6434,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
64296434
outvar = fp.read()
64306435
fp.close()
64316436
return outvar
6432-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6437+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
64336438
fp = CompressOpenFileAlt(
64346439
fp, compression, compressionlevel, compressionuselist, formatspecs)
64356440
fp.seek(0, 0)
@@ -6505,7 +6510,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr
65056510
fp = MkTempFile()
65066511
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
65076512
fp = outfile
6508-
elif(re.findall(__upload_proto_support__, outfile)):
6513+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
65096514
fp = MkTempFile()
65106515
else:
65116516
fbasename = os.path.splitext(outfile)[0]
@@ -6534,7 +6539,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr
65346539
outvar = fp.read()
65356540
fp.close()
65366541
return outvar
6537-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6542+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
65386543
fp = CompressOpenFileAlt(
65396544
fp, compression, compressionlevel, compressionuselist, formatspecs)
65406545
fp.seek(0, 0)
@@ -6592,7 +6597,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto",
65926597
fp = MkTempFile()
65936598
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
65946599
fp = outfile
6595-
elif(re.findall(__upload_proto_support__, outfile)):
6600+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
65966601
fp = MkTempFile()
65976602
else:
65986603
fbasename = os.path.splitext(outfile)[0]
@@ -6621,7 +6626,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto",
66216626
outvar = fp.read()
66226627
fp.close()
66236628
return outvar
6624-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6629+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
66256630
fp = CompressOpenFileAlt(
66266631
fp, compression, compressionlevel, compressionuselist, formatspecs)
66276632
fp.seek(0, 0)
@@ -6679,7 +6684,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto",
66796684
fp = MkTempFile()
66806685
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
66816686
fp = outfile
6682-
elif(re.findall(__upload_proto_support__, outfile)):
6687+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
66836688
fp = MkTempFile()
66846689
else:
66856690
fbasename = os.path.splitext(outfile)[0]
@@ -6708,7 +6713,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto",
67086713
outvar = fp.read()
67096714
fp.close()
67106715
return outvar
6711-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6716+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
67126717
fp = CompressOpenFileAlt(
67136718
fp, compression, compressionlevel, compressionuselist, formatspecs)
67146719
fp.seek(0, 0)
@@ -6770,7 +6775,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto",
67706775
fp = MkTempFile()
67716776
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
67726777
fp = outfile
6773-
elif(re.findall(__upload_proto_support__, outfile)):
6778+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
67746779
fp = MkTempFile()
67756780
else:
67766781
fbasename = os.path.splitext(outfile)[0]
@@ -6799,7 +6804,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto",
67996804
outvar = fp.read()
68006805
fp.close()
68016806
return outvar
6802-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6807+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
68036808
fp = CompressOpenFileAlt(
68046809
fp, compression, compressionlevel, compressionuselist, formatspecs)
68056810
fp.seek(0, 0)
@@ -6861,7 +6866,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a
68616866
fp = MkTempFile()
68626867
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
68636868
fp = outfile
6864-
elif(re.findall(__upload_proto_support__, outfile)):
6869+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
68656870
fp = MkTempFile()
68666871
else:
68676872
fbasename = os.path.splitext(outfile)[0]
@@ -6890,7 +6895,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a
68906895
outvar = fp.read()
68916896
fp.close()
68926897
return outvar
6893-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6898+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
68946899
fp = CompressOpenFileAlt(
68956900
fp, compression, compressionlevel, compressionuselist, formatspecs)
68966901
fp.seek(0, 0)
@@ -7135,7 +7140,7 @@ def FoxFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_form
71357140
if(not fp):
71367141
return False
71377142
fp.seek(filestart, 0)
7138-
elif(re.findall(__download_proto_support__, infile)):
7143+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
71397144
fp = download_file_from_internet_file(infile)
71407145
fp = UncompressFileAlt(fp, formatspecs, filestart)
71417146
compresscheck = CheckCompressionType(fp, formatspecs, 0, False)
@@ -8072,7 +8077,7 @@ def RePackFoxFile(infile, outfile, fmttype="auto", compression="auto", compressw
80728077
pass
80738078
return outvar
80748079
elif ((not hasattr(outfile, "read") and not hasattr(outfile, "write"))
8075-
and re.findall(__upload_proto_support__, outfile)):
8080+
and re.findall(__upload_proto_support__, outfile) and pywwwget):
80768081
fp = CompressOpenFileAlt(fp, compression, compressionlevel, compressionuselist, formatspecs)
80778082
fp.seek(0, 0)
80788083
upload_file_to_internet_file(fp, outfile)
@@ -8515,7 +8520,7 @@ def TarFileListFiles(infile, formatspecs=__file_format_multi_dict__, verbose=Fal
85158520
if(not infile):
85168521
return False
85178522
infile.seek(0, 0)
8518-
elif(re.findall(__download_proto_support__, infile)):
8523+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
85198524
infile = download_file_from_internet_file(infile)
85208525
infile.seek(0, 0)
85218526
if(not infile):
@@ -8637,7 +8642,7 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
86378642
if(not infile):
86388643
return False
86398644
infile.seek(0, 0)
8640-
elif(re.findall(__download_proto_support__, infile)):
8645+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
86418646
infile = download_file_from_internet_file(infile)
86428647
infile.seek(0, 0)
86438648
if(not infile):

0 commit comments

Comments
 (0)