support data:URI scheme in XHTML-IM message. Fixed #6106

This commit is contained in:
Denis Fomin 2010-12-14 19:30:00 +03:00
parent c4f94915ce
commit e95ffa55ef
1 changed files with 64 additions and 45 deletions

View File

@ -489,6 +489,12 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
'''
mem = ''
try:
if attrs['src'].startswith('data:image/'):
# The "data" URL scheme http://tools.ietf.org/html/rfc2397
import base64
img = attrs['src'].split(',')[1]
mem = base64.standard_b64decode(urllib2.unquote(img))
else:
# Wait maximum 1s for connection
socket.setdefaulttimeout(1)
try:
@ -1090,6 +1096,19 @@ return faciter(n,1)</pre>
</div>
<p/>
<p>#232/1</p>
</body>
''')
htmlview.print_real_text(None, xhtml='<hr />')
htmlview.print_real_text(None, xhtml='''
<body xmlns='http://www.w3.org/1999/xhtml'>
<br/>
<img src='data:image/png;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw\
AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz\
ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp\
a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl\
ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis\
F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH\
hhx4dbgYKAAA7' alt='Larry'/>
</body>
''')
htmlview.tv.show()