From 0387301aec12a197ce55e145a8d3df4b5c49babd 2011-08-25 16:28:45 From: MinRK Date: 2011-08-25 16:28:45 Subject: [PATCH] respect encoding of display data from urls --- diff --git a/IPython/core/display.py b/IPython/core/display.py index df4987b..3466272 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -268,6 +268,16 @@ class DisplayObject(object): import urllib2 response = urllib2.urlopen(self.url) self.data = response.read() + # extract encoding from header, if there is one: + encoding = None + for sub in response.headers['content-type'].split(';'): + sub = sub.strip() + if sub.startswith('charset'): + encoding = sub.split('=')[-1].strip() + break + # decode data, if an encoding was specified + if encoding: + self.data = self.data.decode(encoding, 'replace') except: self.data = None