def get_cmdcls(self, cmdname, interface='ACTIVE', exclusive=False):
"""Resolve command name `cmdname` to command class
If `interface` is 'ACTIVE', return command class from
`active_commands`.
If `interface` is 'ANY', return command class from `all_commands`.
If `interface` is anything else, it must be an existing interface and
only a command that supports it is returned.
If `exclusive` evaluates to True, the returned command class does not
support any other interfaces.
Returns None if not matching command class is registered.
"""
if interface == 'ACTIVE':
cmdpool = self.active_commands
elif interface == 'ANY':
cmdpool = self.all_commands
elif isinstance(interface, abc.Hashable):
try:
cmdpool = tuple(self._cmds[interface].values())
except KeyError:
raise ValueError('Unknown interface: {!r}'.format(interface))
else:
raise RuntimeError('Interface type must be hashable: {!r}'.format(interface))
for cmd in cmdpool:
if cmdname in cmd.names:
if not exclusive:
return cmd
elif cmd.provides == (interface,):
return cmd
评论列表
文章目录