]> granicus.if.org Git - python/commitdiff
Try to transfer the Unicode test data files gzipped.
authorGeorg Brandl <georg@python.org>
Thu, 6 Nov 2014 14:33:30 +0000 (15:33 +0100)
committerGeorg Brandl <georg@python.org>
Thu, 6 Nov 2014 14:33:30 +0000 (15:33 +0100)
Lib/test/support/__init__.py

index a64ed56299e1c2f02985d859fd5a8b5827626d80..e6db70ff5c78a06bd94385a5af8710fcbf054955 100644 (file)
@@ -1029,7 +1029,12 @@ def open_urlresource(url, *args, **kw):
     requires('urlfetch')
 
     print('\tfetching %s ...' % url, file=get_original_stdout())
-    f = urllib.request.urlopen(url, timeout=15)
+    opener = urllib.request.build_opener()
+    if gzip:
+        opener.addheaders.append(('Accept-Encoding', 'gzip'))
+    f = opener.open(url, timeout=15)
+    if gzip and f.headers.get('Content-Encoding') == 'gzip':
+        f = gzip.GzipFile(fileobj=f)
     try:
         with open(fn, "wb") as out:
             s = f.read()