mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added Http.extension
This commit is contained in:
parent
d91cc33c58
commit
03aad1712a
@ -447,6 +447,50 @@ class Http(callbacks.Privmsg):
|
||||
finally:
|
||||
fd.close()
|
||||
|
||||
_filextre = re.compile(
|
||||
r'<strong>Extension:</strong>.*?<tr>.*?</tr>\s+<tr>\s+<td colspan='\
|
||||
r'"2">(?:<a href[^>]+>([^<]+)</a>\s+|([^<]+))</td>\s+<td>'\
|
||||
r'(?:<a href[^>]+>([^<]+)</a>|<img src="images/spacer.gif"(.))',
|
||||
re.I|re.S)
|
||||
def extension(self, irc, msg, args):
|
||||
"""<ext>
|
||||
|
||||
Returns the results of querying filext.com for file extenstions that
|
||||
match <ext>.
|
||||
"""
|
||||
ext = privmsgs.getArgs(args)
|
||||
invalid = '|<>\^=?/[]";,*'
|
||||
for c in invalid:
|
||||
if c in ext:
|
||||
irc.error(msg, '\'%s\' is an invalid extension character' % c)
|
||||
return
|
||||
s = 'http://www.filext.com/detaillist.php?extdetail=%s&goButton=Go'
|
||||
try:
|
||||
text = webutils.getUrl(s % ext)
|
||||
except webutils.WebError, e:
|
||||
irc.error(msg, str(e))
|
||||
matches = self._filextre.findall(text)
|
||||
#print matches
|
||||
res = []
|
||||
for match in matches:
|
||||
(file1, file2, comp1, comp2) = match
|
||||
if file1:
|
||||
filetype = file1.strip()
|
||||
else:
|
||||
filetype = file2.strip()
|
||||
if comp1:
|
||||
company = comp1.strip()
|
||||
else:
|
||||
company = comp2.strip()
|
||||
if company:
|
||||
res.append('%s\'s %s' % (company, filetype))
|
||||
else:
|
||||
res.append(filetype)
|
||||
if res:
|
||||
irc.reply(msg, utils.commaAndify(res))
|
||||
else:
|
||||
irc.error(msg, 'No matching file extenstions were found.')
|
||||
|
||||
Class = Http
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
@ -33,6 +33,12 @@ from testsupport import *
|
||||
|
||||
class HttpTest(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Http',)
|
||||
def testExtension(self):
|
||||
self.assertHelp('extension')
|
||||
self.assertRegexp('extension doc', r'Microsoft\'s Word Document')
|
||||
self.assertError('extension zapohd')
|
||||
self.assertError('extension fo<')
|
||||
|
||||
def testHeaders(self):
|
||||
self.assertError('headers ftp://ftp.cdrom.com/pub/linux')
|
||||
self.assertNotError('headers http://www.slashdot.org/')
|
||||
|
Loading…
Reference in New Issue
Block a user