mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure timeouts are respected by all fetches in BasicNewsRecipe
This commit is contained in:
parent
0c678a1dc4
commit
1bec527eb7
@ -699,7 +699,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
# the recipe implements get_browser() or not
|
# the recipe implements get_browser() or not
|
||||||
br = self.clone_browser(self.browser)
|
br = self.clone_browser(self.browser)
|
||||||
open_func = getattr(br, 'open_novisit', br.open)
|
open_func = getattr(br, 'open_novisit', br.open)
|
||||||
with closing(open_func(url_or_raw)) as f:
|
with closing(open_func(url_or_raw, timeout=self.timeout)) as f:
|
||||||
_raw = f.read()
|
_raw = f.read()
|
||||||
if not _raw:
|
if not _raw:
|
||||||
raise RuntimeError('Could not fetch index from %s'%url_or_raw)
|
raise RuntimeError('Could not fetch index from %s'%url_or_raw)
|
||||||
@ -1128,7 +1128,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
if bn:
|
if bn:
|
||||||
img = os.path.join(imgdir, 'feed_image_%d%s'%(self.image_counter, os.path.splitext(bn)))
|
img = os.path.join(imgdir, 'feed_image_%d%s'%(self.image_counter, os.path.splitext(bn)))
|
||||||
try:
|
try:
|
||||||
with open(img, 'wb') as fi, closing(self.browser.open(feed.image_url)) as r:
|
with open(img, 'wb') as fi, closing(self.browser.open(feed.image_url, timeout=self.timeout)) as r:
|
||||||
fi.write(r.read())
|
fi.write(r.read())
|
||||||
self.image_counter += 1
|
self.image_counter += 1
|
||||||
feed.image_url = img
|
feed.image_url = img
|
||||||
@ -1333,7 +1333,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
cdata = f.read()
|
cdata = f.read()
|
||||||
else:
|
else:
|
||||||
self.report_progress(1, _('Downloading cover from %s')%cu)
|
self.report_progress(1, _('Downloading cover from %s')%cu)
|
||||||
with closing(self.browser.open(cu)) as r:
|
with closing(self.browser.open(cu, timeout=self.timeout)) as r:
|
||||||
cdata = r.read()
|
cdata = r.read()
|
||||||
if not cdata:
|
if not cdata:
|
||||||
return
|
return
|
||||||
@ -1382,7 +1382,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
with open(mpath, 'wb') as mfile:
|
with open(mpath, 'wb') as mfile:
|
||||||
mfile.write(open(mu, 'rb').read())
|
mfile.write(open(mu, 'rb').read())
|
||||||
else:
|
else:
|
||||||
with open(mpath, 'wb') as mfile, closing(self.browser.open(mu)) as r:
|
with open(mpath, 'wb') as mfile, closing(self.browser.open(mu, timeout=self.timeout)) as r:
|
||||||
mfile.write(r.read())
|
mfile.write(r.read())
|
||||||
self.report_progress(1, _('Masthead image downloaded'))
|
self.report_progress(1, _('Masthead image downloaded'))
|
||||||
self.prepare_masthead_image(mpath, outfile)
|
self.prepare_masthead_image(mpath, outfile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user