diff --git a/plugins/Admin/plugin.py b/plugins/Admin/plugin.py index 9da5434dd..6f891b246 100644 --- a/plugins/Admin/plugin.py +++ b/plugins/Admin/plugin.py @@ -154,7 +154,7 @@ class Admin(callbacks.Privmsg): """ L = irc.state.channels.keys() if L: - utils.sortBy(ircutils.toLower, L) + utils.gen.sortBy(ircutils.toLower, L) irc.reply(format('%L', L)) else: irc.reply('I\'m not currently in any channels.') diff --git a/plugins/Babelfish/plugin.py b/plugins/Babelfish/plugin.py index 700112cb5..35db0045f 100644 --- a/plugins/Babelfish/plugin.py +++ b/plugins/Babelfish/plugin.py @@ -38,7 +38,7 @@ import supybot.callbacks as callbacks class Babelfish(callbacks.Privmsg): threaded = True - _abbrevs = utils.abbrev(map(str.lower, babelfish.available_languages)) + _abbrevs = utils.gen.abbrev(map(str.lower, babelfish.available_languages)) _abbrevs['de'] = 'german' _abbrevs['jp'] = 'japanese' _abbrevs['kr'] = 'korean' diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index caa93950e..a194a690e 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -786,7 +786,7 @@ class Channel(callbacks.Privmsg): message isn't sent in the channel itself. """ L = list(irc.state.channels[channel].users) - utils.sortBy(str.lower, L) + utils.gen.sortBy(str.lower, L) irc.reply(utils.str.commaAndify(L)) nicks = wrap(nicks, ['inChannel']) # XXX Check that the caller is in chan. diff --git a/plugins/Config/plugin.py b/plugins/Config/plugin.py index f48c3846b..696dc3adc 100644 --- a/plugins/Config/plugin.py +++ b/plugins/Config/plugin.py @@ -116,7 +116,7 @@ class Config(callbacks.Privmsg): if v._added and not all(ircutils.isChannel, v._added): vname = '@' + vname L.append(vname) - utils.sortBy(str.lower, L) + utils.gen.sortBy(str.lower, L) return L def list(self, irc, msg, args, group): diff --git a/plugins/Dict/plugin.py b/plugins/Dict/plugin.py index b3270d842..0e4e5c34d 100644 --- a/plugins/Dict/plugin.py +++ b/plugins/Dict/plugin.py @@ -111,7 +111,7 @@ class Dict(callbacks.Privmsg): db = ircutils.bold(db) s = utils.str.normalizeWhitespace(s).rstrip(';.,') L.append('%s: %s' % (db, s)) - utils.sortBy(len, L) + utils.gen.sortBy(len, L) if dictionary == '*' and len(dbs) > 1: s = '%s responded: %s' % (utils.str.commaAndify(dbs), '; '.join(L)) else: diff --git a/plugins/Format/plugin.py b/plugins/Format/plugin.py index 9b39c7fbe..edcd0f11c 100644 --- a/plugins/Format/plugin.py +++ b/plugins/Format/plugin.py @@ -184,7 +184,7 @@ class Format(callbacks.Privmsg): s %= tuple(args) irc.reply(s) except TypeError, e: - self.log.debug(utils.exnToString(e)) + self.log.debug(utils.gen.exnToString(e)) irc.error('Not enough arguments for the format string.',Raise=True) diff --git a/plugins/Math/plugin.py b/plugins/Math/plugin.py index 0655483bd..f508c74ae 100644 --- a/plugins/Math/plugin.py +++ b/plugins/Math/plugin.py @@ -230,7 +230,7 @@ class Math(callbacks.Privmsg): except NameError, e: irc.error('%s is not a defined function.' % str(e).split()[1]) except Exception, e: - irc.error(utils.exnToString(e)) + irc.error(utils.gen.exnToString(e)) icalc = wrap(icalc, [('checkCapability', 'trusted'), 'text']) _rpnEnv = { diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 3609c086f..f0a040406 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -73,7 +73,8 @@ class Misc(callbacks.Privmsg): ircdb.ignores.add(banmask, time.time() + punishment) irc.reply('You\'ve given me %s invalid commands within the last ' 'minute; I\'m now ignoring you for %s.' % - (maximum, utils.timeElapsed(punishment, seconds=False))) + (maximum, + utils.gen.timeElapsed(punishment, seconds=False))) return # Now, for normal handling. channel = msg.args[0] @@ -499,7 +500,7 @@ class Misc(callbacks.Privmsg): L = module.__contributors__.items() def negativeSecondElement(x): return -len(x[1]) - utils.sortBy(negativeSecondElement, L) + utils.gen.sortBy(negativeSecondElement, L) return [t[0] for t in L] def buildPeopleString(module): """ diff --git a/plugins/Network/plugin.py b/plugins/Network/plugin.py index bc9e74b4d..7fe687dcc 100644 --- a/plugins/Network/plugin.py +++ b/plugins/Network/plugin.py @@ -182,7 +182,7 @@ class Network(callbacks.Privmsg): L = ['isn\'t on any non-secret channels'] channels = utils.str.commaAndify(L) if '317' in d: - idle = utils.timeElapsed(d['317'].args[2]) + idle = utils.gen.timeElapsed(d['317'].args[2]) signon = time.strftime(conf.supybot.reply.format.time(), time.localtime(float(d['317'].args[3]))) else: diff --git a/plugins/Owner/plugin.py b/plugins/Owner/plugin.py index e87e5d564..0e56e11ca 100644 --- a/plugins/Owner/plugin.py +++ b/plugins/Owner/plugin.py @@ -321,7 +321,7 @@ class Owner(callbacks.Privmsg): try: m = ircmsgs.IrcMsg(s) except Exception, e: - irc.error(utils.exnToString(e)) + irc.error(utils.gen.exnToString(e)) else: irc.queueMsg(m) irc.noReply() diff --git a/plugins/Status/plugin.py b/plugins/Status/plugin.py index 2bd29705f..8723a36b8 100644 --- a/plugins/Status/plugin.py +++ b/plugins/Status/plugin.py @@ -99,7 +99,7 @@ class Status(callbacks.Privmsg): """ try: elapsed = time.time() - self.connected[irc.getRealIrc()] - timeElapsed = utils.timeElapsed(elapsed) + timeElapsed = utils.gen.timeElapsed(elapsed) except KeyError: timeElapsed = 'an indeterminate amount of time' irc.reply('I have received %s messages for a total of %s bytes. ' @@ -202,7 +202,7 @@ class Status(callbacks.Privmsg): Returns the amount of time the bot has been running. """ response = 'I have been running for %s.' % \ - utils.timeElapsed(time.time() - world.startedAt) + utils.gen.timeElapsed(time.time() - world.startedAt) irc.reply(response) uptime = wrap(uptime) diff --git a/plugins/__init__.py b/plugins/__init__.py index 4dd6eaf76..613b98e32 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -313,11 +313,11 @@ class ChannelUserDB(ChannelUserDictionary): except Exception, e: log.warning('Invalid line #%s in %s.', lineno, self.__class__.__name__) - log.debug('Exception: %s', utils.exnToString(e)) + log.debug('Exception: %s', utils.gen.exnToString(e)) except Exception, e: # This catches exceptions from csv.reader. log.warning('Invalid line #%s in %s.', lineno, self.__class__.__name__) - log.debug('Exception: %s', utils.exnToString(e)) + log.debug('Exception: %s', utils.gen.exnToString(e)) def flush(self): fd = utils.file.AtomicFile(self.filename, makeBackupIfSmaller=False) diff --git a/scripts/supybot b/scripts/supybot index a859467cd..c516a2491 100644 --- a/scripts/supybot +++ b/scripts/supybot @@ -109,7 +109,8 @@ def main(): print 'Exception raised in log.exception. This is *really*' print 'bad. Hopefully it won\'t happen again, but tell us' print 'about it anyway, this is a significant problem.' - print 'Anyway, here\'s the exception: %s'% utils.exnToString(e) + print 'Anyway, here\'s the exception: %s' % \ + utils.gen.exnToString(e) except: print 'Man, this really sucks. Not only did log.exception' print 'raise an exception, but freaking-a, it was a string' @@ -117,7 +118,7 @@ def main(): print 'die a slow, painful death.' now = time.time() seconds = now - world.startedAt - log.info('Total uptime: %s.', utils.timeElapsed(seconds)) + log.info('Total uptime: %s.', utils.gen.timeElapsed(seconds)) (user, system, _, _, _) = os.times() log.info('Total CPU time taken: %s seconds.', user+system) log.info('No more Irc objects, exiting.') diff --git a/scripts/supybot-test b/scripts/supybot-test index 3a10a3a3e..e790e1509 100644 --- a/scripts/supybot-test +++ b/scripts/supybot-test @@ -133,14 +133,14 @@ if __name__ == '__main__': if not args: parser.print_help() sys.exit(-1) - + if options.timeout: test.timeout = options.timeout if options.trace: traceFilename = conf.supybot.directories.log.dirize('trace.log') fd = file(traceFilename, 'w') - sys.settrace(utils.callTracer(fd)) + sys.settrace(utils.gen.callTracer(fd)) atexit.register(fd.close) atexit.register(lambda : sys.settrace(None)) @@ -172,7 +172,7 @@ if __name__ == '__main__': sys.exit(-1) if hasattr(pluginModule, 'test'): test.suites.append(load(pluginModule.test)) - + suite = unittest.TestSuite(test.suites) runner = unittest.TextTestRunner(verbosity=2) print 'Testing began at %s (pid %s)' % (time.ctime(), os.getpid()) diff --git a/scripts/supybot-wizard b/scripts/supybot-wizard index b19631ceb..df9dd8771 100644 --- a/scripts/supybot-wizard +++ b/scripts/supybot-wizard @@ -92,7 +92,7 @@ def loadPlugin(name): except Exception, e: output("""We encountered a bit of trouble trying to load plugin %r. Python told us %r. We'll skip over it for now, you can always add it - later.""" % (name, utils.exnToString(e))) + later.""" % (name, utils.gen.exnToString(e))) return None def describePlugin(module, showUsage): diff --git a/src/callbacks.py b/src/callbacks.py index 090ff1605..a6b1f10ba 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -659,7 +659,7 @@ class IrcObjectProxy(RichReplyMethods): cb.log.exception('Uncaught exception in %s.%s:', cb.name(), name) if conf.supybot.reply.error.detailed(): - return self.error(utils.exnToString(e)) + return self.error(utils.gen.exnToString(e)) else: return self.replyError() finally: @@ -1079,7 +1079,7 @@ class Privmsg(irclib.IrcCallback): handleBadArgs() else: handleBadArgs() - dispatcher = utils.changeFunctionName(dispatcher, canonicalname) + dispatcher = utils.gen.changeFunctionName(dispatcher, canonicalname) if self._original: dispatcher.__doc__ = self._original.__doc__ dispatcher.isDispatcher = False @@ -1139,7 +1139,7 @@ class Privmsg(irclib.IrcCallback): except (getopt.GetoptError, ArgumentError): irc.reply(formatArgumentError(method, name=name)) except (SyntaxError, Error), e: - self.log.debug('Error return: %s', utils.exnToString(e)) + self.log.debug('Error return: %s', utils.gen.exnToString(e)) irc.error(str(e)) elapsed = time.time() - start log.stat('%s took %s seconds', name, elapsed) @@ -1299,7 +1299,7 @@ class PrivmsgRegexp(Privmsg): self.log.exception('Uncaught exception in %s.%s:', self.name(), name) if conf.supybot.reply.error.detailed(): - irc.error(utils.exnToString(e)) + irc.error(utils.gen.exnToString(e)) else: irc.replyError() @@ -1363,7 +1363,7 @@ class PrivmsgCommandAndRegexp(Privmsg): if catchErrors: self.log.exception('Uncaught exception in callCommand:') if conf.supybot.reply.error.detailed(): - irc.error(utils.exnToString(e)) + irc.error(utils.gen.exnToString(e)) else: irc.replyError() else: diff --git a/src/commands.py b/src/commands.py index 95bdb7b76..5615d02b3 100644 --- a/src/commands.py +++ b/src/commands.py @@ -64,7 +64,7 @@ def thread(f): t.start() else: f(self, irc, msg, args, *L, **kwargs) - return utils.changeFunctionName(newf, f.func_name, f.__doc__) + return utils.gen.changeFunctionName(newf, f.func_name, f.__doc__) class UrlSnarfThread(world.SupyThread): def __init__(self, *args, **kwargs): @@ -78,7 +78,7 @@ class UrlSnarfThread(world.SupyThread): try: super(UrlSnarfThread, self).run() except utils.web.Error, e: - log.debug('Exception in urlSnarfer: %s' % utils.exnToString(e)) + log.debug('Exception in urlSnarfer: %s' % utils.gen.exnToString(e)) class SnarfQueue(ircutils.FloodQueue): timeout = conf.supybot.snarfThrottle @@ -132,7 +132,7 @@ def urlSnarfer(f): L = list(L) t = UrlSnarfThread(target=doSnarf, url=url) t.start() - newf = utils.changeFunctionName(newf, f.func_name, f.__doc__) + newf = utils.gen.changeFunctionName(newf, f.func_name, f.__doc__) return newf @@ -514,7 +514,7 @@ def getLiteral(irc, msg, args, state, literals, errmsg=None): # ??? Should we allow abbreviations? if isinstance(literals, basestring): literals = (literals,) - abbrevs = utils.abbrev(literals) + abbrevs = utils.gen.abbrev(literals) if args[0] in abbrevs: state.args.append(abbrevs[args.pop(0)]) elif errmsg is not None: @@ -694,7 +694,7 @@ class optional(additional): try: super(optional, self).__call__(irc, msg, args, state) except (callbacks.ArgumentError, callbacks.Error), e: - log.debug('Got %s, returning default.', utils.exnToString(e)) + log.debug('Got %s, returning default.', utils.gen.exnToString(e)) setDefault(state, self.default) class any(context): @@ -714,7 +714,8 @@ class any(context): if not self.continueOnError: raise else: - log.debug('Got %s, returning default.', utils.exnToString(e)) + log.debug('Got %s, returning default.', + utils.gen.exnToString(e)) pass state.args.append(st.args) @@ -863,7 +864,7 @@ def wrap(f, specList=[], **kw): state = spec(irc, msg, args, stateAttrs={'cb': self, 'log': self.log}) self.log.debug('State before call: %s' % state) f(self, irc, msg, args, *state.args, **state.kwargs) - return utils.changeFunctionName(newf, f.func_name, f.__doc__) + return utils.gen.changeFunctionName(newf, f.func_name, f.__doc__) __all__ = [ diff --git a/src/conf.py b/src/conf.py index 2377d0138..3407a36c0 100644 --- a/src/conf.py +++ b/src/conf.py @@ -292,11 +292,11 @@ registerChannelValue(supybot.reply.format.time.elapsed, 'short', registry.Boolean(False, """Determines whether elapsed times will be given as "1 day, 2 hours, 3 minutes, and 15 seconds" or as "1d 2h 3m 15s".""")) -originalTimeElapsed = utils.timeElapsed +originalTimeElapsed = utils.gen.timeElapsed def timeElapsed(*args, **kwargs): kwargs['short'] = supybot.reply.format.time.elapsed.short() return originalTimeElapsed(*args, **kwargs) -utils.timeElapsed = timeElapsed +utils.gen.timeElapsed = timeElapsed registerGlobalValue(supybot.reply, 'maximumLength', registry.Integer(512*256, """Determines the absolute maximum length of the diff --git a/src/drivers/__init__.py b/src/drivers/__init__.py index a497993a0..ecb0fea21 100644 --- a/src/drivers/__init__.py +++ b/src/drivers/__init__.py @@ -140,13 +140,13 @@ class Log(object): if isinstance(e, socket.gaierror): e = e.args[1] else: - e = utils.exnToString(e) + e = utils.gen.exnToString(e) self.warning('Error connecting to %s: %s', server, e) def disconnect(self, server, e=None): if e: if isinstance(e, Exception): - e = utils.exnToString(e) + e = utils.gen.exnToString(e) else: e = str(e) if not e.endswith('.'): diff --git a/src/ircdb.py b/src/ircdb.py index 4b362fcf0..93352f61e 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -252,7 +252,7 @@ class IrcUser(object): """Sets the user's password.""" if hashed or self.hashed: self.hashed = True - self.password = utils.saltHash(password) + self.password = utils.gen.saltHash(password) else: self.password = password @@ -260,7 +260,7 @@ class IrcUser(object): """Checks the user's password.""" if self.hashed: (salt, _) = self.password.split('|') - return (self.password == utils.saltHash(password, salt=salt)) + return (self.password == utils.gen.saltHash(password, salt=salt)) else: return (self.password == password) @@ -440,11 +440,11 @@ class IrcChannel(object): for capability in self.capabilities: write('capability ' + capability) bans = self.bans.items() - utils.sortBy(operator.itemgetter(1), bans) + utils.gen.sortBy(operator.itemgetter(1), bans) for (ban, expiration) in bans: write('ban %s %d' % (ban, expiration)) ignores = self.ignores.items() - utils.sortBy(operator.itemgetter(1), ignores) + utils.gen.sortBy(operator.itemgetter(1), ignores) for (ignore, expiration) in ignores: write('ignore %s %d' % (ignore, expiration)) fd.write(os.linesep) @@ -581,7 +581,7 @@ class UsersDictionary(utils.IterableMap): self.flush() except EnvironmentError, e: log.error('Invalid user dictionary file, resetting to empty.') - log.error('Exact error: %s', utils.exnToString(e)) + log.error('Exact error: %s', utils.gen.exnToString(e)) except Exception, e: log.exception('Exact error:') finally: @@ -777,7 +777,7 @@ class ChannelsDictionary(utils.IterableMap): self.flush() except Exception, e: log.error('Invalid channel database, resetting to empty.') - log.error('Exact error: %s', utils.exnToString(e)) + log.error('Exact error: %s', utils.gen.exnToString(e)) finally: self.noFlush = False diff --git a/src/irclib.py b/src/irclib.py index 3941354d7..faf70378e 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -970,7 +970,7 @@ class Irc(IrcCommandDispatcher): log.debug('Last Irc, clearing callbacks.') self.callbacks[:] = [] else: - log.warning('Irc object killed twice: %s', utils.stackTrace()) + log.warning('Irc object killed twice: %s', utils.gen.stackTrace()) def __hash__(self): return id(self) diff --git a/src/log.py b/src/log.py index ecaa874b9..54860ef19 100644 --- a/src/log.py +++ b/src/log.py @@ -109,7 +109,7 @@ class StdoutStreamHandler(logging.StreamHandler): if not isinstance(record.levelname, basestring): print record print record.levelname - print utils.stackTrace() + print utils.gen.stackTrace() prefixLen = len(record.levelname) + 1 # ' ' s = textwrap.fill(s, width=78, subsequent_indent=' '*prefixLen) s.rstrip('\r\n') @@ -337,7 +337,7 @@ def firewall(f, errorHandler=None): except Exception, e: logException(self, 'Uncaught exception in errorHandler') - m = utils.changeFunctionName(m, f.func_name, f.__doc__) + m = utils.gen.changeFunctionName(m, f.func_name, f.__doc__) return m class MetaFirewall(type): @@ -377,7 +377,7 @@ except EnvironmentError, e: 'Generally, this is because you are running Supybot in a directory ' \ 'you don\'t have permissions to add files in, or you\'re running ' \ 'Supybot as a different user than you normal do. The original ' \ - 'error was: %s' % (miscLogFilename, utils.exnToString(e)) + 'error was: %s' % (miscLogFilename, utils.gen.exnToString(e)) _handler.setFormatter(formatter) _handler.setLevel(-1) class PluginLogFilter(logging.Filter): diff --git a/src/plugin.py b/src/plugin.py index b1a0cf8a5..b6334a903 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -112,3 +112,5 @@ def loadPluginClass(irc, module, register=None): pass # The plugin isn't there. irc.addCallback(cb) return cb + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/src/registry.py b/src/registry.py index 696185c1a..cd654447d 100644 --- a/src/registry.py +++ b/src/registry.py @@ -430,11 +430,11 @@ class String(Value): elif s[0] != s[-1] or s[0] not in '\'"': s = repr(s) try: - v = utils.safeEval(s) + v = utils.gen.safeEval(s) if not isinstance(v, basestring): raise ValueError self.setValue(v) - except ValueError: # This catches utils.safeEval(s) errors too. + except ValueError: # This catches utils.gen.safeEval(s) errors too. self.error() _printable = string.printable[:-4] diff --git a/src/test.py b/src/test.py index 55a33abb9..af5850fa6 100644 --- a/src/test.py +++ b/src/test.py @@ -84,7 +84,7 @@ class TestPlugin(callbacks.Privmsg): try: irc.reply(repr(eval(' '.join(args)))) except Exception, e: - irc.reply(utils.exnToString(e)) + irc.reply(utils.gen.exnToString(e)) # Since we know we don't now need the Irc object, we just give None. This # might break if callbacks.Privmsg ever *requires* the Irc object. TestInstance = TestPlugin(None) @@ -126,7 +126,7 @@ class PluginTestCase(SupyTestCase): run = False if run: originalRunTest() - runTest = utils.changeFunctionName(runTest, methodName) + runTest = utils.gen.changeFunctionName(runTest, methodName) setattr(self.__class__, methodName, runTest) SupyTestCase.__init__(self, methodName=methodName) self.originals = {} diff --git a/src/utils/gen.py b/src/utils/gen.py index 4223145c9..5bdde8f92 100644 --- a/src/utils/gen.py +++ b/src/utils/gen.py @@ -50,7 +50,7 @@ def abbrev(strings, d=None): yield s[:i] if len(strings) != len(set(strings)): raise ValueError, \ - 'strings given to utils.abbrev have duplicates: %r' % strings + 'strings given to utils.gen.abbrev have duplicates: %r' % strings if d is None: d = {} for s in strings: diff --git a/test/test_irclib.py b/test/test_irclib.py index 2fba1484c..d6216c1fd 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -83,7 +83,8 @@ class IrcMsgQueueTestCase(SupyTestCase): try: repr(q) except Exception, e: - self.fail('repr(q) raised an exception: %s' % utils.exnToString(e)) + self.fail('repr(q) raised an exception: %s' % + utils.gen.exnToString(e)) def testEmpty(self): q = irclib.IrcMsgQueue()