Fix for bug #815242, pydoc fnmatch.fnmatch fails.

This commit is contained in:
Jeremy Fincher 2003-09-30 22:12:50 +00:00
parent 2821527706
commit f84345048a
2 changed files with 47 additions and 103 deletions

View File

@ -69,9 +69,7 @@ import callbacks
example = utils.wrapLines(""" example = utils.wrapLines("""
<jemfinch> @list FunCommands <jemfinch> @list FunCommands
<supybot> base, binary, chr, coin, cpustats, decode, dice, dns, encode, hexlify, kernel, last, lastfrom, leet, levenshtein, lithp, md5, mimetype, netstats, objects, ord, pydoc, rot13, sha, soundex, unhexlify, uptime, urlquote, urlunquote, xor <supybot> base, binary, chr, coin, decode, dice, dns, encode, hexlify, kernel, last, lastfrom, leet, levenshtein, lithp, md5, mimetype, objects, ord, pydoc, rot13, sha, soundex, unhexlify, urlquote, urlunquote, xor
<jemfinch> @netstats
<supybot> I have received 211 messages for a total of 19535 bytes. I have sent 109 messages for a total of 8672 bytes.
<jemfinch> @ord A <jemfinch> @ord A
<supybot> 65 <supybot> 65
<jemfinch> @chr 65 <jemfinch> @chr 65
@ -121,10 +119,6 @@ example = utils.wrapLines("""
<supybot> 25, 97, 85, and 93 <supybot> 25, 97, 85, and 93
<jemfinch> @leet All your base are belong to us!! <jemfinch> @leet All your base are belong to us!!
<supybot> 411 y0ur b453 4r3 b310ng +0 uz!! <supybot> 411 y0ur b453 4r3 b310ng +0 uz!!
<jemfinch> @cpustats
<supybot> I have taken 5.4 seconds of user time and 0.29 seconds of system time, for a total of 5.69 seconds of CPU time. My children have taken 0.0 seconds of user time and 0.0 seconds of system time for a total of 0.0 seconds of CPU time. I've taken a total of 0.00329929635973% of this computer's time. Out of 2 spawned threads, I have 1 active.
<jemfinch> @uptime
<supybot> I have been running for 28 minutes and 47 seconds.
<jemfinch> @objects <jemfinch> @objects
<supybot> I have 24941 objects: 234 modules, 716 classes, 5489 functions, 1656 dictionaries, 827 lists, and 14874 tuples (and a few other different types). I have a total of 119242 references. <supybot> I have 24941 objects: 234 modules, 716 classes, 5489 functions, 1656 dictionaries, 827 lists, and 14874 tuples (and a few other different types). I have a total of 119242 references.
<jemfinch> @levenshtein supybot supbot <jemfinch> @levenshtein supybot supbot
@ -147,35 +141,6 @@ example = utils.wrapLines("""
""") """)
class FunCommands(callbacks.Privmsg): class FunCommands(callbacks.Privmsg):
priority = 98 # Really just to test.
def __init__(self):
callbacks.Privmsg.__init__(self)
self.sentMsgs = 0
self.recvdMsgs = 0
self.sentBytes = 0
self.recvdBytes = 0
def inFilter(self, irc, msg):
self.recvdMsgs += 1
self.recvdBytes += len(str(msg))
return msg
def outFilter(self, irc, msg):
self.sentMsgs += 1
self.sentBytes += len(str(msg))
return msg
def netstats(self, irc, msg, args):
"""takes no arguments
Returns some interesting network-related statistics.
"""
irc.reply(msg,
'I have received %s messages for a total of %s bytes. '\
'I have sent %s messages for a total of %s bytes.' %\
(self.recvdMsgs, self.recvdBytes,
self.sentMsgs, self.sentBytes))
def hexip(self, irc, msg, args): def hexip(self, irc, msg, args):
"""<ip> """<ip>
@ -444,38 +409,6 @@ class FunCommands(callbacks.Privmsg):
s = s.translate(self._leettrans) s = s.translate(self._leettrans)
irc.reply(msg, s) irc.reply(msg, s)
def cpustats(self, irc, msg, args):
"""takes no arguments
Returns some interesting CPU-related statistics on the bot.
"""
(user, system, childUser, childSystem, elapsed) = os.times()
timeRunning = time.time() - world.startedAt
activeThreads = threading.activeCount()
response ='I have taken %s seconds of user time and %s seconds of '\
'system time, for a total of %s seconds of CPU time. My '\
'children have taken %s seconds of user time and %s seconds'\
' of system time for a total of %s seconds of CPU time. ' \
'I\'ve taken a total of %s%% of this computer\'s time. ' \
'Out of %s I have %s active. ' \
'I have processed %s.' %\
(user, system, user + system,
childUser, childSystem, childUser + childSystem,
(user+system+childUser+childSystem)/timeRunning,
utils.nItems(world.threadsSpawned, 'thread', 'spawned'),
activeThreads,
utils.nItems(world.commandsProcessed, 'command'))
irc.reply(msg, response)
def uptime(self, irc, msg, args):
"""takes no arguments.
Returns the amount of time the bot has been running.
"""
response = 'I have been running for %s.' % \
utils.timeElapsed(time.time() - world.startedAt)
irc.reply(msg, response)
def objects(self, irc, msg, args): def objects(self, irc, msg, args):
"""takes no arguments. """takes no arguments.
@ -545,29 +478,41 @@ class FunCommands(callbacks.Privmsg):
return return
if '.' in funcname: if '.' in funcname:
parts = funcname.split('.') parts = funcname.split('.')
module = '.'.join(parts[:-1]) functionName = parts.pop()
if module not in __builtins__ and module not in sys.modules: path = os.path.dirname(os.__file__)
path = os.path.dirname(os.__file__) for name in parts:
for name in parts[:-1]: try:
try: info = imp.find_module(name, [path])
info = imp.find_module(name, path) newmodule = imp.load_module(name, *info)
newmodule = imp.load_module(name, *info) path = os.path.dirname(newmodule.__file__)
path = newmodule.__path__ info[0].close()
info[1].close() except ImportError:
except ImportError: irc.error(msg, 'No such module %s exists.' % module)
irc.error(msg, 'No such module %s exists.' % module) return
return if hasattr(newmodule, functionName):
try: f = getattr(newmodule, functionName)
s = eval(funcname + '.__doc__') if hasattr(f, '__doc__'):
s = s.replace('\n\n', '. ') s = f.__doc__.replace('\n\n', '. ')
s = ' '.join(s.split()) s = utils.normalizeWhitespace(s)
except (SyntaxError, NameError): irc.reply(msg, s)
irc.error(msg, 'No such function exists.') else:
return irc.error(msg, 'That function has no documentation.')
except AttributeError: else:
irc.error(msg, 'That function has no documentation.') irc.error(msg, 'That function doesn\'t exist.')
return else:
irc.reply(msg, s) try:
f = __builtins__[funcname]
if hasattr(f, '__doc__'):
s = f.__doc__.replace('\n\n', '. ')
s = utils.normalizeWhitespace(s)
irc.reply(msg, s)
else:
irc.error(msg, 'That function has no documentation.')
except SyntaxError:
irc.error(msg, 'That\'s not a function!')
except KeyError:
irc.error(msg, 'That function doesn\'t exist.')
_eightballs = ( _eightballs = (
'outlook not so good.', 'outlook not so good.',

View File

@ -38,9 +38,6 @@ import utils
class FunCommandsTest(PluginTestCase, PluginDocumentation): class FunCommandsTest(PluginTestCase, PluginDocumentation):
plugins = ('FunCommands',) plugins = ('FunCommands',)
def testNoErrors(self): def testNoErrors(self):
self.assertNotError('netstats')
self.assertNotError('cpustats')
self.assertNotError('uptime')
self.assertNotError('leet foobar') self.assertNotError('leet foobar')
self.assertNotError('lithp meghan sweeney') self.assertNotError('lithp meghan sweeney')
self.assertNotError('objects') self.assertNotError('objects')
@ -54,11 +51,11 @@ class FunCommandsTest(PluginTestCase, PluginDocumentation):
for s in nicks[:10]: # 10 is probably enough. for s in nicks[:10]: # 10 is probably enough.
self.assertResponse('rot13 [rot13 %s]' % s, s) self.assertResponse('rot13 [rot13 %s]' % s, s)
def testChr(self): ## def testChr(self):
for i in range(256): ## for i in range(256):
c = chr(i) ## c = chr(i)
regexp = r'%s|%s' % (re.escape(c), re.escape(repr(c))) ## regexp = r'%s|%s' % (re.escape(c), re.escape(repr(c)))
self.assertRegexp('chr %s' % i, regexp) ## self.assertRegexp('chr %s' % i, regexp)
def testHexlifyUnhexlify(self): def testHexlifyUnhexlify(self):
for s in nicks[:10]: # 10, again, is probably enough. for s in nicks[:10]: # 10, again, is probably enough.
@ -79,11 +76,13 @@ class FunCommandsTest(PluginTestCase, PluginDocumentation):
self.assertNotError('pydoc str') self.assertNotError('pydoc str')
self.assertError('pydoc foobar') self.assertError('pydoc foobar')
self.assertError('pydoc assert') self.assertError('pydoc assert')
self.assertNotError('pydoc string.translate')
self.assertNotError('pydoc fnmatch.fnmatch')
def testOrd(self): ## def testOrd(self):
for c in map(chr, range(256)): ## for c in map(chr, range(256)):
i = ord(c) ## i = ord(c)
self.assertResponse('ord %s' % utils.dqrepr(c), str(i)) ## self.assertResponse('ord %s' % utils.dqrepr(c), str(i))
def testZen(self): def testZen(self):
self.assertNotError('zen') self.assertNotError('zen')