2525
2626if sys .version_info [0 ] == 3 :
2727 from urllib .request import urlretrieve
28+ from urllib .request import urlopen
2829 unicode = lambda s : str (s )
2930else :
3031 # Not Python 3 - today, it is most likely to be Python 2
3132 from urllib import urlretrieve
33+ from urllib import urlopen
3234
3335if 'Windows' in platform .system ():
3436 import requests
@@ -79,6 +81,26 @@ def unpack(filename, destination):
7981 shutil .rmtree (rename_to )
8082 shutil .move (dirname , rename_to )
8183
84+ def download_file (url ,filename ):
85+ import ssl
86+ import contextlib
87+ ctx = ssl .create_default_context ()
88+ ctx .check_hostname = False
89+ ctx .verify_mode = ssl .CERT_NONE
90+ with contextlib .closing (urlopen (url ,context = ctx )) as fp :
91+ block_size = 1024 * 8
92+ block = fp .read (block_size )
93+ if block :
94+ with open (filename ,'wb' ) as out_file :
95+ out_file .write (block )
96+ while True :
97+ block = fp .read (block_size )
98+ if not block :
99+ break
100+ out_file .write (block )
101+ else :
102+ raise Exception ('nonexisting file or connection error' )
103+
82104def get_tool (tool ):
83105 sys_name = platform .system ()
84106 archive_name = tool ['archiveFileName' ]
@@ -100,7 +122,11 @@ def get_tool(tool):
100122 f .write (r .content )
101123 f .close ()
102124 else :
103- urlretrieve (url , local_path , report_progress )
125+ is_ci = os .environ .get ('TRAVIS_BUILD_DIR' );
126+ if is_ci :
127+ download_file (url , local_path )
128+ else :
129+ urlretrieve (url , local_path , report_progress )
104130 sys .stdout .write ("\r Done\n " )
105131 sys .stdout .flush ()
106132 else :
0 commit comments