From a8c7ba28db34854af56da138245f321533ecc282 2020-04-17 22:46:23 From: Ian Castleden Date: 2020-04-17 22:46:23 Subject: [PATCH] uncompress compressed data --- diff --git a/IPython/core/display.py b/IPython/core/display.py index 8cdd07f..2b97bc6 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -661,12 +661,21 @@ class DisplayObject(object): data = response.read() # extract encoding from header, if there is one: encoding = None - if "content-type" in response.headers: + if 'content-type' in response.headers: for sub in response.headers['content-type'].split(';'): sub = sub.strip() if sub.startswith('charset'): encoding = sub.split('=')[-1].strip() break + if 'content-encoding' in response.headers: + # TODO: do deflate? + if 'gzip' in response.headers['content-encoding']: + import gzip + from io import BytesIO + with gzip.open(BytesIO(data), 'rt', encoding=encoding) as fp: + encoding = None + data = fp.read() + # decode data, if an encoding was specified # We only touch self.data once since # subclasses such as SVG have @data.setter methods