-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpywwwgetold.py
executable file
·6279 lines (6066 loc) · 357 KB
/
pywwwgetold.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
'''
This program is free software; you can redistribute it and/or modify
it under the terms of the Revised BSD License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Revised BSD License for more details.
Copyright 2016-2023 Game Maker 2k - https://github.com/GameMaker2k
Copyright 2016-2023 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: pywwwgetold.py - Last Update: 10/22/2024 Ver. 2.1.0 RC 1 - Author: cooldude2k $
'''
from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
import re
import os
import sys
import hashlib
import shutil
import platform
import tempfile
import urllib
import zlib
import time
import argparse
import subprocess
import socket
import email.utils
import datetime
import time
import logging as log
from ftplib import FTP, FTP_TLS
from base64 import b64encode
try:
from cgi import parse_qsl
except ImportError:
try:
from urlparse import parse_qsl
except ImportError:
from urllib.parse import parse_qsl
except (DeprecationWarning, TypeError):
try:
from urlparse import parse_qsl
except ImportError:
from urllib.parse import parse_qsl
haverequests = False
try:
import requests
haverequests = True
except ImportError:
haverequests = False
havemechanize = False
try:
import mechanize
havemechanize = True
except ImportError:
havemechanize = False
havepycurl = False
try:
import pycurl
havepycurl = True
except ImportError:
havepycurl = False
haveparamiko = False
try:
import paramiko
haveparamiko = True
except ImportError:
haveparamiko = False
havepysftp = False
try:
import pysftp
havepysftp = True
except ImportError:
havepysftp = False
haveurllib3 = False
try:
import urllib3
haveurllib3 = True
except ImportError:
haveurllib3 = False
havehttplib2 = False
try:
import httplib2
from httplib2 import HTTPConnectionWithTimeout, HTTPSConnectionWithTimeout
havehttplib2 = True
except ImportError:
havehttplib2 = False
havehttpx = False
try:
import httpx
havehttpx = True
except ImportError:
havehttpx = False
havehttpcore = False
try:
import httpcore
havehttpcore = True
except ImportError:
havehttpcore = False
haveaiohttp = False
try:
import aiohttp
haveaiohttp = True
except ImportError:
haveaiohttp = False
havebrotli = False
try:
import brotli
havebrotli = True
except ImportError:
havebrotli = False
havezstd = False
try:
import zstandard
havezstd = True
except ImportError:
havezstd = False
havelzma = False
try:
import lzma
havelzma = True
except ImportError:
havelzma = False
if(sys.version[0] == "2"):
try:
from io import StringIO, BytesIO
except ImportError:
try:
from cStringIO import StringIO
from cStringIO import StringIO as BytesIO
except ImportError:
from StringIO import StringIO
from StringIO import StringIO as BytesIO
# From http://python-future.org/compatible_idioms.html
from urlparse import urlparse, urlunparse, urlsplit, urlunsplit, urljoin
from urllib import urlencode
from urllib import urlopen as urlopenalt
from urllib2 import urlopen, Request, install_opener, HTTPError, URLError, build_opener, HTTPCookieProcessor
import urlparse
import cookielib
from httplib import HTTPConnection, HTTPSConnection
if(sys.version[0] >= "3"):
from io import StringIO, BytesIO
# From http://python-future.org/compatible_idioms.html
from urllib.parse import urlparse, urlunparse, urlsplit, urlunsplit, urljoin, urlencode
from urllib.request import urlopen, Request, install_opener, build_opener, HTTPCookieProcessor
from urllib.error import HTTPError, URLError
import urllib.parse as urlparse
import http.cookiejar as cookielib
from http.client import HTTPConnection, HTTPSConnection
__program_name__ = "PyWWW-Get"
__program_alt_name__ = "PyWWWGet"
__program_small_name__ = "wwwget"
__project__ = __program_name__
__project_url__ = "https://github.com/GameMaker2k/PyWWW-Get"
__version_info__ = (2, 1, 0, "RC 1", 1)
__version_date_info__ = (2024, 10, 22, "RC 1", 1)
__version_date__ = str(__version_date_info__[0])+"."+str(__version_date_info__[
1]).zfill(2)+"."+str(__version_date_info__[2]).zfill(2)
__revision__ = __version_info__[3]
__revision_id__ = "$Id$"
if(__version_info__[4] is not None):
__version_date_plusrc__ = __version_date__ + \
"-"+str(__version_date_info__[4])
if(__version_info__[4] is None):
__version_date_plusrc__ = __version_date__
if(__version_info__[3] is not None):
__version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(
__version_info__[2])+" "+str(__version_info__[3])
if(__version_info__[3] is None):
__version__ = str(
__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2])
tmpfileprefix = "py" + \
str(sys.version_info[0])+__program_small_name__ + \
str(__version_info__[0])+"-"
tmpfilesuffix = "-"
pytempdir = tempfile.gettempdir()
PyBitness = platform.architecture()
if(PyBitness == "32bit" or PyBitness == "32"):
PyBitness = "32"
elif(PyBitness == "64bit" or PyBitness == "64"):
PyBitness = "64"
else:
PyBitness = "32"
compression_supported_list = ['identity', 'gzip', 'deflate', 'bzip2']
if(havebrotli):
compression_supported_list.append('br')
if(havezstd):
compression_supported_list.append('zstd')
if(havelzma):
compression_supported_list.append('lzma')
compression_supported_list.append('xz')
compression_supported = ', '.join(compression_supported_list)
geturls_cj = cookielib.CookieJar()
windowsNT4_ua_string = "Windows NT 4.0"
windowsNT4_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "32", 'SEC-CH-UA-PLATFORM': "4.0.0"}
windows2k_ua_string = "Windows NT 5.0"
windows2k_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "32", 'SEC-CH-UA-PLATFORM': "5.0.0"}
windowsXP_ua_string = "Windows NT 5.1"
windowsXP_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "32", 'SEC-CH-UA-PLATFORM': "5.1.0"}
windowsXP64_ua_string = "Windows NT 5.2; Win64; x64"
windowsXP64_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "64", 'SEC-CH-UA-PLATFORM': "5.1.0"}
windows7_ua_string = "Windows NT 6.1; Win64; x64"
windows7_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "64", 'SEC-CH-UA-PLATFORM': "6.1.0"}
windows8_ua_string = "Windows NT 6.2; Win64; x64"
windows8_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "64", 'SEC-CH-UA-PLATFORM': "6.2.0"}
windows81_ua_string = "Windows NT 6.3; Win64; x64"
windows81_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "64", 'SEC-CH-UA-PLATFORM': "6.3.0"}
windows10_ua_string = "Windows NT 10.0; Win64; x64"
windows10_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "64", 'SEC-CH-UA-PLATFORM': "10.0.0"}
windows11_ua_string = "Windows NT 11.0; Win64; x64"
windows11_ua_addon = {'SEC-CH-UA-PLATFORM': "Windows", 'SEC-CH-UA-ARCH': "x86",
'SEC-CH-UA-BITNESS': "64", 'SEC-CH-UA-PLATFORM': "11.0.0"}
geturls_ua_firefox_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
"; rv:109.0) Gecko/20100101 Firefox/117.0"
geturls_ua_seamonkey_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
"; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.17"
geturls_ua_chrome_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
geturls_ua_chromium_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
") AppleWebKit/537.36 (KHTML, like Gecko) Chromium/117.0.0.0 Chrome/117.0.0.0 Safari/537.36"
geturls_ua_palemoon_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
"; rv:102.0) Gecko/20100101 Goanna/6.3 Firefox/102.0 PaleMoon/32.4.0.1"
geturls_ua_opera_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 OPR/102.0.0.0"
geturls_ua_vivaldi_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Vivaldi/6.2.3105.48"
geturls_ua_internet_explorer_windows7 = "Mozilla/5.0 (" + \
windows7_ua_string+"; Trident/7.0; rv:11.0) like Gecko"
geturls_ua_microsoft_edge_windows7 = "Mozilla/5.0 ("+windows7_ua_string + \
") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.31"
geturls_ua_pywwwget_python = "Mozilla/5.0 (compatible; {proname}/{prover}; +{prourl})".format(
proname=__project__, prover=__version__, prourl=__project_url__)
if(platform.python_implementation() != ""):
py_implementation = platform.python_implementation()
if(platform.python_implementation() == ""):
py_implementation = "Python"
geturls_ua_pywwwget_python_alt = "Mozilla/5.0 ({osver}; {archtype}; +{prourl}) {pyimp}/{pyver} (KHTML, like Gecko) {proname}/{prover}".format(osver=platform.system(
)+" "+platform.release(), archtype=platform.machine(), prourl=__project_url__, pyimp=py_implementation, pyver=platform.python_version(), proname=__project__, prover=__version__)
geturls_ua_googlebot_google = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
geturls_ua_googlebot_google_old = "Googlebot/2.1 (+http://www.google.com/bot.html)"
geturls_ua = geturls_ua_firefox_windows7
geturls_headers_firefox_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_firefox_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
geturls_headers_seamonkey_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_seamonkey_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
geturls_headers_chrome_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_chrome_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close", 'SEC-CH-UA': "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"", 'SEC-CH-UA-FULL-VERSION': "117.0.5938.63"}
geturls_headers_chrome_windows7.update(windows7_ua_addon)
geturls_headers_chromium_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_chromium_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close", 'SEC-CH-UA': "\"Chromium\";v=\"117\", \"Not;A=Brand\";v=\"24\"", 'SEC-CH-UA-FULL-VERSION': "117.0.5938.63"}
geturls_headers_chromium_windows7.update(windows7_ua_addon)
geturls_headers_palemoon_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_palemoon_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
geturls_headers_opera_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_opera_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close", 'SEC-CH-UA': "\"Chromium\";v=\"116\", \"Not;A=Brand\";v=\"8\", \"Opera\";v=\"102\"", 'SEC-CH-UA-FULL-VERSION': "102.0.4880.56"}
geturls_headers_opera_windows7.update(windows7_ua_addon)
geturls_headers_vivaldi_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_vivaldi_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close", 'SEC-CH-UA': "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Vivaldi\";v=\"6.2\"", 'SEC-CH-UA-FULL-VERSION': "6.2.3105.48"}
geturls_headers_vivaldi_windows7.update(windows7_ua_addon)
geturls_headers_internet_explorer_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_internet_explorer_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language':
"en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
geturls_headers_microsoft_edge_windows7 = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_microsoft_edge_windows7, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close", 'SEC-CH-UA': "\"Microsoft Edge\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"", 'SEC-CH-UA-FULL-VERSION': "117.0.2045.31"}
geturls_headers_microsoft_edge_windows7.update(windows7_ua_addon)
geturls_headers_pywwwget_python = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_pywwwget_python, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close",
'SEC-CH-UA': "\""+__project__+"\";v=\""+str(__version__)+"\", \"Not;A=Brand\";v=\"8\", \""+py_implementation+"\";v=\""+str(platform.release())+"\"", 'SEC-CH-UA-FULL-VERSION': str(__version__), 'SEC-CH-UA-PLATFORM': ""+py_implementation+"", 'SEC-CH-UA-ARCH': ""+platform.machine()+"", 'SEC-CH-UA-PLATFORM': str(__version__), 'SEC-CH-UA-BITNESS': str(PyBitness)}
geturls_headers_pywwwget_python_alt = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_pywwwget_python_alt, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close",
'SEC-CH-UA': "\""+__project__+"\";v=\""+str(__version__)+"\", \"Not;A=Brand\";v=\"8\", \""+py_implementation+"\";v=\""+str(platform.release())+"\"", 'SEC-CH-UA-FULL-VERSION': str(__version__), 'SEC-CH-UA-PLATFORM': ""+py_implementation+"", 'SEC-CH-UA-ARCH': ""+platform.machine()+"", 'SEC-CH-UA-PLATFORM': str(__version__), 'SEC-CH-UA-BITNESS': str(PyBitness)}
geturls_headers_googlebot_google = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_googlebot_google, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
geturls_headers_googlebot_google_old = {'Referer': "http://google.com/", 'User-Agent': geturls_ua_googlebot_google_old, 'Accept-Encoding': "none", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6",
'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}
geturls_headers = geturls_headers_firefox_windows7
geturls_download_sleep = 0
def verbose_printout(dbgtxt, outtype="log", dbgenable=True, dgblevel=20):
if(outtype == "print" and dbgenable):
print(dbgtxt)
return True
elif(outtype == "log" and dbgenable):
logging.info(dbgtxt)
return True
elif(outtype == "warning" and dbgenable):
logging.warning(dbgtxt)
return True
elif(outtype == "error" and dbgenable):
logging.error(dbgtxt)
return True
elif(outtype == "critical" and dbgenable):
logging.critical(dbgtxt)
return True
elif(outtype == "exception" and dbgenable):
logging.exception(dbgtxt)
return True
elif(outtype == "logalt" and dbgenable):
logging.log(dgblevel, dbgtxt)
return True
elif(outtype == "debug" and dbgenable):
logging.debug(dbgtxt)
return True
elif(not dbgenable):
return True
else:
return False
return False
def verbose_printout_return(dbgtxt, outtype="log", dbgenable=True, dgblevel=20):
dbgout = verbose_printout(dbgtxt, outtype, dbgenable, dgblevel)
if(not dbgout):
return False
return dbgtxt
def add_url_param(url, **params):
n = 3
parts = list(urlparse.urlsplit(url))
d = dict(parse_qsl(parts[n])) # use cgi.parse_qs for list values
d.update(params)
parts[n] = urlencode(d)
return urlparse.urlunsplit(parts)
os.environ["PATH"] = os.environ["PATH"] + os.pathsep + \
os.path.dirname(os.path.realpath(__file__)) + os.pathsep + os.getcwd()
def which_exec(execfile):
for path in os.environ["PATH"].split(":"):
if os.path.exists(path + "/" + execfile):
return path + "/" + execfile
def listize(varlist):
il = 0
ix = len(varlist)
ilx = 1
newlistreg = {}
newlistrev = {}
newlistfull = {}
while(il < ix):
newlistreg.update({ilx: varlist[il]})
newlistrev.update({varlist[il]: ilx})
ilx = ilx + 1
il = il + 1
newlistfull = {1: newlistreg, 2: newlistrev,
'reg': newlistreg, 'rev': newlistrev}
return newlistfull
def twolistize(varlist):
il = 0
ix = len(varlist)
ilx = 1
newlistnamereg = {}
newlistnamerev = {}
newlistdescreg = {}
newlistdescrev = {}
newlistfull = {}
while(il < ix):
newlistnamereg.update({ilx: varlist[il][0].strip()})
newlistnamerev.update({varlist[il][0].strip(): ilx})
newlistdescreg.update({ilx: varlist[il][1].strip()})
newlistdescrev.update({varlist[il][1].strip(): ilx})
ilx = ilx + 1
il = il + 1
newlistnametmp = {1: newlistnamereg, 2: newlistnamerev,
'reg': newlistnamereg, 'rev': newlistnamerev}
newlistdesctmp = {1: newlistdescreg, 2: newlistdescrev,
'reg': newlistdescreg, 'rev': newlistdescrev}
newlistfull = {1: newlistnametmp, 2: newlistdesctmp,
'name': newlistnametmp, 'desc': newlistdesctmp}
return newlistfull
def arglistize(proexec, *varlist):
il = 0
ix = len(varlist)
ilx = 1
newarglist = [proexec]
while(il < ix):
if varlist[il][0] is not None:
newarglist.append(varlist[il][0])
if varlist[il][1] is not None:
newarglist.append(varlist[il][1])
il = il + 1
return newarglist
def fix_header_names(header_dict):
if(sys.version[0] == "2"):
header_dict = {k.title(): v for k, v in header_dict.iteritems()}
if(sys.version[0] >= "3"):
header_dict = {k.title(): v for k, v in header_dict.items()}
return header_dict
# hms_string by ArcGIS Python Recipes
# https://arcpy.wordpress.com/2012/04/20/146/
def hms_string(sec_elapsed):
h = int(sec_elapsed / (60 * 60))
m = int((sec_elapsed % (60 * 60)) / 60)
s = sec_elapsed % 60.0
return "{}:{:>02}:{:>05.2f}".format(h, m, s)
# get_readable_size by Lipis
# http://stackoverflow.com/posts/14998888/revisions
def get_readable_size(bytes, precision=1, unit="IEC"):
unit = unit.upper()
if(unit != "IEC" and unit != "SI"):
unit = "IEC"
if(unit == "IEC"):
units = [" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB"]
unitswos = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"]
unitsize = 1024.0
if(unit == "SI"):
units = [" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB"]
unitswos = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"]
unitsize = 1000.0
return_val = {}
orgbytes = bytes
for unit in units:
if abs(bytes) < unitsize:
strformat = "%3."+str(precision)+"f%s"
pre_return_val = (strformat % (bytes, unit))
pre_return_val = re.sub(
r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
alt_return_val = pre_return_val.split()
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
return return_val
bytes /= unitsize
strformat = "%."+str(precision)+"f%s"
pre_return_val = (strformat % (bytes, "YiB"))
pre_return_val = re.sub(r"([0]+) ([A-Za-z]+)", r" \2", pre_return_val)
pre_return_val = re.sub(r"\. ([A-Za-z]+)", r" \1", pre_return_val)
alt_return_val = pre_return_val.split()
return_val = {'Bytes': orgbytes, 'ReadableWithSuffix': pre_return_val,
'ReadableWithoutSuffix': alt_return_val[0], 'ReadableSuffix': alt_return_val[1]}
return return_val
def get_readable_size_from_file(infile, precision=1, unit="IEC", usehashes=False, usehashtypes="md5,sha1"):
unit = unit.upper()
usehashtypes = usehashtypes.lower()
getfilesize = os.path.getsize(infile)
return_val = get_readable_size(getfilesize, precision, unit)
if(usehashes):
hashtypelist = usehashtypes.split(",")
openfile = open(infile, "rb")
filecontents = openfile.read()
openfile.close()
listnumcount = 0
listnumend = len(hashtypelist)
while(listnumcount < listnumend):
hashtypelistlow = hashtypelist[listnumcount].strip()
hashtypelistup = hashtypelistlow.upper()
filehash = hashlib.new(hashtypelistup)
filehash.update(filecontents)
filegethash = filehash.hexdigest()
return_val.update({hashtypelistup: filegethash})
listnumcount += 1
return return_val
def get_readable_size_from_string(instring, precision=1, unit="IEC", usehashes=False, usehashtypes="md5,sha1"):
unit = unit.upper()
usehashtypes = usehashtypes.lower()
getfilesize = len(instring)
return_val = get_readable_size(getfilesize, precision, unit)
if(usehashes):
hashtypelist = usehashtypes.split(",")
listnumcount = 0
listnumend = len(hashtypelist)
while(listnumcount < listnumend):
hashtypelistlow = hashtypelist[listnumcount].strip()
hashtypelistup = hashtypelistlow.upper()
filehash = hashlib.new(hashtypelistup)
if(sys.version[0] == "2"):
filehash.update(instring)
if(sys.version[0] >= "3"):
filehash.update(instring.encode('utf-8'))
filegethash = filehash.hexdigest()
return_val.update({hashtypelistup: filegethash})
listnumcount += 1
return return_val
def http_status_to_reason(code):
reasons = {
100: 'Continue',
101: 'Switching Protocols',
102: 'Processing',
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-Authoritative Information',
204: 'No Content',
205: 'Reset Content',
206: 'Partial Content',
207: 'Multi-Status',
208: 'Already Reported',
226: 'IM Used',
300: 'Multiple Choices',
301: 'Moved Permanently',
302: 'Found',
303: 'See Other',
304: 'Not Modified',
305: 'Use Proxy',
307: 'Temporary Redirect',
308: 'Permanent Redirect',
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required',
408: 'Request Timeout',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Failed',
413: 'Payload Too Large',
414: 'URI Too Long',
415: 'Unsupported Media Type',
416: 'Range Not Satisfiable',
417: 'Expectation Failed',
421: 'Misdirected Request',
422: 'Unprocessable Entity',
423: 'Locked',
424: 'Failed Dependency',
426: 'Upgrade Required',
428: 'Precondition Required',
429: 'Too Many Requests',
431: 'Request Header Fields Too Large',
451: 'Unavailable For Legal Reasons',
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Timeout',
505: 'HTTP Version Not Supported',
506: 'Variant Also Negotiates',
507: 'Insufficient Storage',
508: 'Loop Detected',
510: 'Not Extended',
511: 'Network Authentication Required'
}
return reasons.get(code, 'Unknown Status Code')
def ftp_status_to_reason(code):
reasons = {
110: 'Restart marker reply',
120: 'Service ready in nnn minutes',
125: 'Data connection already open; transfer starting',
150: 'File status okay; about to open data connection',
200: 'Command okay',
202: 'Command not implemented, superfluous at this site',
211: 'System status, or system help reply',
212: 'Directory status',
213: 'File status',
214: 'Help message',
215: 'NAME system type',
220: 'Service ready for new user',
221: 'Service closing control connection',
225: 'Data connection open; no transfer in progress',
226: 'Closing data connection',
227: 'Entering Passive Mode',
230: 'User logged in, proceed',
250: 'Requested file action okay, completed',
257: '"PATHNAME" created',
331: 'User name okay, need password',
332: 'Need account for login',
350: 'Requested file action pending further information',
421: 'Service not available, closing control connection',
425: 'Can\'t open data connection',
426: 'Connection closed; transfer aborted',
450: 'Requested file action not taken',
451: 'Requested action aborted. Local error in processing',
452: 'Requested action not taken. Insufficient storage space in system',
500: 'Syntax error, command unrecognized',
501: 'Syntax error in parameters or arguments',
502: 'Command not implemented',
503: 'Bad sequence of commands',
504: 'Command not implemented for that parameter',
530: 'Not logged in',
532: 'Need account for storing files',
550: 'Requested action not taken. File unavailable',
551: 'Requested action aborted. Page type unknown',
552: 'Requested file action aborted. Exceeded storage allocation',
553: 'Requested action not taken. File name not allowed'
}
return reasons.get(code, 'Unknown Status Code')
def sftp_status_to_reason(code):
reasons = {
0: 'SSH_FX_OK',
1: 'SSH_FX_EOF',
2: 'SSH_FX_NO_SUCH_FILE',
3: 'SSH_FX_PERMISSION_DENIED',
4: 'SSH_FX_FAILURE',
5: 'SSH_FX_BAD_MESSAGE',
6: 'SSH_FX_NO_CONNECTION',
7: 'SSH_FX_CONNECTION_LOST',
8: 'SSH_FX_OP_UNSUPPORTED'
}
return reasons.get(code, 'Unknown Status Code')
def make_http_headers_from_dict_to_list(headers={'Referer': "http://google.com/", 'User-Agent': geturls_ua, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}):
if isinstance(headers, dict):
returnval = []
if(sys.version[0] == "2"):
for headkey, headvalue in headers.iteritems():
returnval.append((headkey, headvalue))
if(sys.version[0] >= "3"):
for headkey, headvalue in headers.items():
returnval.append((headkey, headvalue))
elif isinstance(headers, list):
returnval = headers
else:
returnval = False
return returnval
def make_http_headers_from_dict_to_pycurl(headers={'Referer': "http://google.com/", 'User-Agent': geturls_ua, 'Accept-Encoding': compression_supported, 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}):
if isinstance(headers, dict):
returnval = []
if(sys.version[0] == "2"):
for headkey, headvalue in headers.iteritems():
returnval.append(headkey+": "+headvalue)
if(sys.version[0] >= "3"):
for headkey, headvalue in headers.items():
returnval.append(headkey+": "+headvalue)
elif isinstance(headers, list):
returnval = headers
else:
returnval = False
return returnval
def make_http_headers_from_pycurl_to_dict(headers):
header_dict = {}
headers = headers.strip().split('\r\n')
for header in headers:
parts = header.split(': ', 1)
if(len(parts) == 2):
key, value = parts
header_dict[key.title()] = value
return header_dict
def make_http_headers_from_list_to_dict(headers=[("Referer", "http://google.com/"), ("User-Agent", geturls_ua), ("Accept-Encoding", compression_supported), ("Accept-Language", "en-US,en;q=0.8,en-CA,en-GB;q=0.6"), ("Accept-Charset", "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7"), ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), ("Connection", "close")]):
if isinstance(headers, list):
returnval = {}
mli = 0
mlil = len(headers)
while(mli < mlil):
returnval.update({headers[mli][0]: headers[mli][1]})
mli = mli + 1
elif isinstance(headers, dict):
returnval = headers
else:
returnval = False
return returnval
def get_httplib_support(checkvalue=None):
global haverequests, havemechanize, havehttplib2, haveurllib3, havehttpx, havehttpcore, haveparamiko, havepysftp
returnval = []
returnval.append("ftp")
returnval.append("httplib")
if(havehttplib2):
returnval.append("httplib2")
returnval.append("urllib")
if(haveurllib3):
returnval.append("urllib3")
returnval.append("request3")
returnval.append("request")
if(haverequests):
returnval.append("requests")
if(haveaiohttp):
returnval.append("aiohttp")
if(havehttpx):
returnval.append("httpx")
returnval.append("httpx2")
if(havemechanize):
returnval.append("mechanize")
if(havepycurl):
returnval.append("pycurl")
if(hasattr(pycurl, "CURL_HTTP_VERSION_2_0")):
returnval.append("pycurl2")
if(hasattr(pycurl, "CURL_HTTP_VERSION_3_0")):
returnval.append("pycurl3")
if(haveparamiko):
returnval.append("sftp")
if(havepysftp):
returnval.append("pysftp")
if(not checkvalue is None):
if(checkvalue == "urllib1" or checkvalue == "urllib2"):
checkvalue = "urllib"
if(checkvalue == "httplib1"):
checkvalue = "httplib"
if(checkvalue in returnval):
returnval = True
else:
returnval = False
return returnval
def check_httplib_support(checkvalue="urllib"):
if(checkvalue == "urllib1" or checkvalue == "urllib2"):
checkvalue = "urllib"
if(checkvalue == "httplib1"):
checkvalue = "httplib"
returnval = get_httplib_support(checkvalue)
return returnval
def get_httplib_support_list():
returnval = get_httplib_support(None)
return returnval
def download_from_url(httpurl, httpheaders=geturls_headers, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", postdata=None, httplibuse="urllib", buffersize=524288, sleep=-1, timeout=10):
global geturls_download_sleep, havezstd, havebrotli, haveaiohttp, haverequests, havemechanize, havepycurl, havehttplib2, haveurllib3, havehttpx, havehttpcore, haveparamiko, havepysftp
if(sleep < 0):
sleep = geturls_download_sleep
if(timeout <= 0):
timeout = 10
if(httplibuse == "urllib1" or httplibuse == "urllib2" or httplibuse == "request"):
httplibuse = "urllib"
if(httplibuse == "httplib1"):
httplibuse = "httplib"
if(not haverequests and httplibuse == "requests"):
httplibuse = "urllib"
if(not haveaiohttp and httplibuse == "aiohttp"):
httplibuse = "urllib"
if(not havehttpx and httplibuse == "httpx"):
httplibuse = "urllib"
if(not havehttpx and httplibuse == "httpx2"):
httplibuse = "urllib"
if(not havehttpcore and httplibuse == "httpcore"):
httplibuse = "urllib"
if(not havehttpcore and httplibuse == "httpcore2"):
httplibuse = "urllib"
if(not havemechanize and httplibuse == "mechanize"):
httplibuse = "urllib"
if(not havepycurl and httplibuse == "pycurl"):
httplibuse = "urllib"
if(not havepycurl and httplibuse == "pycurl2"):
httplibuse = "urllib"
if(havepycurl and httplibuse == "pycurl2" and not hasattr(pycurl, "CURL_HTTP_VERSION_2_0")):
httplibuse = "pycurl"
if(not havepycurl and httplibuse == "pycurl3"):
httplibuse = "urllib"
if(havepycurl and httplibuse == "pycurl3" and not hasattr(pycurl, "CURL_HTTP_VERSION_3_0") and hasattr(pycurl, "CURL_HTTP_VERSION_2_0")):
httplibuse = "pycurl2"
if(havepycurl and httplibuse == "pycurl3" and not hasattr(pycurl, "CURL_HTTP_VERSION_3_0") and not hasattr(pycurl, "CURL_HTTP_VERSION_2_0")):
httplibuse = "pycurl"
if(not havehttplib2 and httplibuse == "httplib2"):
httplibuse = "httplib"
if(not haveparamiko and httplibuse == "sftp"):
httplibuse = "ftp"
if(not havepysftp and httplibuse == "pysftp"):
httplibuse = "ftp"
if(httplibuse == "urllib" or httplibuse == "request"):
returnval = download_from_url_with_urllib(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "request"):
returnval = download_from_url_with_request(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "request3"):
returnval = download_from_url_with_request3(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "httplib"):
returnval = download_from_url_with_httplib(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "httplib2"):
returnval = download_from_url_with_httplib2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "urllib3" or httplibuse == "request3"):
returnval = download_from_url_with_urllib3(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "requests"):
returnval = download_from_url_with_requests(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "aiohttp"):
returnval = download_from_url_with_aiohttp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "httpx"):
returnval = download_from_url_with_httpx(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "httpx2"):
returnval = download_from_url_with_httpx2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "httpcore"):
returnval = download_from_url_with_httpcore(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "httpcore2"):
returnval = download_from_url_with_httpcore2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "mechanize"):
returnval = download_from_url_with_mechanize(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "pycurl"):
returnval = download_from_url_with_pycurl(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "pycurl2"):
returnval = download_from_url_with_pycurl2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "pycurl3"):
returnval = download_from_url_with_pycurl3(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "ftp"):
returnval = download_from_url_with_ftp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "sftp"):
returnval = download_from_url_with_sftp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
elif(httplibuse == "pysftp"):
returnval = download_from_url_with_pysftp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, buffersize, sleep, timeout)
else:
returnval = False
return returnval
def download_from_url_from_list(httpurl, httpheaders=geturls_headers, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", postdata=None, httplibuse="urllib", buffersize=524288, sleep=-1, timeout=10):
if(isinstance(httpurl, list)):
pass
elif(isinstance(httpurl, tuple)):
pass
elif(isinstance(httpurl, dict)):
httpurl = httpurl.values()
else:
httpurl = [httpurl]
listsize = len(httpurl)
listcount = 0
returnval = []
while(listcount < listsize):
ouputval = download_from_url(httpurl[listcount], httpheaders, httpuseragent, httpreferer,
httpcookie, httpmethod, postdata, httplibuse, buffersize, sleep, timeout)
returnval.append(ouputval)
listcount += 1
return returnval
def download_from_url_file(httpurl, httpheaders=geturls_headers, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", postdata=None, httplibuse="urllib", ranges=[None, None], buffersize=524288, sleep=-1, timeout=10):
global geturls_download_sleep, havezstd, havebrotli, haveaiohttp, haverequests, havemechanize, havepycurl, havehttplib2, haveurllib3, havehttpx, havehttpcore, haveparamiko, havepysftp
if(sleep < 0):
sleep = geturls_download_sleep
if(timeout <= 0):
timeout = 10
if(httplibuse == "urllib1" or httplibuse == "urllib2" or httplibuse == "request"):
httplibuse = "urllib"
if(httplibuse == "httplib1"):
httplibuse = "httplib"
if(not haverequests and httplibuse == "requests"):
httplibuse = "urllib"
if(not haveaiohttp and httplibuse == "aiohttp"):
httplibuse = "urllib"
if(not havehttpx and httplibuse == "httpx"):
httplibuse = "urllib"
if(not havehttpx and httplibuse == "httpx2"):
httplibuse = "urllib"
if(not havehttpcore and httplibuse == "httpcore"):
httplibuse = "urllib"
if(not havehttpcore and httplibuse == "httpcore2"):
httplibuse = "urllib"
if(not havemechanize and httplibuse == "mechanize"):
httplibuse = "urllib"
if(not havepycurl and httplibuse == "pycurl"):
httplibuse = "urllib"
if(not havepycurl and httplibuse == "pycurl2"):
httplibuse = "urllib"
if(havepycurl and httplibuse == "pycurl2" and not hasattr(pycurl, "CURL_HTTP_VERSION_2_0")):
httplibuse = "pycurl"
if(not havepycurl and httplibuse == "pycurl3"):
httplibuse = "urllib"
if(havepycurl and httplibuse == "pycurl3" and not hasattr(pycurl, "CURL_HTTP_VERSION_3_0") and hasattr(pycurl, "CURL_HTTP_VERSION_2_0")):
httplibuse = "pycurl2"
if(havepycurl and httplibuse == "pycurl3" and not hasattr(pycurl, "CURL_HTTP_VERSION_3_0") and not hasattr(pycurl, "CURL_HTTP_VERSION_2_0")):
httplibuse = "pycurl"
if(not havehttplib2 and httplibuse == "httplib2"):
httplibuse = "httplib"
if(not haveparamiko and httplibuse == "sftp"):
httplibuse = "ftp"
if(not haveparamiko and httplibuse == "pysftp"):
httplibuse = "ftp"
if(httplibuse == "urllib" or httplibuse == "request"):
returnval = download_from_url_file_with_urllib(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "request"):
returnval = download_from_url_file_with_request(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "request3"):
returnval = download_from_url_file_with_request3(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "httplib"):
returnval = download_from_url_file_with_httplib(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "httplib2"):
returnval = download_from_url_file_with_httplib2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "urllib3" or httplibuse == "request3"):
returnval = download_from_url_file_with_urllib3(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "requests"):
returnval = download_from_url_file_with_requests(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "aiohttp"):
returnval = download_from_url_file_with_aiohttp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "httpx"):
returnval = download_from_url_file_with_httpx(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "httpx2"):
returnval = download_from_url_file_with_httpx2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "httpcore"):
returnval = download_from_url_file_with_httpcore(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "httpcore2"):
returnval = download_from_url_file_with_httpcore2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "mechanize"):
returnval = download_from_url_file_with_mechanize(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "pycurl"):
returnval = download_from_url_file_with_pycurl(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "pycurl2"):
returnval = download_from_url_file_with_pycurl2(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "pycurl3"):
returnval = download_from_url_file_with_pycurl3(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "ftp"):
returnval = download_from_url_file_with_ftp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "sftp"):
returnval = download_from_url_file_with_sftp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
elif(httplibuse == "pysftp"):
returnval = download_from_url_file_with_pysftp(
httpurl, httpheaders, httpuseragent, httpreferer, httpcookie, httpmethod, postdata, ranges, buffersize, sleep, timeout)
else:
returnval = False
return returnval
def download_from_url_file_with_list(httpurl, httpheaders=geturls_headers, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", postdata=None, httplibuse="urllib", ranges=[None, None], buffersize=524288, sleep=-1, timeout=10):
if(isinstance(httpurl, list)):
pass
elif(isinstance(httpurl, tuple)):
pass
elif(isinstance(httpurl, dict)):
httpurl = httpurl.values()
else:
httpurl = [httpurl]
listsize = len(httpurl)
listcount = 0
returnval = []
while(listcount < listsize):
ouputval = download_from_url_file(httpurl[listcount], httpheaders, httpuseragent, httpreferer,
httpcookie, httpmethod, postdata, httplibuse, ranges, buffersize, sleep, timeout)
returnval.append(ouputval)
listcount += 1
return returnval