Permalink
Browse files

respect encoding of display data from urls

  • Loading branch information...
1 parent b28881b commit 0387301aec12a197ce55e145a8d3df4b5c49babd @minrk committed Aug 25, 2011
Showing with 10 additions and 0 deletions.
  1. +10 −0 IPython/core/display.py
View
@@ -268,6 +268,16 @@ def reload(self):
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

0 comments on commit 0387301

Please sign in to comment.