本文整理汇总了Python中supybot.callbacks.canonicalName函数的典型用法代码示例。如果您正苦于以下问题:Python canonicalName函数的具体用法?Python canonicalName怎么用?Python canonicalName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了canonicalName函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: addAlias
def addAlias(self, irc, name, alias, lock=False):
if not self.isValidName(name):
raise AliasError('Invalid alias name.')
realName = callbacks.canonicalName(name)
if name != realName:
s = format(_('That name isn\'t valid. Try %q instead.'), realName)
raise AliasError(s)
name = realName
if self.isCommandMethod(name):
if realName not in self.aliases:
s = 'You can\'t overwrite commands in this plugin.'
raise AliasError(s)
if name in self.aliases:
(currentAlias, locked, _) = self.aliases[name]
if locked and currentAlias != alias:
raise AliasError(format('Alias %q is locked.', name))
f = makeNewAlias(name, alias)
f = types.MethodType(f, self)
if name in self.aliases:
# We gotta remove it so its value gets updated.
self.aliasRegistryRemove(name)
aliasGroup = self.aliasRegistryGroup(name)
if needsEscaping(name):
confname = escapeAlias(name)
else:
confname = name
conf.registerGlobalValue(aliasGroup, confname,
registry.String(alias, ''))
conf.registerGlobalValue(aliasGroup.get(confname), 'locked',
registry.Boolean(lock, ''))
self.aliases[name] = [alias, lock, f]
开发者ID:ElectroCode,项目名称:Limnoria,代码行数:31,代码来源:plugin.py
示例2: __call__
def __call__(self, irc, msg):
self.__parent.__call__(irc, msg)
irc = callbacks.SimpleProxy(irc, msg)
newFeeds = {}
for channel in irc.state.channels:
feeds = self.registryValue("announce", channel)
for name in feeds:
commandName = callbacks.canonicalName(name)
if self.isCommandMethod(commandName):
url = self.feedNames[commandName][0]
else:
url = name
if self.willGetNewFeed(url):
newFeeds.setdefault((url, name), []).append(channel)
for ((url, name), channels) in newFeeds.iteritems():
# We check if we can acquire the lock right here because if we
# don't, we'll possibly end up spawning a lot of threads to get
# the feed, because this thread may run for a number of bytecodes
# before it switches to a thread that'll get the lock in
# _newHeadlines.
if self.acquireLock(url, blocking=False):
try:
t = threading.Thread(
target=self._newHeadlines, name=format("Fetching %u", url), args=(irc, channels, name, url)
)
self.log.info("Checking for announcements at %u", url)
world.threadsSpawned += 1
t.setDaemon(True)
t.start()
finally:
self.releaseLock(url)
time.sleep(0.1) # So other threads can run.
开发者ID:MrTiggr,项目名称:supybot_fixes,代码行数:32,代码来源:plugin.py
示例3: addAlias
def addAlias(self, irc, name, alias, lock=False):
if self._invalidCharsRe.search(name):
raise AliasError, "Names cannot contain spaces or square brackets."
if "|" in name:
raise AliasError, "Names cannot contain pipes."
realName = callbacks.canonicalName(name)
if name != realName:
s = format("That name isn't valid. Try %q instead.", realName)
raise AliasError, s
name = realName
if self.isCommandMethod(name):
if realName not in self.aliases:
s = "You can't overwrite commands in this plugin."
raise AliasError, s
if name in self.aliases:
(currentAlias, locked, _) = self.aliases[name]
if locked and currentAlias != alias:
raise AliasError, format("Alias %q is locked.", name)
try:
f = makeNewAlias(name, alias)
f = new.instancemethod(f, self, Alias)
except RecursiveAlias:
raise AliasError, "You can't define a recursive alias."
if name in self.aliases:
# We gotta remove it so its value gets updated.
conf.supybot.plugins.Alias.aliases.unregister(name)
conf.supybot.plugins.Alias.aliases.register(name, registry.String(alias, ""))
conf.supybot.plugins.Alias.aliases.get(name).register("locked", registry.Boolean(lock, ""))
self.aliases[name] = [alias, lock, f]
开发者ID:ephemey,项目名称:ephesite,代码行数:29,代码来源:plugin.py
示例4: renameCommand
def renameCommand(cb, name, newName):
assert not hasattr(cb, newName), "Cannot rename over existing attributes."
assert newName == callbacks.canonicalName(newName), "newName must already be normalized."
if name != newName:
method = getattr(cb.__class__, name)
setattr(cb.__class__, newName, method)
delattr(cb.__class__, name)
开发者ID:nanotube,项目名称:supybot_fixes,代码行数:7,代码来源:plugin.py
示例5: remove_aka
def remove_aka(self, channel, name):
name = callbacks.canonicalName(name, preserve_spaces=True)
if sys.version_info[0] < 3 and isinstance(name, str):
name = name.decode('utf8')
db = self.get_db(channel)
db.query(SQLAlchemyAlias).filter(SQLAlchemyAlias.name == name).delete()
db.commit()
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:7,代码来源:plugin.py
示例6: get_feedName
def get_feedName(irc, msg, args, state):
if ircutils.isChannel(args[0]):
state.errorInvalid('feed name', args[0], 'must not be channel names.')
if not registry.isValidRegistryName(args[0]):
state.errorInvalid('feed name', args[0],
'Feed names must not include spaces.')
state.args.append(callbacks.canonicalName(args.pop(0)))
开发者ID:tvieira,项目名称:Limnoria,代码行数:7,代码来源:plugin.py
示例7: addAlias
def addAlias(self, irc, name, alias, lock=False):
if self._invalidCharsRe.search(name):
raise AliasError, 'Names cannot contain spaces or square brackets.'
if '|' in name:
raise AliasError, 'Names cannot contain pipes.'
realName = callbacks.canonicalName(name)
if name != realName:
s = format('That name isn\'t valid. Try %q instead.', realName)
raise AliasError, s
name = realName
if self.isCommandMethod(name):
if realName not in self.aliases:
s = 'You can\'t overwrite commands in this plugin.'
raise AliasError, s
if name in self.aliases:
(currentAlias, locked, _) = self.aliases[name]
if locked and currentAlias != alias:
raise AliasError, format('Alias %q is locked.', name)
try:
f = makeNewAlias(name, alias)
f = new.instancemethod(f, self, Alias)
except RecursiveAlias:
raise AliasError, 'You can\'t define a recursive alias.'
aliasGroup = self.registryValue('aliases', value=False)
if name in self.aliases:
# We gotta remove it so its value gets updated.
aliasGroup.unregister(name)
conf.registerGlobalValue(aliasGroup, name, registry.String(alias, ''))
conf.registerGlobalValue(aliasGroup.get(name), 'locked',
registry.Boolean(lock, ''))
self.aliases[name] = [alias, lock, f]
开发者ID:Chalks,项目名称:Supybot,代码行数:31,代码来源:plugin.py
示例8: addAlias
def addAlias(self, irc, name, alias, lock=False):
if not self._validNameRe.search(name):
raise AliasError('Names can only contain alphanumerical '
'characters, dots, pipes, and '
'exclamation/interrogatin marks '
'(and the first character cannot be a number).')
realName = callbacks.canonicalName(name)
if name != realName:
s = format(_('That name isn\'t valid. Try %q instead.'), realName)
raise AliasError(s)
name = realName
if self.isCommandMethod(name):
if realName not in self.aliases:
s = 'You can\'t overwrite commands in this plugin.'
raise AliasError(s)
if name in self.aliases:
(currentAlias, locked, _) = self.aliases[name]
if locked and currentAlias != alias:
raise AliasError(format('Alias %q is locked.', name))
f = makeNewAlias(name, alias)
f = types.MethodType(f, self)
if '.' in name or '|' in name:
aliasGroup = self.registryValue('escapedaliases', value=False)
confname = escapeAlias(name)
else:
aliasGroup = self.registryValue('aliases', value=False)
confname = name
if name in self.aliases:
# We gotta remove it so its value gets updated.
aliasGroup.unregister(confname)
conf.registerGlobalValue(aliasGroup, confname,
registry.String(alias, ''))
conf.registerGlobalValue(aliasGroup.get(confname), 'locked',
registry.Boolean(lock, ''))
self.aliases[name] = [alias, lock, f]
开发者ID:gerdesas,项目名称:Limnoria,代码行数:35,代码来源:plugin.py
示例9: has_aka
def has_aka(self, channel, name):
name = callbacks.canonicalName(name, preserve_spaces=True)
if sys.version_info[0] < 3 and isinstance(name, str):
name = name.decode('utf8')
count = self.get_db(channel).query(SQLAlchemyAlias) \
.filter(SQLAlchemyAlias.name == name) \
.count()
return bool(count)
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:8,代码来源:plugin.py
示例10: get_alias
def get_alias(self, channel, name):
name = callbacks.canonicalName(name, preserve_spaces=True)
if sys.version_info[0] < 3 and isinstance(name, str):
name = name.decode('utf8')
try:
return self.get_db(channel).query(SQLAlchemyAlias.alias) \
.filter(SQLAlchemyAlias.name == name).one()[0]
except sqlalchemy.orm.exc.NoResultFound:
return None
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:9,代码来源:plugin.py
示例11: testCanonicalName
def testCanonicalName(self):
self.assertEqual('foo', callbacks.canonicalName('foo'))
self.assertEqual('foobar', callbacks.canonicalName('foo-bar'))
self.assertEqual('foobar', callbacks.canonicalName('foo_bar'))
self.assertEqual('foobar', callbacks.canonicalName('FOO-bar'))
self.assertEqual('foobar', callbacks.canonicalName('FOOBAR'))
self.assertEqual('foobar', callbacks.canonicalName('foo___bar'))
self.assertEqual('foobar', callbacks.canonicalName('_f_o_o-b_a_r'))
# The following seems to be a hack for the Karma plugin; I'm not
# entirely sure that it's completely necessary anymore.
self.assertEqual('foobar--', callbacks.canonicalName('foobar--'))
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:11,代码来源:test_callbacks.py
示例12: removeAlias
def removeAlias(self, name, evenIfLocked=False):
name = callbacks.canonicalName(name)
if name in self.aliases and self.isCommandMethod(name):
if evenIfLocked or not self.aliases[name][1]:
del self.aliases[name]
self.aliasRegistryRemove(name)
else:
raise AliasError('That alias is locked.')
else:
raise AliasError('There is no such alias.')
开发者ID:ElectroCode,项目名称:Limnoria,代码行数:10,代码来源:plugin.py
示例13: get_aka_lock
def get_aka_lock(self, channel, name):
name = callbacks.canonicalName(name, preserve_spaces=True)
if sys.version_info[0] < 3 and isinstance(name, str):
name = name.decode('utf8')
try:
return self.get_db(channel) \
.query(SQLAlchemyAlias.locked, SQLAlchemyAlias.locked_by, SQLAlchemyAlias.locked_at)\
.filter(SQLAlchemyAlias.name == name).one()
except sqlalchemy.orm.exc.NoResultFound:
raise AkaError(_('This Aka does not exist.'))
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:10,代码来源:plugin.py
示例14: removeAlias
def removeAlias(self, name, evenIfLocked=False):
name = callbacks.canonicalName(name)
if name in self.aliases and self.isCommandMethod(name):
if evenIfLocked or not self.aliases[name][1]:
del self.aliases[name]
conf.supybot.plugins.Alias.aliases.unregister(name)
else:
raise AliasError, 'That alias is locked.'
else:
raise AliasError, 'There is no such alias.'
开发者ID:Chalks,项目名称:Supybot,代码行数:10,代码来源:plugin.py
示例15: unlock_aka
def unlock_aka(self, channel, name, by):
name = callbacks.canonicalName(name, preserve_spaces=True)
if sys.version_info[0] < 3 and isinstance(name, str):
name = name.decode('utf8')
db = self.get_db(channel)
cursor = db.cursor()
cursor.execute("""UPDATE aliases SET locked=0, locked_at=?
WHERE name = ?""", (datetime.datetime.now(), name))
if cursor.rowcount == 0:
raise AkaError(_('This Aka does not exist.'))
db.commit()
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:11,代码来源:plugin.py
示例16: search
def search(self, irc, msg, args, optlist, query):
"""[--channel <#channel>] <query>
Searches Akas defined for <channel>. If <channel> is not specified,
searches all global Akas."""
query = callbacks.canonicalName(query, preserve_spaces=True)
channel = 'global'
for (option, arg) in optlist:
if option == 'channel':
if not ircutils.isChannel(arg):
irc.error(_('%r is not a valid channel.') % arg,
Raise=True)
channel = arg
aka_list = self._db.get_aka_list(channel)
aka_list = [callbacks.canonicalName(k[0], preserve_spaces=True)
for k in aka_list]
matching = [aka for aka in aka_list if query in aka]
if matching:
irc.replies(matching)
else:
irc.error(_("No matching Akas were found."))
开发者ID:GLolol,项目名称:Limnoria,代码行数:21,代码来源:plugin.py
示例17: add_aka
def add_aka(self, channel, name, alias):
name = callbacks.canonicalName(name, preserve_spaces=True)
if self.has_aka(channel, name):
raise AkaError(_('This Aka already exists.'))
if sys.version_info[0] < 3:
if isinstance(name, str):
name = name.decode('utf8')
if isinstance(alias, str):
alias = alias.decode('utf8')
db = self.get_db(channel)
db.add(SQLAlchemyAlias(name, alias))
db.commit()
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:12,代码来源:plugin.py
示例18: TestDocumentation
def TestDocumentation(self):
if self.__class__ in (PluginTestCase, ChannelPluginTestCase):
return
for cb in self.irc.callbacks:
name = cb.name()
if (name in self._noTestDoc) and not name.lower() in self.__class__.__name__.lower():
continue
self.failUnless(sys.modules[cb.__class__.__name__].__doc__, "%s has no module documentation." % name)
if hasattr(cb, "isCommandMethod"):
for attr in dir(cb):
if cb.isCommandMethod(attr) and attr == callbacks.canonicalName(attr):
self.failUnless(getattr(cb, attr, None).__doc__, "%s.%s has no help." % (name, attr))
开发者ID:cnelsonsic,项目名称:Limnoria,代码行数:12,代码来源:test.py
示例19: isCommandMethod
def isCommandMethod(self, name):
args = name.split(' ')
if len(args) > 1 and \
callbacks.canonicalName(args[0]) != self.canonicalName():
for cb in dynamic.irc.callbacks: # including this plugin
if cb.getCommand(args[0:-1]):
return False
if sys.version_info[0] < 3 and isinstance(name, str):
name = name.decode('utf8')
channel = dynamic.channel or 'global'
return self._db.has_aka(channel, name) or \
self._db.has_aka('global', name) or \
self.__parent.isCommandMethod(name)
开发者ID:foxtacles,项目名称:Limnoria,代码行数:13,代码来源:plugin.py
示例20: getEventName
def getEventName(irc, msg, args, state):
if not registry.isValidRegistryName(args[0]):
state.errorInvalid('event name', args[0],
'Illegal event name')
state.args.append(callbacks.canonicalName(args.pop(0)))
开发者ID:hce,项目名称:supybotplugins,代码行数:5,代码来源:plugin.py
注:本文中的supybot.callbacks.canonicalName函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论