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', |
@@ -250,17 +251,31 @@ |
try: |
return urllib.urlopen(url) |
except IOError as e: |
- error = e |
+ error = Exception('Error {0} while opening {1} url' |
+ .format(e, url)) |
time.sleep(5) |
raise error |
+def _parseXMLDocument(url, attempts=2): |
+ for i in range(attempts): |
+ page = _urlopen(url) |
+ content = page.read() |
+ page.close() |
Sebastian Noack
2017/01/17 09:33:32
The close() should have gone into a finally block,
Sebastian Noack
2017/01/17 10:16:56
Yes, in Python 2, the repsonse object returned by
Sebastian Noack
2017/01/17 10:20:15
Well, alternatively you could use try-finally. But
Vasily Kuznetsov
2017/01/17 10:30:34
Yeah, with is nicer, especially having Python 3 in
|
+ 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') |