Correctly catch the HTMLParseError

This commit is contained in:
James Vega 2005-05-07 03:55:14 +00:00
parent 47179f8bc6
commit 06800f9fc7

View File

@ -28,8 +28,7 @@
### ###
import re import re
import HTMLParser
from HTMLParser import HTMLParser
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
@ -38,11 +37,11 @@ import supybot.plugins as plugins
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
class Title(HTMLParser): class Title(HTMLParser.HTMLParser):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.inTitle = False self.inTitle = False
self.title = None self.title = None
HTMLParser.__init__(self, *args, **kwargs) HTMLParser.HTMLParser.__init__(self, *args, **kwargs)
def handle_starttag(self, tag, attrs): def handle_starttag(self, tag, attrs):
if tag == 'title': if tag == 'title':
@ -88,7 +87,7 @@ class Web(callbacks.PluginRegexp):
parser = Title() parser = Title()
try: try:
parser.feed(text) parser.feed(text)
except HTMLParserError: except HTMLParser.HTMLParseError:
self.log.debug('Unable to parse %u', url) self.log.debug('Unable to parse %u', url)
return return
if parser.title is not None: if parser.title is not None:
@ -164,9 +163,10 @@ class Web(callbacks.PluginRegexp):
parser = Title() parser = Title()
try: try:
parser.feed(text) parser.feed(text)
except HTMLParserError: except HTMLParser.HTMLParseError:
irc.reply(format('That URL appears to have no HTML title within ' irc.reply(format('That URL appears to have no HTML title within '
'the first %i bytes.', size)) 'the first %i bytes.', size))
return
if parser.title is not None: if parser.title is not None:
irc.reply(utils.web.htmlToText(parser.title.strip())) irc.reply(utils.web.htmlToText(parser.title.strip()))
else: else: