mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-06 09:34:05 +01:00
Update usage of utils.str functions.
This commit is contained in:
parent
47aa4c0f7c
commit
de89bf0265
@ -184,8 +184,8 @@ class Admin(callbacks.Privmsg):
|
|||||||
def do438(self, irc, msg):
|
def do438(self, irc, msg):
|
||||||
irc = self.pendingNickChanges.get(irc, None)
|
irc = self.pendingNickChanges.get(irc, None)
|
||||||
if irc is not None:
|
if irc is not None:
|
||||||
irc.error('I can\'t change nicks, the server said %s.' %
|
irc.error(format('I can\'t change nicks, the server said %q.',
|
||||||
utils.str.quoted(msg.args[2]), private=True)
|
msg.args[2]), private=True)
|
||||||
else:
|
else:
|
||||||
self.log.debug('Got 438 without Admin.nick being called.')
|
self.log.debug('Got 438 without Admin.nick being called.')
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
|
|
||||||
Returns the languages that Babelfish can translate to/from.
|
Returns the languages that Babelfish can translate to/from.
|
||||||
"""
|
"""
|
||||||
irc.reply(utils.str.commaAndify(babelfish.available_languages))
|
irc.reply(format('%L', babelfish.available_languages))
|
||||||
|
|
||||||
def translate(self, irc, msg, args, fromLang, toLang, text):
|
def translate(self, irc, msg, args, fromLang, toLang, text):
|
||||||
"""<from-language> [to] <to-language> <text>
|
"""<from-language> [to] <to-language> <text>
|
||||||
@ -77,20 +77,20 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
try:
|
try:
|
||||||
(fromLang, toLang) = self._getLang(fromLang, toLang, chan)
|
(fromLang, toLang) = self._getLang(fromLang, toLang, chan)
|
||||||
if not fromLang or not toLang:
|
if not fromLang or not toLang:
|
||||||
langs = self.registryValue('languages', chan)
|
langs = list(self.registryValue('languages', chan))
|
||||||
if not langs:
|
if not langs:
|
||||||
irc.error('I do not speak any other languages.')
|
irc.error('I do not speak any other languages.')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
irc.error('I only speak %s.' % utils.str.commaAndify(langs))
|
irc.error(format('I only speak %L.', langs))
|
||||||
return
|
return
|
||||||
translation = babelfish.translate(text, fromLang, toLang)
|
translation = babelfish.translate(text, fromLang, toLang)
|
||||||
irc.reply(utils.web.htmlToText(translation))
|
irc.reply(utils.web.htmlToText(translation))
|
||||||
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
||||||
languages = self.registryValue('languages', chan)
|
languages = self.registryValue('languages', chan)
|
||||||
if languages:
|
if languages:
|
||||||
languages = 'Valid languages include %s' % \
|
languages = format('Valid languages include %L',
|
||||||
utils.str.commaAndify(sorted(languages))
|
sorted(languages))
|
||||||
else:
|
else:
|
||||||
languages = 'I do not speak any other languages.'
|
languages = 'I do not speak any other languages.'
|
||||||
irc.errorInvalid('language', str(e), languages)
|
irc.errorInvalid('language', str(e), languages)
|
||||||
@ -120,16 +120,15 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
irc.error('I do not speak any other languages.')
|
irc.error('I do not speak any other languages.')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
irc.error('I only speak %s.' % utils.str.commaAndify(langs,
|
irc.error(format('I only speak %L.', (langs, 'or')))
|
||||||
And='or'))
|
|
||||||
return
|
return
|
||||||
translations = babelfish.babelize(text, fromLang, toLang)
|
translations = babelfish.babelize(text, fromLang, toLang)
|
||||||
irc.reply(utils.web.htmlToText(translations[-1]))
|
irc.reply(utils.web.htmlToText(translations[-1]))
|
||||||
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
||||||
languages = self.registryValue('languages', chan)
|
languages = self.registryValue('languages', chan)
|
||||||
if languages:
|
if languages:
|
||||||
languages = 'Valid languages include %s' % \
|
languages = format('Valid languages include %L',
|
||||||
utils.str.commaAndify(sorted(languages))
|
sorted(languages))
|
||||||
else:
|
else:
|
||||||
languages = 'I do not speak any other languages.'
|
languages = 'I do not speak any other languages.'
|
||||||
irc.errorInvalid('language', str(e), languages)
|
irc.errorInvalid('language', str(e), languages)
|
||||||
|
@ -46,13 +46,12 @@ class BanmaskStyle(registry.SpaceSeparatedSetOfStrings):
|
|||||||
assert self.validStrings, 'There must be some valid strings. ' \
|
assert self.validStrings, 'There must be some valid strings. ' \
|
||||||
'This is a bug.'
|
'This is a bug.'
|
||||||
registry.SpaceSeparatedSetOfStrings.__init__(self, *args, **kwargs)
|
registry.SpaceSeparatedSetOfStrings.__init__(self, *args, **kwargs)
|
||||||
self.__doc__ = 'Valid values include %s.' % \
|
self.__doc__ = format('Valid values include %L.',
|
||||||
utils.str.commaAndify(map(repr, self.validStrings))
|
map(repr, self.validStrings))
|
||||||
|
|
||||||
def help(self):
|
def help(self):
|
||||||
strings = [s for s in self.validStrings if s]
|
strings = [s for s in self.validStrings if s]
|
||||||
return '%s Valid strings: %s.' % \
|
return format('%s Valid strings: %L.', self._help, strings)
|
||||||
(self._help, utils.str.commaAndify(strings))
|
|
||||||
|
|
||||||
def normalize(self, s):
|
def normalize(self, s):
|
||||||
lowered = s.lower()
|
lowered = s.lower()
|
||||||
|
@ -284,13 +284,12 @@ class Channel(callbacks.Privmsg):
|
|||||||
# Check that they're not trying to make us kickban ourself.
|
# Check that they're not trying to make us kickban ourself.
|
||||||
self.log.debug('In kban')
|
self.log.debug('In kban')
|
||||||
if not irc.isNick(bannedNick):
|
if not irc.isNick(bannedNick):
|
||||||
self.log.warning('%s tried to kban a non nick: %s',
|
self.log.warning(format('%q tried to kban a non nick: %q',
|
||||||
utils.str.quoted(msg.prefix),
|
msg.prefix, bannedNick))
|
||||||
utils.str.quoted(bannedNick))
|
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
elif bannedNick == irc.nick:
|
elif bannedNick == irc.nick:
|
||||||
self.log.warning('%s tried to make me kban myself.',
|
self.log.warning(format('%q tried to make me kban myself.',
|
||||||
utils.str.quoted(msg.prefix))
|
msg.prefix))
|
||||||
irc.error('I cowardly refuse to kickban myself.')
|
irc.error('I cowardly refuse to kickban myself.')
|
||||||
return
|
return
|
||||||
if not reason:
|
if not reason:
|
||||||
@ -327,8 +326,8 @@ class Channel(callbacks.Privmsg):
|
|||||||
# Check (again) that they're not trying to make us kickban ourself.
|
# Check (again) that they're not trying to make us kickban ourself.
|
||||||
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
|
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
|
||||||
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
|
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
|
||||||
self.log.warning('%s tried to make me kban myself.',
|
self.log.warning(format('%q tried to make me kban myself.',
|
||||||
utils.str.quoted(msg.prefix))
|
msg.prefix))
|
||||||
irc.error('I cowardly refuse to ban myself.')
|
irc.error('I cowardly refuse to ban myself.')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -351,16 +350,16 @@ class Channel(callbacks.Privmsg):
|
|||||||
doBan()
|
doBan()
|
||||||
elif ircdb.checkCapability(msg.prefix, capability):
|
elif ircdb.checkCapability(msg.prefix, capability):
|
||||||
if ircdb.checkCapability(bannedHostmask, capability):
|
if ircdb.checkCapability(bannedHostmask, capability):
|
||||||
self.log.warning('%s tried to ban %s, but both have %s',
|
self.log.warning(
|
||||||
msg.prefix, utils.str.quoted(bannedHostmask),
|
format('%s tried to ban %q, but both have %s',
|
||||||
capability)
|
msg.prefix, bannedHostmask, capability))
|
||||||
irc.error('%s has %s too, you can\'t ban him/her/it.' %
|
irc.error('%s has %s too, you can\'t ban him/her/it.' %
|
||||||
(bannedNick, capability))
|
(bannedNick, capability))
|
||||||
else:
|
else:
|
||||||
doBan()
|
doBan()
|
||||||
else:
|
else:
|
||||||
self.log.warning('%s attempted kban without %s',
|
self.log.warning(format('%q attempted kban without %s',
|
||||||
utils.str.quoted(msg.prefix), capability)
|
msg.prefix, capability))
|
||||||
irc.errorNoCapability(capability)
|
irc.errorNoCapability(capability)
|
||||||
exact,nick,user,host
|
exact,nick,user,host
|
||||||
kban = wrap(kban,
|
kban = wrap(kban,
|
||||||
@ -513,7 +512,7 @@ class Channel(callbacks.Privmsg):
|
|||||||
# XXX Add the expirations.
|
# XXX Add the expirations.
|
||||||
c = ircdb.channels.getChannel(channel)
|
c = ircdb.channels.getChannel(channel)
|
||||||
if c.bans:
|
if c.bans:
|
||||||
irc.reply(utils.str.commaAndify(map(utils.str.dqrepr, c.bans)))
|
irc.reply(format('%L', map(utils.str.dqrepr, c.bans)))
|
||||||
else:
|
else:
|
||||||
irc.reply('There are currently no permanent bans on %s' % channel)
|
irc.reply('There are currently no permanent bans on %s' % channel)
|
||||||
permbans = wrap(permbans, [('checkChannelCapability', 'op')])
|
permbans = wrap(permbans, [('checkChannelCapability', 'op')])
|
||||||
@ -558,8 +557,8 @@ class Channel(callbacks.Privmsg):
|
|||||||
# XXX Add the expirations.
|
# XXX Add the expirations.
|
||||||
c = ircdb.channels.getChannel(channel)
|
c = ircdb.channels.getChannel(channel)
|
||||||
if len(c.ignores) == 0:
|
if len(c.ignores) == 0:
|
||||||
s = 'I\'m not currently ignoring any hostmasks in %s' % \
|
s = format('I\'m not currently ignoring any hostmasks in %q',
|
||||||
utils.str.quoted(channel)
|
channel)
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
else:
|
else:
|
||||||
L = sorted(c.ignores)
|
L = sorted(c.ignores)
|
||||||
@ -599,9 +598,10 @@ class Channel(callbacks.Privmsg):
|
|||||||
fail.append(c)
|
fail.append(c)
|
||||||
ircdb.users.setUser(user)
|
ircdb.users.setUser(user)
|
||||||
if fail:
|
if fail:
|
||||||
irc.error('That user didn\'t have the %s %s.' %
|
s = 'capability'
|
||||||
(utils.str.commaAndify(fail),
|
if len(fail) > 1:
|
||||||
utils.str.pluralize('capability', len(fail))),
|
s = utils.str.pluralize(s)
|
||||||
|
irc.error(format('That user didn\'t have the %L %s.', fail, s),
|
||||||
Raise=True)
|
Raise=True)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
removecapability = wrap(removecapability,
|
removecapability = wrap(removecapability,
|
||||||
@ -660,9 +660,10 @@ class Channel(callbacks.Privmsg):
|
|||||||
fail.append(c)
|
fail.append(c)
|
||||||
ircdb.channels.setChannel(channel, chan)
|
ircdb.channels.setChannel(channel, chan)
|
||||||
if fail:
|
if fail:
|
||||||
irc.error('I do not know about the %s %s.' %
|
s = 'capability'
|
||||||
(utils.str.commaAndify(fail),
|
if len(fail) > 1:
|
||||||
utils.str.pluralize('capability', len(fail))),
|
s = utils.str.pluralize(s)
|
||||||
|
irc.error(format('I do not know about the %L %s.', fail, s),
|
||||||
Raise=True)
|
Raise=True)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
unsetcapability = wrap(unsetcapability,
|
unsetcapability = wrap(unsetcapability,
|
||||||
|
@ -130,7 +130,7 @@ class Config(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
L = self._list(group)
|
L = self._list(group)
|
||||||
if L:
|
if L:
|
||||||
irc.reply(utils.str.commaAndify(L))
|
irc.reply(format('%L', L))
|
||||||
else:
|
else:
|
||||||
irc.error('There don\'t seem to be any values in %s.' % group._name)
|
irc.error('There don\'t seem to be any values in %s.' % group._name)
|
||||||
list = wrap(list, ['configVar'])
|
list = wrap(list, ['configVar'])
|
||||||
@ -147,7 +147,7 @@ class Config(callbacks.Privmsg):
|
|||||||
if not ircutils.isChannel(possibleChannel):
|
if not ircutils.isChannel(possibleChannel):
|
||||||
L.append(name)
|
L.append(name)
|
||||||
if L:
|
if L:
|
||||||
irc.reply(utils.str.commaAndify(L))
|
irc.reply(format('%L', L))
|
||||||
else:
|
else:
|
||||||
irc.reply('There were no matching configuration variables.')
|
irc.reply('There were no matching configuration variables.')
|
||||||
search = wrap(search, ['lowered']) # XXX compose with withoutSpaces?
|
search = wrap(search, ['lowered']) # XXX compose with withoutSpaces?
|
||||||
|
@ -48,9 +48,9 @@ class Dict(callbacks.Privmsg):
|
|||||||
try:
|
try:
|
||||||
server = conf.supybot.plugins.Dict.server()
|
server = conf.supybot.plugins.Dict.server()
|
||||||
conn = dictclient.Connection(server)
|
conn = dictclient.Connection(server)
|
||||||
dbs = conn.getdbdescs().keys()
|
dbs = list(conn.getdbdescs().keys())
|
||||||
dbs.sort()
|
dbs.sort()
|
||||||
irc.reply(utils.str.commaAndify(dbs))
|
irc.reply(format('%L', dbs))
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
irc.error(utils.web.strError(e))
|
irc.error(utils.web.strError(e))
|
||||||
dictionaries = wrap(dictionaries)
|
dictionaries = wrap(dictionaries)
|
||||||
@ -98,11 +98,10 @@ class Dict(callbacks.Privmsg):
|
|||||||
dbs = set()
|
dbs = set()
|
||||||
if not definitions:
|
if not definitions:
|
||||||
if dictionary == '*':
|
if dictionary == '*':
|
||||||
irc.reply('No definition for %s could be found.' %
|
irc.reply(format('No definition for %q could be found.', word))
|
||||||
utils.str.quoted(word))
|
|
||||||
else:
|
else:
|
||||||
irc.reply('No definition for %s could be found in %s' %
|
irc.reply(format('No definition for %q could be found in %s',
|
||||||
(utils.str.quoted(word), ircutils.bold(dictionary)))
|
word, ircutils.bold(dictionary)))
|
||||||
return
|
return
|
||||||
L = []
|
L = []
|
||||||
for d in definitions:
|
for d in definitions:
|
||||||
@ -113,7 +112,7 @@ class Dict(callbacks.Privmsg):
|
|||||||
L.append('%s: %s' % (db, s))
|
L.append('%s: %s' % (db, s))
|
||||||
utils.gen.sortBy(len, L)
|
utils.gen.sortBy(len, L)
|
||||||
if dictionary == '*' and len(dbs) > 1:
|
if dictionary == '*' and len(dbs) > 1:
|
||||||
s = '%s responded: %s' % (utils.str.commaAndify(dbs), '; '.join(L))
|
s = format('%L responded: %s', list(dbs), '; '.join(L))
|
||||||
else:
|
else:
|
||||||
s = '; '.join(L)
|
s = '; '.join(L)
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
|
@ -184,8 +184,7 @@ class Math(callbacks.Privmsg):
|
|||||||
return str(x)
|
return str(x)
|
||||||
text = self._mathRe.sub(handleMatch, text)
|
text = self._mathRe.sub(handleMatch, text)
|
||||||
try:
|
try:
|
||||||
self.log.info('evaluating %s from %s' %
|
self.log.info(format('evaluating %q from %s', text, msg.prefix))
|
||||||
(utils.str.quoted(text), msg.prefix))
|
|
||||||
x = complex(eval(text, self._mathEnv, self._mathEnv))
|
x = complex(eval(text, self._mathEnv, self._mathEnv))
|
||||||
irc.reply(self._complexToString(x))
|
irc.reply(self._complexToString(x))
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
@ -219,8 +218,7 @@ class Math(callbacks.Privmsg):
|
|||||||
return
|
return
|
||||||
text = text.replace('lambda', '')
|
text = text.replace('lambda', '')
|
||||||
try:
|
try:
|
||||||
self.log.info('evaluating %s from %s' %
|
self.log.info(format('evaluating %q from %s', text, msg.prefix))
|
||||||
(utils.str.quoted(text), msg.prefix))
|
|
||||||
irc.reply(str(eval(text, self._mathEnv, self._mathEnv)))
|
irc.reply(str(eval(text, self._mathEnv, self._mathEnv)))
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
maxFloat = math.ldexp(0.9999999999999999, 1024)
|
maxFloat = math.ldexp(0.9999999999999999, 1024)
|
||||||
@ -276,8 +274,7 @@ class Math(callbacks.Privmsg):
|
|||||||
try:
|
try:
|
||||||
stack.append(eval(s, self._mathEnv, self._mathEnv))
|
stack.append(eval(s, self._mathEnv, self._mathEnv))
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
irc.error('%s is not a defined function.' %
|
irc.error(format('%q is not a defined function.', arg))
|
||||||
utils.str.quoted(arg))
|
|
||||||
return
|
return
|
||||||
if len(stack) == 1:
|
if len(stack) == 1:
|
||||||
irc.reply(str(self._complexToString(complex(stack[0]))))
|
irc.reply(str(self._complexToString(complex(stack[0]))))
|
||||||
|
@ -118,7 +118,7 @@ class Misc(callbacks.Privmsg):
|
|||||||
(not private and isPublic(cb))]
|
(not private and isPublic(cb))]
|
||||||
names.sort()
|
names.sort()
|
||||||
if names:
|
if names:
|
||||||
irc.reply(utils.str.commaAndify(names))
|
irc.reply(format('%L', names))
|
||||||
else:
|
else:
|
||||||
if private:
|
if private:
|
||||||
irc.reply('There are no private plugins.')
|
irc.reply('There are no private plugins.')
|
||||||
@ -143,7 +143,7 @@ class Misc(callbacks.Privmsg):
|
|||||||
commands.append(s)
|
commands.append(s)
|
||||||
if commands:
|
if commands:
|
||||||
commands.sort()
|
commands.sort()
|
||||||
irc.reply(utils.str.commaAndify(commands))
|
irc.reply(format('%L', commands))
|
||||||
else:
|
else:
|
||||||
irc.error('That plugin exists, but it has no '
|
irc.error('That plugin exists, but it has no '
|
||||||
'commands with help.')
|
'commands with help.')
|
||||||
@ -172,7 +172,7 @@ class Misc(callbacks.Privmsg):
|
|||||||
L.append('%s %s' % (name, key))
|
L.append('%s %s' % (name, key))
|
||||||
if L:
|
if L:
|
||||||
L.sort()
|
L.sort()
|
||||||
irc.reply(utils.str.commaAndify(L))
|
irc.reply(format('%L', L))
|
||||||
else:
|
else:
|
||||||
irc.reply('No appropriate commands were found.')
|
irc.reply('No appropriate commands were found.')
|
||||||
apropos = wrap(apropos, ['lowered'])
|
apropos = wrap(apropos, ['lowered'])
|
||||||
@ -204,9 +204,9 @@ class Misc(callbacks.Privmsg):
|
|||||||
irc.error('There is no command %s.' % command)
|
irc.error('There is no command %s.' % command)
|
||||||
elif len(cbs) > 1:
|
elif len(cbs) > 1:
|
||||||
names = sorted([cb.name() for cb in cbs])
|
names = sorted([cb.name() for cb in cbs])
|
||||||
irc.error('That command exists in the %s plugins. '
|
irc.error(format('That command exists in the %L plugins. '
|
||||||
'Please specify exactly which plugin command '
|
'Please specify exactly which plugin command '
|
||||||
'you want help with.'% utils.str.commaAndify(names))
|
'you want help with.', names))
|
||||||
else:
|
else:
|
||||||
getHelp(cbs[0])
|
getHelp(cbs[0])
|
||||||
else:
|
else:
|
||||||
@ -260,13 +260,14 @@ class Misc(callbacks.Privmsg):
|
|||||||
if cbs:
|
if cbs:
|
||||||
names = [cb.name() for cb in cbs]
|
names = [cb.name() for cb in cbs]
|
||||||
names.sort()
|
names.sort()
|
||||||
plugin = utils.str.commaAndify(names)
|
|
||||||
if irc.nested:
|
if irc.nested:
|
||||||
irc.reply(utils.str.commaAndify(names))
|
irc.reply(format('%L', names))
|
||||||
else:
|
else:
|
||||||
irc.reply('The %s command is available in the %s %s.' %
|
s = 'plugin'
|
||||||
(utils.str.quoted(command), plugin,
|
if len(names) > 1:
|
||||||
utils.str.pluralize('plugin', len(names))))
|
s = utils.str.pluralize(s)
|
||||||
|
irc.reply(format('The %q command is available in the %L %s.',
|
||||||
|
command, names, s))
|
||||||
else:
|
else:
|
||||||
irc.error('There is no such command %s.' % command)
|
irc.error('There is no such command %s.' % command)
|
||||||
plugin = wrap(plugin, ['commandName'])
|
plugin = wrap(plugin, ['commandName'])
|
||||||
@ -311,8 +312,7 @@ class Misc(callbacks.Privmsg):
|
|||||||
L = self._mores[userHostmask]
|
L = self._mores[userHostmask]
|
||||||
chunk = L.pop()
|
chunk = L.pop()
|
||||||
if L:
|
if L:
|
||||||
chunk += ' \x02(%s)\x0F' % \
|
chunk += format(' \x02(%n)\x0F', (len(L), 'message', 'more'))
|
||||||
utils.str.nItems('message', len(L), 'more')
|
|
||||||
irc.reply(chunk, True)
|
irc.reply(chunk, True)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.error('You haven\'t asked me a command; perhaps you want '
|
irc.error('You haven\'t asked me a command; perhaps you want '
|
||||||
@ -404,7 +404,7 @@ class Misc(callbacks.Privmsg):
|
|||||||
irc.error('I couldn\'t find a message matching that criteria in '
|
irc.error('I couldn\'t find a message matching that criteria in '
|
||||||
'my history of %s messages.' % len(irc.state.history))
|
'my history of %s messages.' % len(irc.state.history))
|
||||||
else:
|
else:
|
||||||
irc.reply(utils.str.commaAndify(resp))
|
irc.reply(format('%L', resp))
|
||||||
last = wrap(last, [getopts({'nolimit': '',
|
last = wrap(last, [getopts({'nolimit': '',
|
||||||
'on': 'something',
|
'on': 'something',
|
||||||
'with': 'something',
|
'with': 'something',
|
||||||
@ -491,7 +491,7 @@ class Misc(callbacks.Privmsg):
|
|||||||
shortname[, shortname and shortname].
|
shortname[, shortname and shortname].
|
||||||
"""
|
"""
|
||||||
L = [getShortName(n) for n in longList]
|
L = [getShortName(n) for n in longList]
|
||||||
return utils.str.commaAndify(L)
|
return format('%L', L)
|
||||||
def sortAuthors():
|
def sortAuthors():
|
||||||
"""
|
"""
|
||||||
Sort the list of 'long names' based on the number of contributions
|
Sort the list of 'long names' based on the number of contributions
|
||||||
@ -525,9 +525,9 @@ class Misc(callbacks.Privmsg):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if contribs:
|
if contribs:
|
||||||
contrib = '%s %s contributed to it.' % \
|
contrib = format('%s %h contributed to it.',
|
||||||
(buildContributorsString(contribs),
|
buildContributorsString(contribs),
|
||||||
utils.str.has(len(contribs)))
|
len(contribs))
|
||||||
hasContribs = True
|
hasContribs = True
|
||||||
elif hasAuthor:
|
elif hasAuthor:
|
||||||
contrib = 'has no additional contributors listed'
|
contrib = 'has no additional contributors listed'
|
||||||
@ -557,19 +557,22 @@ class Misc(callbacks.Privmsg):
|
|||||||
contributions)
|
contributions)
|
||||||
results = []
|
results = []
|
||||||
if commands:
|
if commands:
|
||||||
results.append(
|
s = 'command'
|
||||||
'the %s %s' %(utils.str.commaAndify(commands),
|
if len(commands) > 1:
|
||||||
utils.str.pluralize('command',len(commands))))
|
s = utils.str.pluralize(s)
|
||||||
|
results.append(format('the %L %s', commands, s))
|
||||||
if nonCommands:
|
if nonCommands:
|
||||||
results.append('the %s' % utils.str.commaAndify(nonCommands))
|
results.append(format('the %L', nonCommands))
|
||||||
if results and isAuthor:
|
if results and isAuthor:
|
||||||
return '%s wrote the %s plugin and also contributed %s' % \
|
return format('%s wrote the %s plugin and also contributed %L',
|
||||||
(fullName, cb.name(), utils.str.commaAndify(results))
|
(fullName, cb.name(), results))
|
||||||
elif results and not isAuthor:
|
elif results and not isAuthor:
|
||||||
return '%s contributed %s to the %s plugin' % \
|
return format('%s contributed %L to the %s plugin',
|
||||||
(fullName, utils.str.commaAndify(results), cb.name())
|
fullName, results, cb.name())
|
||||||
elif isAuthor and not results:
|
elif isAuthor and not results:
|
||||||
return '%s wrote the %s plugin' % (fullName, cb.name())
|
return '%s wrote the %s plugin' % (fullName, cb.name())
|
||||||
|
# XXX Does this ever actually get reached? If so, the string
|
||||||
|
# formatting needs to be fixed.
|
||||||
else:
|
else:
|
||||||
return '%s has no listed contributions for the %s plugin %s' %\
|
return '%s has no listed contributions for the %s plugin %s' %\
|
||||||
(fullName, cb.name())
|
(fullName, cb.name())
|
||||||
|
@ -168,19 +168,19 @@ class Network(callbacks.Privmsg):
|
|||||||
normal.append(channel)
|
normal.append(channel)
|
||||||
L = []
|
L = []
|
||||||
if ops:
|
if ops:
|
||||||
L.append('is an op on %s' % utils.str.commaAndify(ops))
|
L.append(format('is an op on %L', ops))
|
||||||
if halfops:
|
if halfops:
|
||||||
L.append('is a halfop on %s' % utils.str.commaAndify(halfops))
|
L.append(format('is a halfop on %L', halfops))
|
||||||
if voices:
|
if voices:
|
||||||
L.append('is voiced on %s' % utils.str.commaAndify(voices))
|
L.append(format('is voiced on %L', voices))
|
||||||
if normal:
|
if normal:
|
||||||
if L:
|
if L:
|
||||||
L.append('is also on %s' % utils.str.commaAndify(normal))
|
L.append(format('is also on %L', normal))
|
||||||
else:
|
else:
|
||||||
L.append('is on %s' % utils.str.commaAndify(normal))
|
L.append(format('is on %L', normal))
|
||||||
else:
|
else:
|
||||||
L = ['isn\'t on any non-secret channels']
|
L = ['isn\'t on any non-secret channels']
|
||||||
channels = utils.str.commaAndify(L)
|
channels = format('%L', L)
|
||||||
if '317' in d:
|
if '317' in d:
|
||||||
idle = utils.gen.timeElapsed(d['317'].args[2])
|
idle = utils.gen.timeElapsed(d['317'].args[2])
|
||||||
signon = time.strftime(conf.supybot.reply.format.time(),
|
signon = time.strftime(conf.supybot.reply.format.time(),
|
||||||
@ -241,8 +241,8 @@ class Network(callbacks.Privmsg):
|
|||||||
Returns the networks to which the bot is currently connected.
|
Returns the networks to which the bot is currently connected.
|
||||||
"""
|
"""
|
||||||
L = ['%s: %s' % (ircd.network, ircd.server) for ircd in world.ircs]
|
L = ['%s: %s' % (ircd.network, ircd.server) for ircd in world.ircs]
|
||||||
utils.sortBy(str.lower, L)
|
utils.gen.sortBy(str.lower, L)
|
||||||
irc.reply(utils.str.commaAndify(L))
|
irc.reply(format('%L', L))
|
||||||
networks = wrap(networks)
|
networks = wrap(networks)
|
||||||
|
|
||||||
def doPong(self, irc, msg):
|
def doPong(self, irc, msg):
|
||||||
|
@ -193,7 +193,7 @@ class Status(callbacks.Privmsg):
|
|||||||
commands.add(attr)
|
commands.add(attr)
|
||||||
commands = list(commands)
|
commands = list(commands)
|
||||||
commands.sort()
|
commands.sort()
|
||||||
irc.reply(utils.str.commaAndify(commands))
|
irc.reply(format('%L', commands))
|
||||||
commands = wrap(commands)
|
commands = wrap(commands)
|
||||||
|
|
||||||
def uptime(self, irc, msg, args):
|
def uptime(self, irc, msg, args):
|
||||||
|
@ -70,8 +70,8 @@ class User(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
users.append(u.name)
|
users.append(u.name)
|
||||||
if users:
|
if users:
|
||||||
utils.sortBy(str.lower, users)
|
utils.gen.sortBy(str.lower, users)
|
||||||
irc.reply(utils.str.commaAndify(users))
|
irc.reply(format('%L', users))
|
||||||
else:
|
else:
|
||||||
if predicates:
|
if predicates:
|
||||||
irc.reply('There are no matching registered users.')
|
irc.reply('There are no matching registered users.')
|
||||||
@ -154,7 +154,7 @@ class User(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
id = ircdb.users.getUserId(newname)
|
id = ircdb.users.getUserId(newname)
|
||||||
irc.error('%s is already registered.' % utils.str.quoted(newname))
|
irc.error(format('%q is already registered.', newname))
|
||||||
return
|
return
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
@ -291,7 +291,7 @@ class User(callbacks.Privmsg):
|
|||||||
def getHostmasks(user):
|
def getHostmasks(user):
|
||||||
hostmasks = map(repr, user.hostmasks)
|
hostmasks = map(repr, user.hostmasks)
|
||||||
hostmasks.sort()
|
hostmasks.sort()
|
||||||
return utils.str.commaAndify(hostmasks)
|
return format('%L', hostmasks)
|
||||||
try:
|
try:
|
||||||
user = ircdb.users.getUser(msg.prefix)
|
user = ircdb.users.getUser(msg.prefix)
|
||||||
if name:
|
if name:
|
||||||
|
@ -384,9 +384,9 @@ class ChannelIdDatabasePlugin(callbacks.Privmsg):
|
|||||||
|
|
||||||
def getCommandHelp(self, name):
|
def getCommandHelp(self, name):
|
||||||
help = self.__parent.getCommandHelp(name)
|
help = self.__parent.getCommandHelp(name)
|
||||||
help = help.replace('$Types', utils.str.pluralize(self.name()))
|
help = help.replace('$Types', format('%p', self.name()))
|
||||||
help = help.replace('$Type', self.name())
|
help = help.replace('$Type', self.name())
|
||||||
help = help.replace('$types', utils.str.pluralize(self.name().lower()))
|
help = help.replace('$types', format('%p', self.name().lower()))
|
||||||
help = help.replace('$type', self.name().lower())
|
help = help.replace('$type', self.name().lower())
|
||||||
return help
|
return help
|
||||||
|
|
||||||
@ -437,8 +437,8 @@ class ChannelIdDatabasePlugin(callbacks.Privmsg):
|
|||||||
remove = wrap(remove, ['user', 'channeldb', 'id'])
|
remove = wrap(remove, ['user', 'channeldb', 'id'])
|
||||||
|
|
||||||
def searchSerializeRecord(self, record):
|
def searchSerializeRecord(self, record):
|
||||||
text = utils.str.quoted(utils.str.ellipsisify(record.text, 50))
|
text = utils.str.ellipsisify(record.text, 50)
|
||||||
return '#%s: %s' % (record.id, text)
|
return format('#%s: %q' % (record.id, text))
|
||||||
|
|
||||||
def search(self, irc, msg, args, channel, optlist, glob):
|
def search(self, irc, msg, args, channel, optlist, glob):
|
||||||
"""[<channel>] [--{regexp,by} <value>] [<glob>]
|
"""[<channel>] [--{regexp,by} <value>] [<glob>]
|
||||||
|
@ -80,8 +80,7 @@ class Debug(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
self._evalEnv['_'] = x
|
self._evalEnv['_'] = x
|
||||||
irc.reply(repr(x))
|
irc.reply(repr(x))
|
||||||
except SyntaxError, e:
|
except SyntaxError, e:
|
||||||
irc.reply('%s: %s' % (utils.exnToString(e),
|
irc.reply(format('%s: %q', utils.gen.exnToString(e), s))
|
||||||
utils.quoted(s)))
|
|
||||||
eval = wrap(eval, ['text'])
|
eval = wrap(eval, ['text'])
|
||||||
|
|
||||||
def _exec(self, irc, msg, args, s):
|
def _exec(self, irc, msg, args, s):
|
||||||
@ -163,7 +162,7 @@ class Debug(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
while times:
|
while times:
|
||||||
L.append(gc.collect())
|
L.append(gc.collect())
|
||||||
times -= 1
|
times -= 1
|
||||||
irc.reply(utils.commaAndify(map(str, L)))
|
irc.reply(format('%L', map(str, L)))
|
||||||
collect = wrap(collect, [additional('positiveInt', 1)])
|
collect = wrap(collect, [additional('positiveInt', 1)])
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ def main():
|
|||||||
else.""")
|
else.""")
|
||||||
pluginDirs = conf.supybot.directories.plugins()
|
pluginDirs = conf.supybot.directories.plugins()
|
||||||
output("""Currently, the bot knows about the following directories:""")
|
output("""Currently, the bot knows about the following directories:""")
|
||||||
output(utils.commaAndify(pluginDirs))
|
output(format('%L', pluginDirs))
|
||||||
while yn('Would you like to add another plugin directory?',
|
while yn('Would you like to add another plugin directory?',
|
||||||
default=False):
|
default=False):
|
||||||
(pluginDir, _) = getDirectoryName('plugins', basedir=basedir)
|
(pluginDir, _) = getDirectoryName('plugins', basedir=basedir)
|
||||||
@ -422,8 +422,7 @@ def main():
|
|||||||
addedBulk = False
|
addedBulk = False
|
||||||
if advanced and yn('Would you like to add plugins en masse first?'):
|
if advanced and yn('Would you like to add plugins en masse first?'):
|
||||||
addedBulk = True
|
addedBulk = True
|
||||||
output("""The available plugins are: %s.""" % \
|
output(format("""The available plugins are: %L.""", plugins))
|
||||||
utils.commaAndify(plugins))
|
|
||||||
output("""What plugins would you like to add? If you've changed your
|
output("""What plugins would you like to add? If you've changed your
|
||||||
mind and would rather not add plugins in bulk like this, just press
|
mind and would rather not add plugins in bulk like this, just press
|
||||||
enter and we'll move on to the individual plugin configuration.""")
|
enter and we'll move on to the individual plugin configuration.""")
|
||||||
|
@ -489,8 +489,8 @@ class RichReplyMethods(object):
|
|||||||
if 'Raise' not in kwargs:
|
if 'Raise' not in kwargs:
|
||||||
kwargs['Raise'] = True
|
kwargs['Raise'] = True
|
||||||
if isinstance(capability, basestring): # checkCommandCapability!
|
if isinstance(capability, basestring): # checkCommandCapability!
|
||||||
log.warning('Denying %s for lacking %s capability.',
|
log.warning(format('Denying %s for lacking %q capability.',
|
||||||
self.msg.prefix, utils.str.quoted(capability))
|
self.msg.prefix, capability))
|
||||||
if not self._getConfig(conf.supybot.reply.error.noCapability):
|
if not self._getConfig(conf.supybot.reply.error.noCapability):
|
||||||
v = self._getConfig(conf.supybot.replies.noCapability)
|
v = self._getConfig(conf.supybot.replies.noCapability)
|
||||||
s = self.__makeReply(v % capability, s)
|
s = self.__makeReply(v % capability, s)
|
||||||
@ -866,7 +866,7 @@ class IrcObjectProxy(RichReplyMethods):
|
|||||||
response = msgs.pop()
|
response = msgs.pop()
|
||||||
if msgs:
|
if msgs:
|
||||||
n = ircutils.bold('(%s)')
|
n = ircutils.bold('(%s)')
|
||||||
n %= utils.str.nItems(len(msgs), 'message', 'more')
|
n %= format('%n', (len(msgs), 'message', 'more'))
|
||||||
response = '%s %s' % (response, n)
|
response = '%s %s' % (response, n)
|
||||||
prefix = msg.prefix
|
prefix = msg.prefix
|
||||||
if self.to and ircutils.isNick(self.to):
|
if self.to and ircutils.isNick(self.to):
|
||||||
@ -1118,8 +1118,7 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
def getCommand(self, name):
|
def getCommand(self, name):
|
||||||
"""Gets the given command from this plugin."""
|
"""Gets the given command from this plugin."""
|
||||||
name = canonicalName(name)
|
name = canonicalName(name)
|
||||||
assert self.isCommand(name), '%s is not a command.' % \
|
assert self.isCommand(name), format('%s is not a command.', name)
|
||||||
utils.str.quoted(name)
|
|
||||||
return getattr(self, name)
|
return getattr(self, name)
|
||||||
|
|
||||||
def callCommand(self, name, irc, msg, *L, **kwargs):
|
def callCommand(self, name, irc, msg, *L, **kwargs):
|
||||||
@ -1155,7 +1154,7 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
elif hasattr(command, '__doc__'):
|
elif hasattr(command, '__doc__'):
|
||||||
return getHelp(command)
|
return getHelp(command)
|
||||||
else:
|
else:
|
||||||
return 'The %s command has no help.' % utils.str.quoted(name)
|
return format('The %s command has no help.', name)
|
||||||
|
|
||||||
def registryValue(self, name, channel=None, value=True):
|
def registryValue(self, name, channel=None, value=True):
|
||||||
plugin = self.name()
|
plugin = self.name()
|
||||||
@ -1286,9 +1285,9 @@ class PrivmsgRegexp(Privmsg):
|
|||||||
r = re.compile(value.__doc__, self.flags)
|
r = re.compile(value.__doc__, self.flags)
|
||||||
self.res.append((r, name))
|
self.res.append((r, name))
|
||||||
except re.error, e:
|
except re.error, e:
|
||||||
self.log.warning('Invalid regexp: %s (%s)',
|
self.log.warning(format('Invalid regexp: %q (%s)',
|
||||||
utils.str.quoted(value.__doc__), e)
|
value.__doc__, e))
|
||||||
utils.sortBy(operator.itemgetter(1), self.res)
|
utils.gen.sortBy(operator.itemgetter(1), self.res)
|
||||||
|
|
||||||
def callCommand(self, name, irc, msg, *L, **kwargs):
|
def callCommand(self, name, irc, msg, *L, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
16
src/ircdb.py
16
src/ircdb.py
@ -221,11 +221,10 @@ class IrcUser(object):
|
|||||||
self.hostmasks = hostmasks
|
self.hostmasks = hostmasks
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s(id=%s, ignore=%s, password="", name=%s, hashed=%r, ' \
|
return format('%s(id=%s, ignore=%s, password="", name=%q, hashed=%r, '
|
||||||
'capabilities=%r, hostmasks=[], secure=%r)\n' % \
|
'capabilities=%r, hostmasks=[], secure=%r)\n',
|
||||||
(self.__class__.__name__, self.id, self.ignore,
|
self.__class__.__name__, self.id, self.ignore,
|
||||||
utils.str.quoted(self.name), self.hashed, self.capabilities,
|
self.name, self.hashed, self.capabilities, self.secure)
|
||||||
self.secure)
|
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.id)
|
return hash(self.id)
|
||||||
@ -652,8 +651,8 @@ class UsersDictionary(utils.IterableMap):
|
|||||||
log.error('Multiple matches found in user database. '
|
log.error('Multiple matches found in user database. '
|
||||||
'Removing the offending hostmasks.')
|
'Removing the offending hostmasks.')
|
||||||
for (id, hostmask) in ids.iteritems():
|
for (id, hostmask) in ids.iteritems():
|
||||||
log.error('Removing %s from user %s.',
|
log.error(format('Removing %q from user %s.', hostmask,
|
||||||
utils.str.quoted(hostmask), id)
|
id))
|
||||||
self.users[id].removeHostmask(hostmask)
|
self.users[id].removeHostmask(hostmask)
|
||||||
raise DuplicateHostmask, 'Ids %r matched.' % ids
|
raise DuplicateHostmask, 'Ids %r matched.' % ids
|
||||||
else: # Not a hostmask, must be a name.
|
else: # Not a hostmask, must be a name.
|
||||||
@ -852,8 +851,7 @@ class IgnoresDB(object):
|
|||||||
expiration = 0
|
expiration = 0
|
||||||
self.add(hostmask, expiration)
|
self.add(hostmask, expiration)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.error('Invalid line in ignores database: %s',
|
log.error(format('Invalid line in ignores database: %q', line))
|
||||||
utils.str.quoted(line))
|
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
@ -35,6 +35,7 @@ import operator
|
|||||||
|
|
||||||
import supybot.log as log
|
import supybot.log as log
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
|
from utils.str import rsplit
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.world as world
|
import supybot.world as world
|
||||||
import supybot.ircdb as ircdb
|
import supybot.ircdb as ircdb
|
||||||
@ -168,8 +169,8 @@ class IrcMsgQueue(object):
|
|||||||
if msg in self.msgs and \
|
if msg in self.msgs and \
|
||||||
not conf.supybot.protocols.irc.queueDuplicateMessages():
|
not conf.supybot.protocols.irc.queueDuplicateMessages():
|
||||||
s = str(msg).strip()
|
s = str(msg).strip()
|
||||||
log.info('Not adding message %s to queue, already added.',
|
log.info(
|
||||||
utils.str.quoted(s))
|
format('Not adding message %q to queue, already added.', s))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.msgs.add(msg)
|
self.msgs.add(msg)
|
||||||
|
@ -188,9 +188,8 @@ class IrcMsg(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self._repr is not None:
|
if self._repr is not None:
|
||||||
return self._repr
|
return self._repr
|
||||||
self._repr = 'IrcMsg(prefix=%s, command=%s, args=%r)' % \
|
self._repr = format('IrcMsg(prefix=%q, command=%q, args=%r)',
|
||||||
(utils.str.quoted(self.prefix),
|
self.prefix, self.command, self.args)
|
||||||
utils.str.quoted(self.command), self.args)
|
|
||||||
return self._repr
|
return self._repr
|
||||||
|
|
||||||
def __reduce__(self):
|
def __reduce__(self):
|
||||||
|
@ -48,8 +48,7 @@ def loadPluginModule(name, ignoreDeprecation=False):
|
|||||||
try:
|
try:
|
||||||
files.extend(os.listdir(dir))
|
files.extend(os.listdir(dir))
|
||||||
except EnvironmentError: # OSError, IOError superclass.
|
except EnvironmentError: # OSError, IOError superclass.
|
||||||
log.warning('Invalid plugin directory: %s; removing.',
|
log.warning(format('Invalid plugin directory: %s; removing.', dir))
|
||||||
utils.str.quoted(dir))
|
|
||||||
conf.supybot.directories.plugins().remove(dir)
|
conf.supybot.directories.plugins().remove(dir)
|
||||||
loweredFiles = map(str.lower, files)
|
loweredFiles = map(str.lower, files)
|
||||||
try:
|
try:
|
||||||
@ -71,8 +70,8 @@ def loadPluginModule(name, ignoreDeprecation=False):
|
|||||||
if ignoreDeprecation:
|
if ignoreDeprecation:
|
||||||
log.warning('Deprecated plugin loaded: %s', name)
|
log.warning('Deprecated plugin loaded: %s', name)
|
||||||
else:
|
else:
|
||||||
raise Deprecated, 'Attempted to load deprecated plugin %s' % \
|
raise Deprecated, format('Attempted to load deprecated plugin %s',
|
||||||
utils.str.quoted(name)
|
name)
|
||||||
if module.__name__ in sys.modules:
|
if module.__name__ in sys.modules:
|
||||||
sys.modules[module.__name__] = module
|
sys.modules[module.__name__] = module
|
||||||
linecache.checkcache()
|
linecache.checkcache()
|
||||||
|
@ -454,13 +454,12 @@ class OnlySomeStrings(String):
|
|||||||
'This is a bug.'
|
'This is a bug.'
|
||||||
self.__parent = super(OnlySomeStrings, self)
|
self.__parent = super(OnlySomeStrings, self)
|
||||||
self.__parent.__init__(*args, **kwargs)
|
self.__parent.__init__(*args, **kwargs)
|
||||||
self.__doc__ = 'Valid values include %s.' % \
|
self.__doc__ = format('Valid values include %L.',
|
||||||
utils.str.commaAndify(map(repr, self.validStrings))
|
map(repr, self.validStrings))
|
||||||
|
|
||||||
def help(self):
|
def help(self):
|
||||||
strings = [s for s in self.validStrings if s]
|
strings = [s for s in self.validStrings if s]
|
||||||
return '%s Valid strings: %s.' % \
|
return format('%s Valid strings: %L.', self._help, strings)
|
||||||
(self._help, utils.str.commaAndify(strings))
|
|
||||||
|
|
||||||
def normalize(self, s):
|
def normalize(self, s):
|
||||||
lowered = s.lower()
|
lowered = s.lower()
|
||||||
|
@ -96,7 +96,7 @@ class SupyTestCase(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
log.critical('Beginning test case %s', self.id())
|
log.critical('Beginning test case %s', self.id())
|
||||||
threads = [t.getName() for t in threading.enumerate()]
|
threads = [t.getName() for t in threading.enumerate()]
|
||||||
log.critical('Threads: %s' % utils.str.commaAndify(threads))
|
log.critical(format('Threads: %L', threads))
|
||||||
unittest.TestCase.setUp(self)
|
unittest.TestCase.setUp(self)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -40,8 +40,8 @@ import UserDict
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from iter import imap
|
from iter import imap
|
||||||
|
from str import format
|
||||||
from file import mktemp
|
from file import mktemp
|
||||||
from str import quoted, nItems, commaAndify
|
|
||||||
|
|
||||||
def abbrev(strings, d=None):
|
def abbrev(strings, d=None):
|
||||||
"""Returns a dictionary mapping unambiguous abbreviations to full forms."""
|
"""Returns a dictionary mapping unambiguous abbreviations to full forms."""
|
||||||
@ -76,40 +76,40 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
|
|||||||
be used.
|
be used.
|
||||||
"""
|
"""
|
||||||
ret = []
|
ret = []
|
||||||
def format(s, i):
|
def Format(s, i):
|
||||||
if i or leadingZeroes or ret:
|
if i or leadingZeroes or ret:
|
||||||
if short:
|
if short:
|
||||||
ret.append('%s%s' % (i, s[0]))
|
ret.append('%s%s' % (i, s[0]))
|
||||||
else:
|
else:
|
||||||
ret.append(nItems(i, s))
|
ret.append(format('%n', (i, s)))
|
||||||
elapsed = int(elapsed)
|
elapsed = int(elapsed)
|
||||||
assert years or weeks or days or \
|
assert years or weeks or days or \
|
||||||
hours or minutes or seconds, 'One flag must be True'
|
hours or minutes or seconds, 'One flag must be True'
|
||||||
if years:
|
if years:
|
||||||
(yrs, elapsed) = (elapsed // 31536000, elapsed % 31536000)
|
(yrs, elapsed) = (elapsed // 31536000, elapsed % 31536000)
|
||||||
format('year', yrs)
|
Format('year', yrs)
|
||||||
if weeks:
|
if weeks:
|
||||||
(wks, elapsed) = (elapsed // 604800, elapsed % 604800)
|
(wks, elapsed) = (elapsed // 604800, elapsed % 604800)
|
||||||
format('week', wks)
|
Format('week', wks)
|
||||||
if days:
|
if days:
|
||||||
(ds, elapsed) = (elapsed // 86400, elapsed % 86400)
|
(ds, elapsed) = (elapsed // 86400, elapsed % 86400)
|
||||||
format('day', ds)
|
Format('day', ds)
|
||||||
if hours:
|
if hours:
|
||||||
(hrs, elapsed) = (elapsed // 3600, elapsed % 3600)
|
(hrs, elapsed) = (elapsed // 3600, elapsed % 3600)
|
||||||
format('hour', hrs)
|
Format('hour', hrs)
|
||||||
if minutes or seconds:
|
if minutes or seconds:
|
||||||
(mins, secs) = (elapsed // 60, elapsed % 60)
|
(mins, secs) = (elapsed // 60, elapsed % 60)
|
||||||
if leadingZeroes or mins:
|
if leadingZeroes or mins:
|
||||||
format('minute', mins)
|
Format('minute', mins)
|
||||||
if seconds:
|
if seconds:
|
||||||
leadingZeroes = True
|
leadingZeroes = True
|
||||||
format('second', secs)
|
Format('second', secs)
|
||||||
if not ret:
|
if not ret:
|
||||||
raise ValueError, 'Time difference not great enough to be noted.'
|
raise ValueError, 'Time difference not great enough to be noted.'
|
||||||
if short:
|
if short:
|
||||||
return ' '.join(ret)
|
return ' '.join(ret)
|
||||||
else:
|
else:
|
||||||
return commaAndify(ret)
|
return format('%L', ret)
|
||||||
|
|
||||||
def findBinaryInPath(s):
|
def findBinaryInPath(s):
|
||||||
"""Return full path of a binary if it's in PATH, otherwise return None."""
|
"""Return full path of a binary if it's in PATH, otherwise return None."""
|
||||||
@ -150,7 +150,7 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}):
|
|||||||
if node.__class__ is compiler.ast.Module:
|
if node.__class__ is compiler.ast.Module:
|
||||||
return node.doc
|
return node.doc
|
||||||
else:
|
else:
|
||||||
raise ValueError, 'Unsafe string: %s' % quoted(s)
|
raise ValueError, format('Unsafe string: %q', s)
|
||||||
node = nodes[0]
|
node = nodes[0]
|
||||||
if node.__class__ is not compiler.ast.Discard:
|
if node.__class__ is not compiler.ast.Discard:
|
||||||
raise ValueError, 'Invalid expression: %s' % quoted(s)
|
raise ValueError, 'Invalid expression: %s' % quoted(s)
|
||||||
|
@ -33,6 +33,7 @@ Simple utility functions related to strings.
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import new
|
import new
|
||||||
|
import sys
|
||||||
import string
|
import string
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user