mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-10-03 01:48:52 +02:00
Web: Catch more errors in getTitle.
This commit is contained in:
parent
3648751911
commit
7466058c8f
@ -149,19 +149,27 @@ class Web(callbacks.PluginRegexp):
|
|||||||
def getTitle(self, irc, url, raiseErrors):
|
def getTitle(self, irc, url, raiseErrors):
|
||||||
size = conf.supybot.protocols.http.peekSize()
|
size = conf.supybot.protocols.http.peekSize()
|
||||||
timeout = self.registryValue('timeout')
|
timeout = self.registryValue('timeout')
|
||||||
(target, text) = utils.web.getUrlTargetAndContent(url, size=size,
|
try:
|
||||||
|
(target, text) = utils.web.getUrlTargetAndContent(url, size=size,
|
||||||
timeout=timeout)
|
timeout=timeout)
|
||||||
|
except Exception as e:
|
||||||
|
if raiseErrors:
|
||||||
|
irc.error(_('That URL raised <' + str(e)) + '>',
|
||||||
|
Raise=True)
|
||||||
|
else:
|
||||||
|
self.log.info('Web plugin TitleSnarfer: URL <%s> raised <%s>', url, str(e))
|
||||||
try:
|
try:
|
||||||
text = text.decode(utils.web.getEncoding(text) or 'utf8',
|
text = text.decode(utils.web.getEncoding(text) or 'utf8',
|
||||||
'replace')
|
'replace')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
if minisix.PY3:
|
||||||
if minisix.PY3 and isinstance(text, bytes):
|
if raiseErrors:
|
||||||
if raiseErrors:
|
irc.error(_('Could not guess the page\'s encoding. (Try '
|
||||||
irc.error(_('Could not guess the page\'s encoding. (Try '
|
'installing python-charade.)'), Raise=True)
|
||||||
'installing python-charade.)'), Raise=True)
|
else:
|
||||||
else:
|
self.log.info('Web plugin TitleSnarfer: URL <%s> Could '
|
||||||
return None
|
'not guess the page\'s encoding. (Try '
|
||||||
|
'installing python-charade.)', url)
|
||||||
try:
|
try:
|
||||||
parser = Title()
|
parser = Title()
|
||||||
parser.feed(text)
|
parser.feed(text)
|
||||||
@ -181,6 +189,13 @@ class Web(callbacks.PluginRegexp):
|
|||||||
else:
|
else:
|
||||||
irc.error(format(_('That URL appears to have no HTML title '
|
irc.error(format(_('That URL appears to have no HTML title '
|
||||||
'within the first %S.'), size), Raise=True)
|
'within the first %S.'), size), Raise=True)
|
||||||
|
else:
|
||||||
|
if len(text) < size:
|
||||||
|
self.log.info('Web plugin TitleSnarfer: URL <%s> appears'
|
||||||
|
' to have no HTML title. ', url)
|
||||||
|
else:
|
||||||
|
self.log.info('Web plugin TitleSnarfer: URL <%s> appears to have no HTML title'
|
||||||
|
' within the first %S.', url, size)
|
||||||
|
|
||||||
@fetch_sandbox
|
@fetch_sandbox
|
||||||
def titleSnarfer(self, irc, msg, match):
|
def titleSnarfer(self, irc, msg, match):
|
||||||
|
Loading…
Reference in New Issue
Block a user