Splitting the function that process images

This commit is contained in:
Julien Pivotto 2011-03-23 09:56:53 +01:00
parent 29fbb7f7e4
commit 15b8253960

View file

@ -484,17 +484,8 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
tag.title = title tag.title = title
return tag return tag
def _process_img(self, attrs): def _get_img(self, attrs):
'''Process a img tag.
'''
mem = '' 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 # Wait maximum 1s for connection
socket.setdefaulttimeout(1) socket.setdefaulttimeout(1)
try: try:
@ -543,6 +534,20 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
alt += '\n' alt += '\n'
alt += _('Image is too big') alt += _('Image is too big')
break break
return mem
def _process_img(self, attrs):
'''Process a img tag.
'''
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:
mem = self._get_img(attrs)
pixbuf = None pixbuf = None
if mem: if mem:
# Caveat: GdkPixbuf is known not to be safe to load # Caveat: GdkPixbuf is known not to be safe to load