本文整理汇总了Python中utilities.Utilities.format方法的典型用法代码示例。如果您正苦于以下问题:Python Utilities.format方法的具体用法?Python Utilities.format怎么用?Python Utilities.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utilities.Utilities
的用法示例。
在下文中一共展示了Utilities.format方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ls
# 需要导入模块: from utilities import Utilities [as 别名]
# 或者: from utilities.Utilities import format [as 别名]
def ls(self, *args):
"""
list commands
(command)?
this exists just for convenience. Use <span class="blue">help</span> for help.
"""
commands = self.commands()
if args:
if args[0] not in commands:
raise self.UnknownCommandError(args[0])
commands = args[:1]
self.shell.log.append(Utilities.format(commands))
self.shell.log.append()
示例2: complete
# 需要导入模块: from utilities import Utilities [as 别名]
# 或者: from utilities.Utilities import format [as 别名]
def complete(self, input):
l = re.split('\s+', input)
matches = [m for m in self.shell.builtins.commands() if re.match(l[0], m)]
matches_length = len(matches)
# matches found
if matches_length > 0:
# partial or exact match
if not l[1:]: # only on first word
# many matches found
if matches_length > 1:
command = Utilities.longest_common_prefix(matches)
completion = Utilities.format(matches)
# one match found
elif matches_length == 1:
command = matches[0]
completion = ''
# exact match with space added for sub completion
elif re.match('{0}\s+'.format(l[0]), input):
try:
submatches = \
[m for m in eval('self.shell.builtins._{0}_completion()'.format(l[0])) if \
re.match(' '.join(l[1:]).strip(), m)]
submatches_length = len(submatches)
# many submatches found
if submatches_length > 1:
command = '{0} {1}'.format(l[0], Utilities.longest_common_prefix(submatches))
completion = Utilities.format(submatches)
# one submatch found
elif submatches_length == 1:
command = '{0} {1}'.format(l[0], submatches[0])
completion = ''
# no submatch found
else:
command = input
completion = ''
# _xxx_completion() does not exist
except AttributeError:
command = input
completion = ''
# no match
else:
command = input
completion = ''
# no match found
else:
command = input
completion = ''
return json.dumps({'command': command,
'completion': completion})