mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Update usage of functions in utils.gen.
This commit is contained in:
parent
0a89623b70
commit
28cb5abc65
@ -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.')
|
||||
|
@ -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'
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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.')
|
||||
|
@ -140,7 +140,7 @@ if __name__ == '__main__':
|
||||
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))
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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__ = [
|
||||
|
@ -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
|
||||
|
@ -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('.'):
|
||||
|
12
src/ircdb.py
12
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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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]
|
||||
|
@ -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 = {}
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user