mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
utils.gen.* functions shouldn't explicitly be called since they're all in the utils namespace.
This commit is contained in:
parent
0ba3b076a5
commit
90c000793d
@ -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.')
|
||||
|
@ -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'
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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):
|
||||
"""[<channel>] {increased,decreased,active}
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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('.'):
|
||||
|
12
src/ircdb.py
12
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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
@ -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]
|
||||
|
@ -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 = {}
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user