+ handle = urllib_request.urlopen(req, **kwargs)
+ if handle.headers['Content-Type'] in ['image/jpeg', 'image/png']:
+ return handle
+ elif handle.info().get('Content-Encoding') == 'gzip':
+ # Handle gzip decompression
+ buf = StringIO(handle.read())
+ f = gzip.GzipFile(fileobj=buf)
+ data = f.read()
+ else:
+ data = handle.read()
+