Web: Display the target domain in snarfer. Re-implements pull request GH-523.

This commit is contained in:
Valentin Lorentz 2013-11-19 10:16:43 +00:00
parent bdec243909
commit 11d8f4655b
1 changed files with 6 additions and 4 deletions

View File

@ -131,11 +131,13 @@ class Web(callbacks.PluginRegexp):
return return
try: try:
size = conf.supybot.protocols.http.peekSize() size = conf.supybot.protocols.http.peekSize()
text = utils.web.getUrl(url, size=size) fd = utils.web.getUrlFd(url)
except utils.web.Error, e: text = fd.read(size)
fd.close()
except socket.timeout, e:
self.log.info('Couldn\'t snarf title of %u: %s.', url, e) self.log.info('Couldn\'t snarf title of %u: %s.', url, e)
if self.registryValue('snarferReportIOExceptions', channel): if self.registryValue('snarferReportIOExceptions', channel):
irc.reply(url+" : "+utils.web.strError(e), prefixNick=False) irc.reply(url+" : "+utils.web.TIMED_OUT, prefixNick=False)
return return
try: try:
text = text.decode(utils.web.getEncoding(text) or 'utf8', text = text.decode(utils.web.getEncoding(text) or 'utf8',
@ -149,7 +151,7 @@ class Web(callbacks.PluginRegexp):
self.log.debug('Encountered a problem parsing %u. Title may ' self.log.debug('Encountered a problem parsing %u. Title may '
'already be set, though', url) 'already be set, though', url)
if parser.title: if parser.title:
domain = utils.web.getDomain(url) domain = utils.web.getDomain(fd.geturl())
title = utils.web.htmlToText(parser.title.strip()) title = utils.web.htmlToText(parser.title.strip())
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
if isinstance(title, unicode): if isinstance(title, unicode):