From 9d8aa07f86278c437b6d084d59e89d795b4e30ef Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 8 Sep 2003 08:48:33 +0000 Subject: [PATCH] Added pgpkey and a test case for it --- plugins/Http.py | 29 +++++++++++++++++++++++++++-- test/test_Http.py | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/Http.py b/plugins/Http.py index 53e6c6f2b..8dcf4a5f8 100644 --- a/plugins/Http.py +++ b/plugins/Http.py @@ -38,7 +38,6 @@ from baseplugin import * import re import sets import time -import urllib import urllib2 import utils @@ -360,7 +359,7 @@ class Http(callbacks.Privmsg): elif 'We could not get any results' in html: irc.reply(msg, 'No results found for %s.' % hostname) else: - irc.error(msg, 'The format of the was odd.') + irc.error(msg, 'The format of page the was odd.') def kernel(self, irc, msg, args): """takes no arguments @@ -382,6 +381,32 @@ class Http(callbacks.Privmsg): irc.reply(msg, 'The latest stable kernel is %s; ' \ 'the latest beta kernel is %s.' % (stable, beta)) + _pgpkeyre = re.compile(r'pub\s+\d{4}\w/([^<]+)[^>]+>([^<]+)') + def pgpkey(self, irc, msg, args): + """ + + Returns the results of querying pgp.mit.edu for keys that match + the . + """ + search = privmsgs.getArgs(args) + urlClean = search.replace(' ', '+') + host = 'http://pgp.mit.edu:11371' + url = '%s/pks/lookup?op=index&search=%s' % (host, urlClean) + fd = urllib2.urlopen(url) + html = fd.read().split('\n') + fd.close() + pgpkeys = '' + for line in html: + info = self._pgpkeyre.search(line) + if info: + pgpkeys += '%s <%s> :: ' % (info.group(3), '%s%s' % (host, + info.group(1))) + if len(pgpkeys) == 0: + irc.reply(msg, 'No results found for %s.' % search) + else: + irc.reply(msg, 'Matches found for %s: %s' % (search, pgpkeys)) + Class = Http # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/test/test_Http.py b/test/test_Http.py index b2d16ebf8..65a905b2c 100644 --- a/test/test_Http.py +++ b/test/test_Http.py @@ -67,5 +67,8 @@ class HttpTest(PluginTestCase, PluginDocumentation): def testKernel(self): self.assertNotError('kernel') + def testPgpkey(self): + self.assertNotError('pgpkey jeremiah fincher') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: