Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/extensions/utils.py

Issue 29370859: Issue 4767 - Improve error reporting in update_update_manifests (Closed)
Patch Set: For comment 13 Created Jan. 13, 2017, 3:38 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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')
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld