This commit is contained in:
Jeremy Fincher 2003-12-04 08:50:49 +00:00
parent 41fd7c7887
commit 56b68d6893
2 changed files with 6 additions and 3 deletions

View File

@ -81,6 +81,7 @@ class Http(callbacks.Privmsg):
except webutils.WebError, e: except webutils.WebError, e:
irc.error(msg, str(e)) irc.error(msg, str(e))
_doctypeRe = re.compile(r'(<!DOCTYPE[^>]+>)', re.M)
def doctype(self, irc, msg, args): def doctype(self, irc, msg, args):
"""<url> """<url>
@ -93,9 +94,9 @@ class Http(callbacks.Privmsg):
return return
try: try:
s = webutils.getUrl(url, size=self.maxSize) s = webutils.getUrl(url, size=self.maxSize)
if 'DOCTYPE' in s and '\n' in s: m = self._doctypeRe.search(s)
line = s.splitlines()[0] if m:
s = utils.normalizeWhitespace(line.strip()) s = utils.normalizeWhitespace(m.group(0))
irc.reply(msg, '%s has the following doctype: %s' % (url, s)) irc.reply(msg, '%s has the following doctype: %s' % (url, s))
else: else:
irc.reply(msg, '%s has no specified doctype.' % url) irc.reply(msg, '%s has no specified doctype.' % url)

View File

@ -40,6 +40,8 @@ class HttpTest(PluginTestCase, PluginDocumentation):
def testDoctype(self): def testDoctype(self):
self.assertError('doctype ftp://ftp.cdrom.com/pub/linux') self.assertError('doctype ftp://ftp.cdrom.com/pub/linux')
self.assertNotError('doctype http://www.slashdot.org/') self.assertNotError('doctype http://www.slashdot.org/')
m = self.getMsg('doctype http://moobot.sf.net/')
self.failUnless(m.args[1].endswith('>'))
def testSize(self): def testSize(self):
self.assertError('size ftp://ftp.cdrom.com/pub/linux') self.assertError('size ftp://ftp.cdrom.com/pub/linux')