Splitting the function that process images
This commit is contained in:
parent
29fbb7f7e4
commit
15b8253960
1 changed files with 53 additions and 48 deletions
|
@ -484,17 +484,8 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
|||
tag.title = title
|
||||
return tag
|
||||
|
||||
def _process_img(self, attrs):
|
||||
'''Process a img tag.
|
||||
'''
|
||||
def _get_img(self, attrs):
|
||||
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:
|
||||
|
@ -543,6 +534,20 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
|||
alt += '\n'
|
||||
alt += _('Image is too big')
|
||||
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
|
||||
if mem:
|
||||
# Caveat: GdkPixbuf is known not to be safe to load
|
||||
|
|
Loading…
Add table
Reference in a new issue