mirror of https://github.com/moparisthebest/xeps
gen.py: support for fetching remote images.
This commit is contained in:
parent
53eeaac258
commit
ff5614fff8
5
gen.py
5
gen.py
|
@ -48,6 +48,7 @@ from xml.dom.minidom import parse,parseString,Document,getDOMImplementation
|
|||
# for serializing inline images
|
||||
import base64
|
||||
import urlparse
|
||||
import urllib
|
||||
|
||||
XEPPATH = "/var/www/vhosts/xmpp.org/extensions"
|
||||
CONFIGPATH = "/var/local/xsf"
|
||||
|
@ -60,6 +61,7 @@ files_to_delete = [];
|
|||
|
||||
def serializeInlineImage(output_dir, xep_nr, no, attrValue):
|
||||
up = urlparse.urlparse(attrValue)
|
||||
if up.scheme == 'data':
|
||||
head, data = up.path.split(',')
|
||||
bits = head.split(';')
|
||||
mime_type = bits[0] if bits[0] else 'text/plain'
|
||||
|
@ -78,6 +80,9 @@ def serializeInlineImage(output_dir, xep_nr, no, attrValue):
|
|||
file_ext = mime_type.split('/')[1]
|
||||
f = open(output_dir + '/' + 'inlineimage-' + xep_nr + '-' + str(no) + '.' + file_ext, 'wb')
|
||||
f.write(plaindata)
|
||||
elif up.scheme == 'http':
|
||||
file_name, file_ext = os.path.splitext(up.path)
|
||||
urllib.urlretrieve(attrValue, output_dir + '/' + 'inlineimage-' + xep_nr + '-' + str(no) + file_ext)
|
||||
|
||||
def serializeXEPInlineImages(output_dir, xep_nr, filename):
|
||||
dom = parse(filename)
|
||||
|
|
Loading…
Reference in New Issue