本文整理汇总了Python中supybot.utils.sortBy函数的典型用法代码示例。如果您正苦于以下问题:Python sortBy函数的具体用法?Python sortBy怎么用?Python sortBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sortBy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: nicks
def nicks(self, irc, msg, args, channel, optlist):
"""[<channel>] [--count]
Returns the nicks in <channel>. <channel> is only necessary if the
message isn't sent in the channel itself. Returns only the number of
nicks if --count option is provided.
"""
# Make sure we don't elicit information about private channels to
# people or channels that shouldn't know
capability = ircdb.makeChannelCapability(channel, 'op')
hostmask = irc.state.nickToHostmask(msg.nick)
if 's' in irc.state.channels[channel].modes and \
msg.args[0] != channel and \
not ircdb.checkCapability(hostmask, capability) and \
(ircutils.isChannel(msg.args[0]) or \
msg.nick not in irc.state.channels[channel].users):
irc.error(_('You don\'t have access to that information.'),
Raise=True)
L = list(irc.state.channels[channel].users)
keys = [option for (option, arg) in optlist]
if 'count' not in keys:
utils.sortBy(str.lower, L)
private = self.registryValue("nicksInPrivate", channel)
irc.reply(utils.str.commaAndify(L), private=private)
else:
irc.reply(str(len(L)))
示例2: _oldnotes
def _oldnotes(self, irc, msg, sender):
try:
user = ircdb.users.getUser(msg.prefix)
except KeyError:
irc.errorNotRegistered()
return
def p(note):
return note.to == user.id and note.read
if sender:
originalP = p
def p(note):
return originalP(note) and note.frm == sender.id
notes = list(self.db.select(p))
if not notes:
irc.reply("I couldn't find any matching read notes " "for your user.")
else:
utils.sortBy(operator.attrgetter("id"), notes)
notes.reverse()
ids = [self._formatNoteId(msg, note) for note in notes]
ids = self._condense(ids)
irc.reply(format("%L.", ids))
示例3: list
def list(self, irc, msg, args, optlist, glob):
"""[--capability=<capability>] [<glob>]
Returns the valid registered usernames matching <glob>. If <glob> is
not given, returns all registered usernames.
"""
predicates = []
for (option, arg) in optlist:
if option == 'capability':
def p(u, cap=arg):
try:
return u._checkCapability(cap)
except KeyError:
return False
predicates.append(p)
if glob:
r = re.compile(fnmatch.translate(glob), re.I)
def p(u):
return r.match(u.name) is not None
predicates.append(p)
users = []
for u in ircdb.users.itervalues():
for predicate in predicates:
if not predicate(u):
break
else:
users.append(u.name)
if users:
utils.sortBy(str.lower, users)
irc.reply(format('%L', users))
else:
if predicates:
irc.reply('There are no matching registered users.')
else:
irc.reply('There are no registered users.')
示例4: nicks
def nicks(self, irc, msg, args, channel, optlist):
"""[<channel>] [--count]
Returns the nicks in <channel>. <channel> is only necessary if the
message isn't sent in the channel itself. Returns only the number of
nicks if --count option is provided.
"""
# Make sure we don't elicit information about private channels to
# people or channels that shouldn't know
if 's' in irc.state.channels[channel].modes and \
msg.args[0] != channel and \
(ircutils.isChannel(msg.args[0]) or \
msg.nick not in irc.state.channels[channel].users):
irc.error(_('You don\'t have access to that information.'),
Raise=True)
L = list(irc.state.channels[channel].users)
keys = [option for (option, arg) in optlist]
if 'count' not in keys:
irc.reply(channel)
irc.reply(optlist)
irc.reply(keys)
irc.reply(args)
utils.sortBy(str.lower, L)
irc.reply(utils.str.commaAndify(L))
else:
irc.reply(args)
irc.reply(channel)
irc.reply(optlist)
irc.reply(keys)
irc.reply(str(len(L)))
示例5: search
def search(self, irc, msg, args, user, optlist, glob):
"""[--{regexp} <value>] [--sent] [<glob>]
Searches your received notes for ones matching <glob>. If --regexp is
given, its associated value is taken as a regexp and matched against
the notes. If --sent is specified, only search sent notes.
"""
criteria = []
def to(note):
return note.to == user.id
def frm(note):
return note.frm == user.id
own = to
for (option, arg) in optlist:
if option == 'regexp':
criteria.append(arg.search)
elif option == 'sent':
own = frm
if glob:
glob = fnmatch.translate(glob)
# ignore the trailing $ fnmatch.translate adds to the regexp
criteria.append(re.compile(glob[:-1]).search)
def match(note):
for p in criteria:
if not p(note.text):
return False
return True
notes = list(self.db.select(lambda n: match(n) and own(n)))
if not notes:
irc.reply('No matching notes were found.')
else:
utils.sortBy(operator.attrgetter('id'), notes)
ids = [self._formatNoteId(msg, note) for note in notes]
ids = self._condense(ids)
irc.reply(format('%L', ids))
示例6: getTopUsers
def getTopUsers(self, channel, word, n):
L = [(id, d[word]) for ((chan, id), d) in self.iteritems()
if ircutils.nickEqual(channel, chan) and word in d]
utils.sortBy(lambda (_, i): i, L)
L = L[-n:]
L.reverse()
return L
示例7: search
def search(self, irc, msg, args, user, optlist, glob):
"""[--{regexp} <value>] [--sent] [<glob>]
Searches your received notes for ones matching <glob>. If --regexp is
given, its associated value is taken as a regexp and matched against
the notes. If --sent is specified, only search sent notes.
"""
criteria = []
def to(note):
return note.to == user.id
def frm(note):
return note.frm == user.id
own = to
for (option, arg) in optlist:
if option == 'regexp':
criteria.append(lambda x: commands.regexp_wrapper(x, reobj=arg,
timeout=0.1, plugin_name = self.name(), fcn_name='search'))
elif option == 'sent':
own = frm
if glob:
glob = utils.python.glob2re(glob)
criteria.append(re.compile(glob).search)
def match(note):
for p in criteria:
if not p(note.text):
return False
return True
notes = list(self.db.select(lambda n: match(n) and own(n)))
if not notes:
irc.reply('No matching notes were found.')
else:
utils.sortBy(operator.attrgetter('id'), notes)
ids = [self._formatNoteId(msg, note) for note in notes]
ids = self._condense(ids)
irc.reply(format('%L', ids))
示例8: networks
def networks(self, irc, msg, args):
"""takes no arguments
Returns the networks to which the bot is currently connected.
"""
L = ['%s: %s' % (ircd.network, ircd.server) for ircd in world.ircs]
utils.sortBy(str.lower, L)
irc.reply(format('%L', L))
示例9: sortAuthors
def sortAuthors():
"""
Sort the list of 'long names' based on the number of contributions
associated with each.
"""
L = list(module.__contributors__.items())
def negativeSecondElement(x):
return -len(x[1])
utils.sortBy(negativeSecondElement, L)
return [t[0] for t in L]
示例10: wulist
def wulist(self, irc, msg, args):
"""takes no arguments
Returns the list of urls in the whitelist.
"""
L = list(self.registryValue('urlWhitelist'))
if L:
utils.sortBy(str.lower, L)
irc.reply(format('%L', L))
else:
irc.reply('There are no urls in the whitelist.')
示例11: channels
def channels(self, irc, msg, args):
"""takes no arguments
Returns the channels the bot is on.
"""
L = irc.state.channels.keys()
if L:
utils.sortBy(ircutils.toLower, L)
irc.reply(format('%L', L), private=True)
else:
irc.reply(_('I\'m not currently in any channels.'))
示例12: channels
def channels(self, irc, msg, args):
"""takes no arguments
Returns the channels the bot is on. Must be given in private, in order
to protect the secrecy of secret channels.
"""
L = irc.state.channels.keys()
if L:
utils.sortBy(ircutils.toLower, L)
irc.reply(format('%L', L))
else:
irc.reply(_('I\'m not currently in any channels.'))
示例13: do315
def do315(self, irc, msg):
mask = msg.args[1]
if mask in self.whos:
(replyIrc, msgs) = self.whos.pop(mask)
nicks = []
for msg in msgs:
nicks.append(msg.args[5])
utils.sortBy(ircutils.toLower, nicks)
if nicks:
replyIrc.reply(format('%s matched: %L.', len(nicks), nicks))
else:
replyIrc.reply('No users matched %s.' % mask)
示例14: nicks
def nicks(self, irc, msg, args):
"""takes no arguments
Returns the nicks that this plugin is configured to identify and ghost
with.
"""
L = list(self.registryValue('nicks'))
if L:
utils.sortBy(ircutils.toLower, L)
irc.reply(format('%L', L))
else:
irc.reply('I\'m not currently configured for any nicks.')
示例15: list
def list(self, irc, msg, args):
"""takes no arguments
Returns the list of words being censored.
"""
L = list(self.words())
if L:
self.filtering = False
utils.sortBy(str.lower, L)
irc.reply(format('%L', L))
else:
irc.reply(_('I\'m not currently censoring any bad words.'))