|
16 | 16 | import hashlib |
17 | 17 | import inspect |
18 | 18 | 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 |
20 | 25 | from io import open |
21 | 26 |
|
22 | 27 | # RAR file support |
@@ -4393,7 +4398,7 @@ def ReadInFileWithContentToArray(infile, fmttype="auto", filestart=0, seekstart= |
4393 | 4398 | outfsize = fp.tell() |
4394 | 4399 | fp.seek(filestart, 0) |
4395 | 4400 | currentfilepos = fp.tell() |
4396 | | - elif(re.findall(__download_proto_support__, infile)): |
| 4401 | + elif(re.findall(__download_proto_support__, infile) and pywwwget): |
4397 | 4402 | fp = download_file_from_internet_file(infile) |
4398 | 4403 | try: |
4399 | 4404 | fp.seek(0, 2) |
@@ -4510,7 +4515,7 @@ def ReadInFileWithContentToList(infile, fmttype="auto", filestart=0, seekstart=0 |
4510 | 4515 | outfsize = fp.tell() |
4511 | 4516 | fp.seek(filestart, 0) |
4512 | 4517 | currentfilepos = fp.tell() |
4513 | | - elif(re.findall(__download_proto_support__, infile)): |
| 4518 | + elif(re.findall(__download_proto_support__, infile) and pywwwget): |
4514 | 4519 | fp = download_file_from_internet_file(infile) |
4515 | 4520 | try: |
4516 | 4521 | fp.seek(0, 2) |
@@ -4775,7 +4780,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile |
4775 | 4780 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
4776 | 4781 | fp = outfile |
4777 | 4782 | 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): |
4779 | 4784 | fp = MkTempFile() |
4780 | 4785 | else: |
4781 | 4786 | fbasename = os.path.splitext(outfile)[0] |
@@ -4804,7 +4809,7 @@ def MakeEmptyFile(outfile, fmttype="auto", compression="auto", compresswholefile |
4804 | 4809 | outvar = fp.read() |
4805 | 4810 | fp.close() |
4806 | 4811 | return outvar |
4807 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 4812 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
4808 | 4813 | fp = CompressOpenFileAlt( |
4809 | 4814 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
4810 | 4815 | fp.seek(0, 0) |
@@ -5271,7 +5276,7 @@ def AppendFilesWithContentFromTarFileToList(infile, extradata=[], jsondata={}, c |
5271 | 5276 | if(not infile): |
5272 | 5277 | return False |
5273 | 5278 | infile.seek(0, 0) |
5274 | | - elif(re.findall(__download_proto_support__, infile)): |
| 5279 | + elif(re.findall(__download_proto_support__, infile) and pywwwget): |
5275 | 5280 | infile = download_file_from_internet_file(infile) |
5276 | 5281 | infile.seek(0, 0) |
5277 | 5282 | if(not infile): |
@@ -5499,7 +5504,7 @@ def AppendFilesWithContentFromZipFileToList(infile, extradata=[], jsondata={}, c |
5499 | 5504 | if(not infile): |
5500 | 5505 | return False |
5501 | 5506 | infile.seek(0, 0) |
5502 | | - elif(re.findall(__download_proto_support__, infile)): |
| 5507 | + elif(re.findall(__download_proto_support__, infile) and pywwwget): |
5503 | 5508 | infile = download_file_from_internet_file(infile) |
5504 | 5509 | infile.seek(0, 0) |
5505 | 5510 | if(not infile): |
@@ -6308,7 +6313,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt |
6308 | 6313 | fp = MkTempFile() |
6309 | 6314 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
6310 | 6315 | fp = outfile |
6311 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 6316 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
6312 | 6317 | fp = MkTempFile() |
6313 | 6318 | else: |
6314 | 6319 | fbasename = os.path.splitext(outfile)[0] |
@@ -6337,7 +6342,7 @@ def AppendFilesWithContentToOutFile(infiles, outfile, dirlistfromtxt=False, fmtt |
6337 | 6342 | outvar = fp.read() |
6338 | 6343 | fp.close() |
6339 | 6344 | 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): |
6341 | 6346 | fp = CompressOpenFileAlt( |
6342 | 6347 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
6343 | 6348 | fp.seek(0, 0) |
@@ -6393,7 +6398,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty |
6393 | 6398 | fp = MkTempFile() |
6394 | 6399 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
6395 | 6400 | fp = outfile |
6396 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 6401 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
6397 | 6402 | fp = MkTempFile() |
6398 | 6403 | else: |
6399 | 6404 | fbasename = os.path.splitext(outfile)[0] |
@@ -6422,7 +6427,7 @@ def AppendListsWithContentToOutFile(inlist, outfile, dirlistfromtxt=False, fmtty |
6422 | 6427 | outvar = fp.read() |
6423 | 6428 | fp.close() |
6424 | 6429 | 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): |
6426 | 6431 | fp = CompressOpenFileAlt( |
6427 | 6432 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
6428 | 6433 | fp.seek(0, 0) |
@@ -6498,7 +6503,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr |
6498 | 6503 | fp = MkTempFile() |
6499 | 6504 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
6500 | 6505 | fp = outfile |
6501 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 6506 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
6502 | 6507 | fp = MkTempFile() |
6503 | 6508 | else: |
6504 | 6509 | fbasename = os.path.splitext(outfile)[0] |
@@ -6527,7 +6532,7 @@ def AppendReadInFileWithContentToOutFile(infiles, outfile, fmttype="auto", compr |
6527 | 6532 | outvar = fp.read() |
6528 | 6533 | fp.close() |
6529 | 6534 | 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): |
6531 | 6536 | fp = CompressOpenFileAlt( |
6532 | 6537 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
6533 | 6538 | fp.seek(0, 0) |
@@ -6585,7 +6590,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto", |
6585 | 6590 | fp = MkTempFile() |
6586 | 6591 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
6587 | 6592 | fp = outfile |
6588 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 6593 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
6589 | 6594 | fp = MkTempFile() |
6590 | 6595 | else: |
6591 | 6596 | fbasename = os.path.splitext(outfile)[0] |
@@ -6614,7 +6619,7 @@ def AppendFilesWithContentFromTarFileToOutFile(infiles, outfile, fmttype="auto", |
6614 | 6619 | outvar = fp.read() |
6615 | 6620 | fp.close() |
6616 | 6621 | 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): |
6618 | 6623 | fp = CompressOpenFileAlt( |
6619 | 6624 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
6620 | 6625 | fp.seek(0, 0) |
@@ -6672,7 +6677,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto", |
6672 | 6677 | fp = MkTempFile() |
6673 | 6678 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
6674 | 6679 | fp = outfile |
6675 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 6680 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
6676 | 6681 | fp = MkTempFile() |
6677 | 6682 | else: |
6678 | 6683 | fbasename = os.path.splitext(outfile)[0] |
@@ -6701,7 +6706,7 @@ def AppendFilesWithContentFromZipFileToOutFile(infiles, outfile, fmttype="auto", |
6701 | 6706 | outvar = fp.read() |
6702 | 6707 | fp.close() |
6703 | 6708 | 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): |
6705 | 6710 | fp = CompressOpenFileAlt( |
6706 | 6711 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
6707 | 6712 | fp.seek(0, 0) |
@@ -6763,7 +6768,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto", |
6763 | 6768 | fp = MkTempFile() |
6764 | 6769 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
6765 | 6770 | fp = outfile |
6766 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 6771 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
6767 | 6772 | fp = MkTempFile() |
6768 | 6773 | else: |
6769 | 6774 | fbasename = os.path.splitext(outfile)[0] |
@@ -6792,7 +6797,7 @@ def AppendFilesWithContentFromRarFileToOutFile(infiles, outfile, fmttype="auto", |
6792 | 6797 | outvar = fp.read() |
6793 | 6798 | fp.close() |
6794 | 6799 | 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): |
6796 | 6801 | fp = CompressOpenFileAlt( |
6797 | 6802 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
6798 | 6803 | fp.seek(0, 0) |
@@ -6854,7 +6859,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a |
6854 | 6859 | fp = MkTempFile() |
6855 | 6860 | elif(hasattr(outfile, "read") or hasattr(outfile, "write")): |
6856 | 6861 | fp = outfile |
6857 | | - elif(re.findall(__upload_proto_support__, outfile)): |
| 6862 | + elif(re.findall(__upload_proto_support__, outfile) and pywwwget): |
6858 | 6863 | fp = MkTempFile() |
6859 | 6864 | else: |
6860 | 6865 | fbasename = os.path.splitext(outfile)[0] |
@@ -6883,7 +6888,7 @@ def AppendFilesWithContentFromSevenZipFileToOutFile(infiles, outfile, fmttype="a |
6883 | 6888 | outvar = fp.read() |
6884 | 6889 | fp.close() |
6885 | 6890 | 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): |
6887 | 6892 | fp = CompressOpenFileAlt( |
6888 | 6893 | fp, compression, compressionlevel, compressionuselist, formatspecs) |
6889 | 6894 | fp.seek(0, 0) |
@@ -7128,7 +7133,7 @@ def ArchiveFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_ |
7128 | 7133 | if(not fp): |
7129 | 7134 | return False |
7130 | 7135 | fp.seek(filestart, 0) |
7131 | | - elif(re.findall(__download_proto_support__, infile)): |
| 7136 | + elif(re.findall(__download_proto_support__, infile) and pywwwget): |
7132 | 7137 | fp = download_file_from_internet_file(infile) |
7133 | 7138 | fp = UncompressFileAlt(fp, formatspecs, filestart) |
7134 | 7139 | compresscheck = CheckCompressionType(fp, formatspecs, 0, False) |
@@ -8065,7 +8070,7 @@ def RePackArchiveFile(infile, outfile, fmttype="auto", compression="auto", compr |
8065 | 8070 | pass |
8066 | 8071 | return outvar |
8067 | 8072 | 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): |
8069 | 8074 | fp = CompressOpenFileAlt(fp, compression, compressionlevel, compressionuselist, formatspecs) |
8070 | 8075 | fp.seek(0, 0) |
8071 | 8076 | upload_file_to_internet_file(fp, outfile) |
@@ -8508,7 +8513,7 @@ def TarFileListFiles(infile, formatspecs=__file_format_multi_dict__, verbose=Fal |
8508 | 8513 | if(not infile): |
8509 | 8514 | return False |
8510 | 8515 | infile.seek(0, 0) |
8511 | | - elif(re.findall(__download_proto_support__, infile)): |
| 8516 | + elif(re.findall(__download_proto_support__, infile) and pywwwget): |
8512 | 8517 | infile = download_file_from_internet_file(infile) |
8513 | 8518 | infile.seek(0, 0) |
8514 | 8519 | if(not infile): |
@@ -8630,7 +8635,7 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False): |
8630 | 8635 | if(not infile): |
8631 | 8636 | return False |
8632 | 8637 | infile.seek(0, 0) |
8633 | | - elif(re.findall(__download_proto_support__, infile)): |
| 8638 | + elif(re.findall(__download_proto_support__, infile) and pywwwget): |
8634 | 8639 | infile = download_file_from_internet_file(infile) |
8635 | 8640 | infile.seek(0, 0) |
8636 | 8641 | if(not infile): |
|
0 commit comments