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://'):
|
if not url.startswith('http://'):
|
||||||
irc.error('Only HTTP urls are valid.')
|
irc.error('Only HTTP urls are valid.')
|
||||||
return
|
return
|
||||||
|
fd = webutils.getUrlFd(url)
|
||||||
try:
|
try:
|
||||||
fd = webutils.getUrlFd(url)
|
|
||||||
s = ', '.join(['%s: %s' % (k, v) for (k, v) in fd.headers.items()])
|
s = ', '.join(['%s: %s' % (k, v) for (k, v) in fd.headers.items()])
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
finally:
|
finally:
|
||||||
@ -113,16 +113,19 @@ class Http(callbacks.Privmsg):
|
|||||||
return
|
return
|
||||||
fd = webutils.getUrlFd(url)
|
fd = webutils.getUrlFd(url)
|
||||||
try:
|
try:
|
||||||
size = fd.headers['Content-Length']
|
try:
|
||||||
irc.reply('%s is %s bytes long.' % (url, size))
|
size = fd.headers['Content-Length']
|
||||||
except KeyError:
|
irc.reply('%s is %s bytes long.' % (url, size))
|
||||||
size = conf.supybot.protocols.http.peekSize()
|
except KeyError:
|
||||||
s = fd.read(size)
|
size = conf.supybot.protocols.http.peekSize()
|
||||||
if len(s) != size:
|
s = fd.read(size)
|
||||||
irc.reply('%s is %s bytes long.' % (url, len(s)))
|
if len(s) != size:
|
||||||
else:
|
irc.reply('%s is %s bytes long.' % (url, len(s)))
|
||||||
irc.reply('The server didn\'t tell me how long %s is '
|
else:
|
||||||
'but it\'s longer than %s bytes.' % (url, size))
|
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):
|
def title(self, irc, msg, args):
|
||||||
"""<url>
|
"""<url>
|
||||||
@ -286,8 +289,8 @@ class Http(callbacks.Privmsg):
|
|||||||
|
|
||||||
Returns information about the current version of the Linux kernel.
|
Returns information about the current version of the Linux kernel.
|
||||||
"""
|
"""
|
||||||
|
fd = webutils.getUrlFd('http://kernel.org/kdist/finger_banner')
|
||||||
try:
|
try:
|
||||||
fd = webutils.getUrlFd('http://kernel.org/kdist/finger_banner')
|
|
||||||
stable = 'unknown'
|
stable = 'unknown'
|
||||||
beta = 'unknown'
|
beta = 'unknown'
|
||||||
for line in fd:
|
for line in fd:
|
||||||
@ -313,9 +316,9 @@ class Http(callbacks.Privmsg):
|
|||||||
urlClean = search.replace(' ', '+')
|
urlClean = search.replace(' ', '+')
|
||||||
host = 'http://pgp.mit.edu:11371'
|
host = 'http://pgp.mit.edu:11371'
|
||||||
url = '%s/pks/lookup?op=index&search=%s' % (host, urlClean)
|
url = '%s/pks/lookup?op=index&search=%s' % (host, urlClean)
|
||||||
|
fd = webutils.getUrlFd(url, headers={})
|
||||||
try:
|
try:
|
||||||
L = []
|
L = []
|
||||||
fd = webutils.getUrlFd(url)
|
|
||||||
for line in iter(fd.next, ''):
|
for line in iter(fd.next, ''):
|
||||||
info = self._pgpkeyre.search(line)
|
info = self._pgpkeyre.search(line)
|
||||||
if info:
|
if info:
|
||||||
@ -418,6 +421,21 @@ class Http(callbacks.Privmsg):
|
|||||||
]
|
]
|
||||||
irc.reply('; '.join(resp))
|
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
|
Class = Http
|
||||||
|
|
||||||
|
@ -119,6 +119,8 @@ if network:
|
|||||||
self.assertRegexp('zipinfo 78014', 'County: La Salle')
|
self.assertRegexp('zipinfo 78014', 'County: La Salle')
|
||||||
self.assertRegexp('zipinfo 90001',
|
self.assertRegexp('zipinfo 90001',
|
||||||
r'City: Los Angeles.*County: Los Angeles')
|
r'City: Los Angeles.*County: Los Angeles')
|
||||||
|
def testBender(self):
|
||||||
|
self.assertNotError('bender')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user