Skip to content

Commit 6640f7d

Browse files
committed
Small update
1 parent f5518da commit 6640f7d

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

pyarchivefile/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
@@ -4393,7 +4398,7 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", filestart=0, seekstart=
43934398
outfsize = fp.tell()
43944399
fp.seek(filestart, 0)
43954400
currentfilepos = fp.tell()
4396-
elif(re.findall(__download_proto_support__, infile)):
4401+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
43974402
fp = download_file_from_internet_file(infile)
43984403
try:
43994404
fp.seek(0, 2)
@@ -4510,7 +4515,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", filestart=0, seekstart=0
45104515
outfsize = fp.tell()
45114516
fp.seek(filestart, 0)
45124517
currentfilepos = fp.tell()
4513-
elif(re.findall(__download_proto_support__, infile)):
4518+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
45144519
fp = download_file_from_internet_file(infile)
45154520
try:
45164521
fp.seek(0, 2)
@@ -4775,7 +4780,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
47754780
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
47764781
fp = outfile
47774782
return MakeEmptyFilePointer(fp, fmttype, checksumtype, formatspecs, saltkey)
4778-
elif(re.findall(__upload_proto_support__, outfile)):
4783+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
47794784
fp = MkTempFile()
47804785
else:
47814786
fbasename = os.path.splitext(outfile)[0]
@@ -4804,7 +4809,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile
48044809
outvar = fp.read()
48054810
fp.close()
48064811
return outvar
4807-
elif(re.findall(__upload_proto_support__, outfile)):
4812+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
48084813
fp = CompressOpenFileAlt(
48094814
fp, compression, compressionlevel, compressionuselist, formatspecs)
48104815
fp.seek(0, 0)
@@ -5271,7 +5276,7 @@ def AppendFilesWithContentFromTarFileToList(infile, extradata=[], jsondata={}, c
52715276
if(not infile):
52725277
return False
52735278
infile.seek(0, 0)
5274-
elif(re.findall(__download_proto_support__, infile)):
5279+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
52755280
infile = download_file_from_internet_file(infile)
52765281
infile.seek(0, 0)
52775282
if(not infile):
@@ -5499,7 +5504,7 @@ def AppendFilesWithContentFromZipFileToList(infile, extradata=[], jsondata={}, c
54995504
if(not infile):
55005505
return False
55015506
infile.seek(0, 0)
5502-
elif(re.findall(__download_proto_support__, infile)):
5507+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
55035508
infile = download_file_from_internet_file(infile)
55045509
infile.seek(0, 0)
55055510
if(not infile):
@@ -6308,7 +6313,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
63086313
fp = MkTempFile()
63096314
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
63106315
fp = outfile
6311-
elif(re.findall(__upload_proto_support__, outfile)):
6316+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
63126317
fp = MkTempFile()
63136318
else:
63146319
fbasename = os.path.splitext(outfile)[0]
@@ -6337,7 +6342,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt
63376342
outvar = fp.read()
63386343
fp.close()
63396344
return outvar
6340-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6345+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
63416346
fp = CompressOpenFileAlt(
63426347
fp, compression, compressionlevel, compressionuselist, formatspecs)
63436348
fp.seek(0, 0)
@@ -6393,7 +6398,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
63936398
fp = MkTempFile()
63946399
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
63956400
fp = outfile
6396-
elif(re.findall(__upload_proto_support__, outfile)):
6401+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
63976402
fp = MkTempFile()
63986403
else:
63996404
fbasename = os.path.splitext(outfile)[0]
@@ -6422,7 +6427,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty
64226427
outvar = fp.read()
64236428
fp.close()
64246429
return outvar
6425-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6430+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
64266431
fp = CompressOpenFileAlt(
64276432
fp, compression, compressionlevel, compressionuselist, formatspecs)
64286433
fp.seek(0, 0)
@@ -6498,7 +6503,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr
64986503
fp = MkTempFile()
64996504
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
65006505
fp = outfile
6501-
elif(re.findall(__upload_proto_support__, outfile)):
6506+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
65026507
fp = MkTempFile()
65036508
else:
65046509
fbasename = os.path.splitext(outfile)[0]
@@ -6527,7 +6532,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr
65276532
outvar = fp.read()
65286533
fp.close()
65296534
return outvar
6530-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6535+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
65316536
fp = CompressOpenFileAlt(
65326537
fp, compression, compressionlevel, compressionuselist, formatspecs)
65336538
fp.seek(0, 0)
@@ -6585,7 +6590,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto",
65856590
fp = MkTempFile()
65866591
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
65876592
fp = outfile
6588-
elif(re.findall(__upload_proto_support__, outfile)):
6593+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
65896594
fp = MkTempFile()
65906595
else:
65916596
fbasename = os.path.splitext(outfile)[0]
@@ -6614,7 +6619,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto",
66146619
outvar = fp.read()
66156620
fp.close()
66166621
return outvar
6617-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6622+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
66186623
fp = CompressOpenFileAlt(
66196624
fp, compression, compressionlevel, compressionuselist, formatspecs)
66206625
fp.seek(0, 0)
@@ -6672,7 +6677,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto",
66726677
fp = MkTempFile()
66736678
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
66746679
fp = outfile
6675-
elif(re.findall(__upload_proto_support__, outfile)):
6680+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
66766681
fp = MkTempFile()
66776682
else:
66786683
fbasename = os.path.splitext(outfile)[0]
@@ -6701,7 +6706,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto",
67016706
outvar = fp.read()
67026707
fp.close()
67036708
return outvar
6704-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6709+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
67056710
fp = CompressOpenFileAlt(
67066711
fp, compression, compressionlevel, compressionuselist, formatspecs)
67076712
fp.seek(0, 0)
@@ -6763,7 +6768,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto",
67636768
fp = MkTempFile()
67646769
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
67656770
fp = outfile
6766-
elif(re.findall(__upload_proto_support__, outfile)):
6771+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
67676772
fp = MkTempFile()
67686773
else:
67696774
fbasename = os.path.splitext(outfile)[0]
@@ -6792,7 +6797,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto",
67926797
outvar = fp.read()
67936798
fp.close()
67946799
return outvar
6795-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6800+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
67966801
fp = CompressOpenFileAlt(
67976802
fp, compression, compressionlevel, compressionuselist, formatspecs)
67986803
fp.seek(0, 0)
@@ -6854,7 +6859,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a
68546859
fp = MkTempFile()
68556860
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
68566861
fp = outfile
6857-
elif(re.findall(__upload_proto_support__, outfile)):
6862+
elif(re.findall(__upload_proto_support__, outfile) and pywwwget):
68586863
fp = MkTempFile()
68596864
else:
68606865
fbasename = os.path.splitext(outfile)[0]
@@ -6883,7 +6888,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a
68836888
outvar = fp.read()
68846889
fp.close()
68856890
return outvar
6886-
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile)):
6891+
elif((not hasattr(outfile, "read") and not hasattr(outfile, "write")) and re.findall(__upload_proto_support__, outfile) and pywwwget):
68876892
fp = CompressOpenFileAlt(
68886893
fp, compression, compressionlevel, compressionuselist, formatspecs)
68896894
fp.seek(0, 0)
@@ -7128,7 +7133,7 @@ def ArchiveFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_
71287133
if(not fp):
71297134
return False
71307135
fp.seek(filestart, 0)
7131-
elif(re.findall(__download_proto_support__, infile)):
7136+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
71327137
fp = download_file_from_internet_file(infile)
71337138
fp = UncompressFileAlt(fp, formatspecs, filestart)
71347139
compresscheck = CheckCompressionType(fp, formatspecs, 0, False)
@@ -8065,7 +8070,7 @@ def RePackArchiveFile(infile, outfile, fmttype="auto", compression="auto", compr
80658070
pass
80668071
return outvar
80678072
elif ((not hasattr(outfile, "read") and not hasattr(outfile, "write"))
8068-
and re.findall(__upload_proto_support__, outfile)):
8073+
and re.findall(__upload_proto_support__, outfile) and pywwwget):
80698074
fp = CompressOpenFileAlt(fp, compression, compressionlevel, compressionuselist, formatspecs)
80708075
fp.seek(0, 0)
80718076
upload_file_to_internet_file(fp, outfile)
@@ -8508,7 +8513,7 @@ def TarFileListFiles(infile, formatspecs=__file_format_multi_dict__, verbose=Fal
85088513
if(not infile):
85098514
return False
85108515
infile.seek(0, 0)
8511-
elif(re.findall(__download_proto_support__, infile)):
8516+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
85128517
infile = download_file_from_internet_file(infile)
85138518
infile.seek(0, 0)
85148519
if(not infile):
@@ -8630,7 +8635,7 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
86308635
if(not infile):
86318636
return False
86328637
infile.seek(0, 0)
8633-
elif(re.findall(__download_proto_support__, infile)):
8638+
elif(re.findall(__download_proto_support__, infile) and pywwwget):
86348639
infile = download_file_from_internet_file(infile)
86358640
infile.seek(0, 0)
86368641
if(not infile):

0 commit comments

Comments
 (0)