@@ -86,7 +86,7 @@ def _load_json_file(filepath):
86
86
LOG .debug ("About to load %s." % filepath )
87
87
88
88
# Sniff whether the file is gzipped
89
- fd = open (filepath , 'r ' )
89
+ fd = open (filepath , 'rb ' )
90
90
magic = fd .read (2 )
91
91
fd .seek (0 )
92
92
@@ -99,7 +99,7 @@ def _load_json_file(filepath):
99
99
LOG .debug ("-> %s" % ' ' .join (cmd ))
100
100
try :
101
101
data = subprocess .check_output (cmd )
102
- except subprocess . CalledProcessError , e :
102
+ except OSError , e :
103
103
if e .errno == errno .ENOENT :
104
104
raise Exception (
105
105
"You don't have gzip installed on your system. "
@@ -135,7 +135,7 @@ def _save_file(req, filepath):
135
135
size = int (req .headers ['Content-Length' ].strip ())
136
136
pbar = DownloadProgressBar (filepath , size ).start ()
137
137
bytes = 0
138
- with open (filepath , 'w ' ) as fd :
138
+ with open (filepath , 'wb ' ) as fd :
139
139
for chunk in req .iter_content (10 * 1024 ):
140
140
if chunk : # filter out keep-alive new chunks
141
141
fd .write (chunk )
@@ -200,7 +200,7 @@ def load_file(filename, url):
200
200
return _lean_load_json_file (filepath )
201
201
202
202
# Issue 213: sometimes we download a corrupted builds-*.js file
203
- except IOError :
203
+ except ( IOError , subprocess . CalledProcessError ) :
204
204
LOG .info ("%s is corrupted, we will have to download a new one." , filename )
205
205
os .remove (filepath )
206
206
return load_file (filename , url )
@@ -210,7 +210,7 @@ def _lean_load_json_file(filepath):
210
210
"""Helper function to load json contents from a file using ijson."""
211
211
LOG .debug ("About to load %s." % filepath )
212
212
213
- fd = open (filepath , 'r ' )
213
+ fd = open (filepath , 'rb ' )
214
214
215
215
gzipper = gzip .GzipFile (fileobj = fd )
216
216
builds = ijson .items (gzipper , 'builds.item' )
0 commit comments