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

View File

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