mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
Added bender, fixed bugs.
This commit is contained in:
parent
fac96b16dc
commit
71c752a7fb
@ -74,8 +74,8 @@ class Http(callbacks.Privmsg):
|
||||
if not url.startswith('http://'):
|
||||
irc.error('Only HTTP urls are valid.')
|
||||
return
|
||||
try:
|
||||
fd = webutils.getUrlFd(url)
|
||||
try:
|
||||
s = ', '.join(['%s: %s' % (k, v) for (k, v) in fd.headers.items()])
|
||||
irc.reply(s)
|
||||
finally:
|
||||
@ -112,6 +112,7 @@ class Http(callbacks.Privmsg):
|
||||
irc.error('Only HTTP urls are valid.')
|
||||
return
|
||||
fd = webutils.getUrlFd(url)
|
||||
try:
|
||||
try:
|
||||
size = fd.headers['Content-Length']
|
||||
irc.reply('%s is %s bytes long.' % (url, size))
|
||||
@ -123,6 +124,8 @@ class Http(callbacks.Privmsg):
|
||||
else:
|
||||
irc.reply('The server didn\'t tell me how long %s is '
|
||||
'but it\'s longer than %s bytes.' % (url, size))
|
||||
finally:
|
||||
fd.close()
|
||||
|
||||
def title(self, irc, msg, args):
|
||||
"""<url>
|
||||
@ -286,8 +289,8 @@ class Http(callbacks.Privmsg):
|
||||
|
||||
Returns information about the current version of the Linux kernel.
|
||||
"""
|
||||
try:
|
||||
fd = webutils.getUrlFd('http://kernel.org/kdist/finger_banner')
|
||||
try:
|
||||
stable = 'unknown'
|
||||
beta = 'unknown'
|
||||
for line in fd:
|
||||
@ -313,9 +316,9 @@ class Http(callbacks.Privmsg):
|
||||
urlClean = search.replace(' ', '+')
|
||||
host = 'http://pgp.mit.edu:11371'
|
||||
url = '%s/pks/lookup?op=index&search=%s' % (host, urlClean)
|
||||
fd = webutils.getUrlFd(url, headers={})
|
||||
try:
|
||||
L = []
|
||||
fd = webutils.getUrlFd(url)
|
||||
for line in iter(fd.next, ''):
|
||||
info = self._pgpkeyre.search(line)
|
||||
if info:
|
||||
@ -418,6 +421,21 @@ class Http(callbacks.Privmsg):
|
||||
]
|
||||
irc.reply('; '.join(resp))
|
||||
|
||||
def bender(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
|
||||
Returns a random Bender (from Futurama) quote from Slashdot's HTTP
|
||||
headers.
|
||||
"""
|
||||
fd = webutils.getUrlFd('http://slashdot.org/')
|
||||
try:
|
||||
if 'X-Bender' in fd.headers:
|
||||
irc.reply(fd.headers['X-Bender'])
|
||||
else:
|
||||
irc.reply('Slashdot seems to be running low on Bender quotes.')
|
||||
finally:
|
||||
fd.close()
|
||||
|
||||
|
||||
Class = Http
|
||||
|
||||
|
@ -119,6 +119,8 @@ if network:
|
||||
self.assertRegexp('zipinfo 78014', 'County: La Salle')
|
||||
self.assertRegexp('zipinfo 90001',
|
||||
r'City: Los Angeles.*County: Los Angeles')
|
||||
def testBender(self):
|
||||
self.assertNotError('bender')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user