diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-22 22:04:28 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-22 22:04:28 +0200 |
commit | 1f37dc83f6287a840d2e10c85ffbb7bf2ddff0af (patch) | |
tree | 774240699243b88f9a2ab6c0953f0d8f5ea4b9af /chimere/utils.py | |
parent | d888cd567aebf972955c06bd005053aa7c0bd503 (diff) | |
download | Chimère-1f37dc83f6287a840d2e10c85ffbb7bf2ddff0af.tar.bz2 Chimère-1f37dc83f6287a840d2e10c85ffbb7bf2ddff0af.zip |
Put a timeout for all url fetch in imports
Diffstat (limited to 'chimere/utils.py')
-rw-r--r-- | chimere/utils.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/chimere/utils.py b/chimere/utils.py index ba0f205..ffa5789 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -50,6 +50,8 @@ from django.utils.translation import ugettext_lazy as _ from chimere import get_version +TIMEOUT = 20 + def unicode_normalize(string): return ''.join( @@ -202,7 +204,7 @@ class ImportManager(object): url = source if extra_url: url += extra_url - remotehandle = urllib.request.urlopen(url) + remotehandle = urllib.request.urlopen(url, timeout=TIMEOUT) source = io.BytesIO(remotehandle.read()) remotehandle.close() except ValueError: @@ -1195,7 +1197,7 @@ class HtmlXsltManager(ImportManager): self.marker_cls = Marker try: main_page = urllib.request.urlopen(self.importer_instance.source, - timeout=20) + timeout=TIMEOUT) assert main_page.getcode() == 200 except (urllib.error.URLError, AssertionError): return (0, 0, _("Source page is unreachable.")) @@ -1243,7 +1245,8 @@ class HtmlXsltManager(ImportManager): not c_item['link'].startswith('https://'): c_item['link'] = base_url + c_item['link'] try: - child_page = urllib.request.urlopen(c_item['link']) + child_page = urllib.request.urlopen(c_item['link'], + timeout=TIMEOUT) assert child_page.getcode() == 200 except (urllib.error.URLError, AssertionError): # don't stop the export for a bad link |