Better error handling for mime parsers. #264.
This commit is contained in:
@@ -153,7 +153,10 @@ class ImgurAlbumMIMEParser(BaseMIMEParser):
|
|||||||
|
|
||||||
urls = []
|
urls = []
|
||||||
for div in soup.find_all('div', class_='post-image'):
|
for div in soup.find_all('div', class_='post-image'):
|
||||||
urls.append('http:' + div.find('img').get('src'))
|
img = div.find('img')
|
||||||
|
src = img.get('src') if img else None
|
||||||
|
if src:
|
||||||
|
urls.append('http:{0}'.format(src))
|
||||||
|
|
||||||
if urls:
|
if urls:
|
||||||
return " ".join(urls), 'image/x-imgur-album'
|
return " ".join(urls), 'image/x-imgur-album'
|
||||||
|
|||||||
@@ -51,12 +51,7 @@ class Terminal(object):
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.loader = LoadScreen(self)
|
self.loader = LoadScreen(self)
|
||||||
self._display = None
|
self._display = None
|
||||||
|
self._mailcap_dict = mailcap.getcaps()
|
||||||
try:
|
|
||||||
self._mailcap_dict = mailcap.getcaps()
|
|
||||||
except IOError:
|
|
||||||
# Python 2 raises an error, python 3 does not
|
|
||||||
self._mailcap_dict = {}
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def up_arrow(self):
|
def up_arrow(self):
|
||||||
@@ -416,7 +411,14 @@ class Terminal(object):
|
|||||||
# could also be updated to point to a different page, or it
|
# could also be updated to point to a different page, or it
|
||||||
# could refer to the location of a temporary file with the
|
# could refer to the location of a temporary file with the
|
||||||
# page's downloaded content.
|
# page's downloaded content.
|
||||||
modified_url, content_type = parser.get_mimetype(url)
|
try:
|
||||||
|
modified_url, content_type = parser.get_mimetype(url)
|
||||||
|
except Exception as e:
|
||||||
|
# If Imgur decides to change its html layout, let it fail
|
||||||
|
# silently in the background instead of crashing.
|
||||||
|
_logger.warn('parser %s raised an exception', parser)
|
||||||
|
_logger.exception(e)
|
||||||
|
raise exceptions.MailcapEntryNotFound()
|
||||||
if not content_type:
|
if not content_type:
|
||||||
_logger.info('Content type could not be determined')
|
_logger.info('Content type could not be determined')
|
||||||
raise exceptions.MailcapEntryNotFound()
|
raise exceptions.MailcapEntryNotFound()
|
||||||
|
|||||||
Reference in New Issue
Block a user