Index: sitescripts/extensions/utils.py |
=================================================================== |
--- a/sitescripts/extensions/utils.py |
+++ b/sitescripts/extensions/utils.py |
@@ -26,6 +26,7 @@ |
from ConfigParser import SafeConfigParser, NoOptionError |
from StringIO import StringIO |
from sitescripts.utils import get_config |
+from xml.parsers.expat import ExpatError |
PACKAGE_SUFFIXES = { |
'gecko': '.xpi', |
@@ -255,12 +256,25 @@ |
raise error |
+def _parseXMLDocument(url, attempts=2): |
+ for i in range(attempts): |
+ page = _urlopen(url) |
+ content = page.read() |
+ page.close() |
+ try: |
+ return dom.parseString(content) |
+ except ExpatError as err: |
+ exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}' |
+ .format(err, content, url)) |
+ raise exception |
+ |
+ |
def _getMozillaDownloadLink(galleryID): |
""" |
gets download link for a Gecko add-on from the Mozilla Addons site |
""" |
url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _urlencode(galleryID) |
- document = dom.parse(_urlopen(url)) |
+ document = _parseXMLDocument(url) |
linkTags = document.getElementsByTagName('install') |
linkTag = linkTags[0] if len(linkTags) > 0 else None |
versionTags = document.getElementsByTagName('version') |