From 90c000793d494e809dcd49839b00ca0a8d78c0b0 Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 15 Feb 2005 13:57:57 +0000 Subject: [PATCH] utils.gen.* functions shouldn't explicitly be called since they're all in the utils namespace. --- plugins/Admin/plugin.py | 2 +- plugins/Babelfish/plugin.py | 2 +- plugins/Channel/plugin.py | 2 +- plugins/Config/plugin.py | 2 +- plugins/Dict/plugin.py | 2 +- plugins/Format/plugin.py | 2 +- plugins/Karma/plugin.py | 2 +- plugins/Math/plugin.py | 2 +- plugins/Misc/plugin.py | 4 ++-- plugins/Network/plugin.py | 4 ++-- plugins/Owner/plugin.py | 2 +- plugins/Status/plugin.py | 4 ++-- plugins/User/plugin.py | 2 +- plugins/__init__.py | 4 ++-- sandbox/Debug/plugin.py | 2 +- src/callbacks.py | 8 ++++---- src/commands.py | 16 +++++++--------- src/conf.py | 4 ++-- src/drivers/__init__.py | 4 ++-- src/ircdb.py | 12 ++++++------ src/irclib.py | 2 +- src/log.py | 2 +- src/registry.py | 4 ++-- src/test.py | 4 ++-- src/utils/gen.py | 2 +- test/test_irclib.py | 2 +- 26 files changed, 48 insertions(+), 50 deletions(-) diff --git a/plugins/Admin/plugin.py b/plugins/Admin/plugin.py index a104b6ce5..3de8e4de4 100644 --- a/plugins/Admin/plugin.py +++ b/plugins/Admin/plugin.py @@ -154,7 +154,7 @@ class Admin(callbacks.Plugin): """ L = irc.state.channels.keys() if L: - utils.gen.sortBy(ircutils.toLower, L) + utils.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 ce4bc07ea..035fd04a8 100644 --- a/plugins/Babelfish/plugin.py +++ b/plugins/Babelfish/plugin.py @@ -36,7 +36,7 @@ import supybot.callbacks as callbacks class Babelfish(callbacks.Plugin): threaded = True - _abbrevs = utils.gen.abbrev(map(str.lower, babelfish.available_languages)) + _abbrevs = utils.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 cafef94ad..7b8042aa8 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -784,7 +784,7 @@ class Channel(callbacks.Plugin): message isn't sent in the channel itself. """ L = list(irc.state.channels[channel].users) - utils.gen.sortBy(str.lower, L) + utils.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 b23dd54ae..0ac825dfd 100644 --- a/plugins/Config/plugin.py +++ b/plugins/Config/plugin.py @@ -117,7 +117,7 @@ class Config(callbacks.Plugin): if v._added and not all(ircutils.isChannel, v._added): vname = '@' + vname L.append(vname) - utils.gen.sortBy(str.lower, L) + utils.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 b26166d6d..ca41dabfb 100644 --- a/plugins/Dict/plugin.py +++ b/plugins/Dict/plugin.py @@ -109,7 +109,7 @@ class Dict(callbacks.Plugin): db = ircutils.bold(db) s = utils.str.normalizeWhitespace(s).rstrip(';.,') L.append('%s: %s' % (db, s)) - utils.gen.sortBy(len, L) + utils.sortBy(len, L) if dictionary == '*' and len(dbs) > 1: s = format('%L responded: %s', list(dbs), '; '.join(L)) else: diff --git a/plugins/Format/plugin.py b/plugins/Format/plugin.py index a1da45d9b..766fa97dc 100644 --- a/plugins/Format/plugin.py +++ b/plugins/Format/plugin.py @@ -184,7 +184,7 @@ class Format(callbacks.Plugin): s %= tuple(args) irc.reply(s) except TypeError, e: - self.log.debug(utils.gen.exnToString(e)) + self.log.debug(utils.exnToString(e)) irc.error('Not enough arguments for the format string.',Raise=True) diff --git a/plugins/Karma/plugin.py b/plugins/Karma/plugin.py index e2fc6a12f..4043daa84 100644 --- a/plugins/Karma/plugin.py +++ b/plugins/Karma/plugin.py @@ -327,7 +327,7 @@ class Karma(callbacks.Plugin): irc.reply(s) karma = wrap(karma, ['channel', any('something')]) - _mostAbbrev = utils.gen.abbrev(['increased', 'decreased', 'active']) + _mostAbbrev = utils.abbrev(['increased', 'decreased', 'active']) def most(self, irc, msg, args, channel, kind): """[] {increased,decreased,active} diff --git a/plugins/Math/plugin.py b/plugins/Math/plugin.py index ef932dc73..0044c2cfd 100644 --- a/plugins/Math/plugin.py +++ b/plugins/Math/plugin.py @@ -228,7 +228,7 @@ class Math(callbacks.Plugin): except NameError, e: irc.error('%s is not a defined function.' % str(e).split()[1]) except Exception, e: - irc.error(utils.gen.exnToString(e)) + irc.error(utils.exnToString(e)) icalc = wrap(icalc, [('checkCapability', 'trusted'), 'text']) _rpnEnv = { diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index b2443efa5..62881af1c 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -76,7 +76,7 @@ class Misc(callbacks.Plugin): irc.reply('You\'ve given me %s invalid commands within the last ' 'minute; I\'m now ignoring you for %s.' % (maximum, - utils.gen.timeElapsed(punishment, seconds=False))) + utils.timeElapsed(punishment, seconds=False))) return # Now, for normal handling. channel = msg.args[0] @@ -456,7 +456,7 @@ class Misc(callbacks.Plugin): L = module.__contributors__.items() def negativeSecondElement(x): return -len(x[1]) - utils.gen.sortBy(negativeSecondElement, L) + utils.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 2879a4e5c..c5638c69f 100644 --- a/plugins/Network/plugin.py +++ b/plugins/Network/plugin.py @@ -182,7 +182,7 @@ class Network(callbacks.Plugin): L = ['isn\'t on any non-secret channels'] channels = format('%L', L) if '317' in d: - idle = utils.gen.timeElapsed(d['317'].args[2]) + idle = utils.timeElapsed(d['317'].args[2]) signon = time.strftime(conf.supybot.reply.format.time(), time.localtime(float(d['317'].args[3]))) else: @@ -241,7 +241,7 @@ class Network(callbacks.Plugin): Returns the networks to which the bot is currently connected. """ L = ['%s: %s' % (ircd.network, ircd.server) for ircd in world.ircs] - utils.gen.sortBy(str.lower, L) + utils.sortBy(str.lower, L) irc.reply(format('%L', L)) networks = wrap(networks) diff --git a/plugins/Owner/plugin.py b/plugins/Owner/plugin.py index 0629a5e76..d16187583 100644 --- a/plugins/Owner/plugin.py +++ b/plugins/Owner/plugin.py @@ -323,7 +323,7 @@ class Owner(callbacks.Plugin): try: m = ircmsgs.IrcMsg(s) except Exception, e: - irc.error(utils.gen.exnToString(e)) + irc.error(utils.exnToString(e)) else: irc.queueMsg(m) irc.noReply() diff --git a/plugins/Status/plugin.py b/plugins/Status/plugin.py index 5e69bef9c..37c50d0da 100644 --- a/plugins/Status/plugin.py +++ b/plugins/Status/plugin.py @@ -99,7 +99,7 @@ class Status(callbacks.Plugin): """ try: elapsed = time.time() - self.connected[irc.getRealIrc()] - timeElapsed = utils.gen.timeElapsed(elapsed) + timeElapsed = utils.timeElapsed(elapsed) except KeyError: timeElapsed = 'an indeterminate amount of time' irc.reply('I have received %s messages for a total of %s bytes. ' @@ -200,7 +200,7 @@ class Status(callbacks.Plugin): Returns the amount of time the bot has been running. """ response = 'I have been running for %s.' % \ - utils.gen.timeElapsed(time.time() - world.startedAt) + utils.timeElapsed(time.time() - world.startedAt) irc.reply(response) uptime = wrap(uptime) diff --git a/plugins/User/plugin.py b/plugins/User/plugin.py index dd95f4bbe..945cbbdc1 100644 --- a/plugins/User/plugin.py +++ b/plugins/User/plugin.py @@ -70,7 +70,7 @@ class User(callbacks.Plugin): else: users.append(u.name) if users: - utils.gen.sortBy(str.lower, users) + utils.sortBy(str.lower, users) irc.reply(format('%L', users)) else: if predicates: diff --git a/plugins/__init__.py b/plugins/__init__.py index 7eb96e846..db5400621 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -279,11 +279,11 @@ class ChannelUserDB(ChannelUserDictionary): except Exception, e: log.warning('Invalid line #%s in %s.', lineno, self.__class__.__name__) - log.debug('Exception: %s', utils.gen.exnToString(e)) + log.debug('Exception: %s', utils.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.gen.exnToString(e)) + log.debug('Exception: %s', utils.exnToString(e)) def flush(self): fd = utils.file.AtomicFile(self.filename, makeBackupIfSmaller=False) diff --git a/sandbox/Debug/plugin.py b/sandbox/Debug/plugin.py index e6adb7e02..2418c166b 100644 --- a/sandbox/Debug/plugin.py +++ b/sandbox/Debug/plugin.py @@ -89,7 +89,7 @@ class Debug(callbacks.Privmsg): self._evalEnv['_'] = x irc.reply(repr(x)) except SyntaxError, e: - irc.reply(format('%s: %q', utils.gen.exnToString(e), s)) + irc.reply(format('%s: %q', utils.exnToString(e), s)) eval = wrap(eval, ['text']) def _exec(self, irc, msg, args, s): diff --git a/src/callbacks.py b/src/callbacks.py index f403a0cef..6b1819749 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -647,7 +647,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.gen.exnToString(e)) + return self.error(utils.exnToString(e)) else: return self.replyError() finally: @@ -1055,7 +1055,7 @@ class Commands(object): except (getopt.GetoptError, ArgumentError): irc.reply(formatArgumentError(method, name=name)) except (SyntaxError, Error), e: - self.log.debug('Error return: %s', utils.gen.exnToString(e)) + self.log.debug('Error return: %s', utils.exnToString(e)) irc.error(str(e)) elapsed = time.time() - start @@ -1128,7 +1128,7 @@ class PluginMixin(irclib.IrcCallback): handleBadArgs() else: handleBadArgs() - dispatcher = utils.gen.changeFunctionName(dispatcher, canonicalname) + dispatcher = utils.changeFunctionName(dispatcher, canonicalname) if self._original: dispatcher.__doc__ = self._original.__doc__ dispatcher.isDispatcher = False @@ -1287,7 +1287,7 @@ class PluginRegexp(Plugin): if catchErrors: self.log.exception('Uncaught exception in callCommand:') if conf.supybot.reply.error.detailed(): - irc.error(utils.gen.exnToString(e)) + irc.error(utils.exnToString(e)) else: irc.replyError() else: diff --git a/src/commands.py b/src/commands.py index c242fcfb5..018d240f8 100644 --- a/src/commands.py +++ b/src/commands.py @@ -65,7 +65,7 @@ def thread(f): t.start() else: f(self, irc, msg, args, *L, **kwargs) - return utils.gen.changeFunctionName(newf, f.func_name, f.__doc__) + return utils.changeFunctionName(newf, f.func_name, f.__doc__) class UrlSnarfThread(world.SupyThread): def __init__(self, *args, **kwargs): @@ -79,7 +79,7 @@ class UrlSnarfThread(world.SupyThread): try: super(UrlSnarfThread, self).run() except utils.web.Error, e: - log.debug('Exception in urlSnarfer: %s' % utils.gen.exnToString(e)) + log.debug('Exception in urlSnarfer: %s' % utils.exnToString(e)) class SnarfQueue(ircutils.FloodQueue): timeout = conf.supybot.snarfThrottle @@ -133,7 +133,7 @@ def urlSnarfer(f): L = list(L) t = UrlSnarfThread(target=doSnarf, url=url) t.start() - newf = utils.gen.changeFunctionName(newf, f.func_name, f.__doc__) + newf = utils.changeFunctionName(newf, f.func_name, f.__doc__) return newf @@ -521,7 +521,7 @@ def getLiteral(irc, msg, args, state, literals, errmsg=None): # ??? Should we allow abbreviations? if isinstance(literals, basestring): literals = (literals,) - abbrevs = utils.gen.abbrev(literals) + abbrevs = utils.abbrev(literals) if args[0] in abbrevs: state.args.append(abbrevs[args.pop(0)]) elif errmsg is not None: @@ -702,7 +702,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.gen.exnToString(e)) + log.debug('Got %s, returning default.', utils.exnToString(e)) setDefault(state, self.default) class any(context): @@ -722,8 +722,7 @@ class any(context): if not self.continueOnError: raise else: - log.debug('Got %s, returning default.', - utils.gen.exnToString(e)) + log.debug('Got %s, returning default.', utils.exnToString(e)) pass state.args.append(st.args) @@ -879,8 +878,7 @@ def wrap(f, specList=[], **kw): funcArgs = inspect.getargs(f.func_code)[0][len(self.commandArgs):] self.log.error('Extra args: %s', funcArgs) raise - return utils.gen.changeFunctionName(newf, f.func_name, f.__doc__) - + return utils.changeFunctionName(newf, f.func_name, f.__doc__) __all__ = [ # Contexts. diff --git a/src/conf.py b/src/conf.py index f90395b83..44cd99d8c 100644 --- a/src/conf.py +++ b/src/conf.py @@ -300,11 +300,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.gen.timeElapsed +originalTimeElapsed = utils.timeElapsed def timeElapsed(*args, **kwargs): kwargs['short'] = supybot.reply.format.time.elapsed.short() return originalTimeElapsed(*args, **kwargs) -utils.gen.timeElapsed = timeElapsed +utils.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 21d95e85c..25c0e99cb 100644 --- a/src/drivers/__init__.py +++ b/src/drivers/__init__.py @@ -138,13 +138,13 @@ class Log(object): if isinstance(e, socket.gaierror): e = e.args[1] else: - e = utils.gen.exnToString(e) + e = utils.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.gen.exnToString(e) + e = utils.exnToString(e) else: e = str(e) if not e.endswith('.'): diff --git a/src/ircdb.py b/src/ircdb.py index e2c41d842..2f7cc8891 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -249,7 +249,7 @@ class IrcUser(object): """Sets the user's password.""" if hashed or self.hashed: self.hashed = True - self.password = utils.gen.saltHash(password) + self.password = utils.saltHash(password) else: self.password = password @@ -257,7 +257,7 @@ class IrcUser(object): """Checks the user's password.""" if self.hashed: (salt, _) = self.password.split('|') - return (self.password == utils.gen.saltHash(password, salt=salt)) + return (self.password == utils.saltHash(password, salt=salt)) else: return (self.password == password) @@ -437,11 +437,11 @@ class IrcChannel(object): for capability in self.capabilities: write('capability ' + capability) bans = self.bans.items() - utils.gen.sortBy(operator.itemgetter(1), bans) + utils.sortBy(operator.itemgetter(1), bans) for (ban, expiration) in bans: write('ban %s %d' % (ban, expiration)) ignores = self.ignores.items() - utils.gen.sortBy(operator.itemgetter(1), ignores) + utils.sortBy(operator.itemgetter(1), ignores) for (ignore, expiration) in ignores: write('ignore %s %d' % (ignore, expiration)) fd.write(os.linesep) @@ -578,7 +578,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.gen.exnToString(e)) + log.error('Exact error: %s', utils.exnToString(e)) except Exception, e: log.exception('Exact error:') finally: @@ -773,7 +773,7 @@ class ChannelsDictionary(utils.IterableMap): self.flush() except Exception, e: log.error('Invalid channel database, resetting to empty.') - log.error('Exact error: %s', utils.gen.exnToString(e)) + log.error('Exact error: %s', utils.exnToString(e)) finally: self.noFlush = False diff --git a/src/irclib.py b/src/irclib.py index f868bf29e..5031f0d61 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -966,7 +966,7 @@ class Irc(IrcCommandDispatcher): log.debug('Last Irc, clearing callbacks.') self.callbacks[:] = [] else: - log.warning('Irc object killed twice: %s', utils.gen.stackTrace()) + log.warning('Irc object killed twice: %s', utils.stackTrace()) def __hash__(self): return id(self) diff --git a/src/log.py b/src/log.py index ef275cacf..7b4e670f2 100644 --- a/src/log.py +++ b/src/log.py @@ -107,7 +107,7 @@ class StdoutStreamHandler(logging.StreamHandler): if not isinstance(record.levelname, basestring): print record print record.levelname - print utils.gen.stackTrace() + print utils.stackTrace() prefixLen = len(record.levelname) + 1 # ' ' s = textwrap.fill(s, width=78, subsequent_indent=' '*prefixLen) s.rstrip('\r\n') diff --git a/src/registry.py b/src/registry.py index b6661cee4..ab4a57e39 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.gen.safeEval(s) + v = utils.safeEval(s) if not isinstance(v, basestring): raise ValueError self.setValue(v) - except ValueError: # This catches utils.gen.safeEval(s) errors too. + except ValueError: # This catches utils.safeEval(s) errors too. self.error() _printable = string.printable[:-4] diff --git a/src/test.py b/src/test.py index b76606df6..c63f782d7 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.gen.exnToString(e)) + irc.reply(utils.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.gen.changeFunctionName(runTest, methodName) + runTest = utils.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 11d7bb63c..63b01eb11 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.gen.abbrev have duplicates: %r' % strings + 'strings given to utils.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 0cf874774..391cb05be 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -97,7 +97,7 @@ class IrcMsgQueueTestCase(SupyTestCase): repr(q) except Exception, e: self.fail('repr(q) raised an exception: %s' % - utils.gen.exnToString(e)) + utils.exnToString(e)) def testEmpty(self): q = irclib.IrcMsgQueue()