本文整理汇总了Python中supybot.callbacks.canonicalName函数的典型用法代码示例。如果您正苦于以下问题:Python canonicalName函数的具体用法?Python canonicalName怎么用?Python canonicalName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了canonicalName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]
示例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.
示例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]
示例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)
示例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()
示例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)))
示例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]
示例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]
示例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)
示例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
示例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--'))
示例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.')
示例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.'))
示例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.'
示例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()