本文整理汇总了Python中jmespath.functions.Functions方法的典型用法代码示例。如果您正苦于以下问题:Python functions.Functions方法的具体用法?Python functions.Functions怎么用?Python functions.Functions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jmespath.functions
的用法示例。
在下文中一共展示了functions.Functions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _custom_functions
# 需要导入模块: from jmespath import functions [as 别名]
# 或者: from jmespath.functions import Functions [as 别名]
def _custom_functions(preview_versions):
class CustomFunctions(functions.Functions): # pylint: disable=too-few-public-methods
@functions.signature({'types': ['array']})
def _func_sort_versions(self, versions): # pylint: disable=no-self-use
"""Custom JMESPath `sort_versions` function that sorts an array of strings as software versions"""
try:
return sorted(versions, key=version_to_tuple)
except (TypeError, ValueError): # if it wasn't sortable, return the input so the pipeline continues
return versions
@functions.signature({'types': ['array']})
def _func_set_preview_array(self, versions):
"""Custom JMESPath `set_preview_array` function that suffixes preview version"""
try:
for i, _ in enumerate(versions):
versions[i] = self._func_set_preview(versions[i])
return versions
except(TypeError, ValueError):
return versions
@functions.signature({'types': ['string']})
def _func_set_preview(self, version): # pylint: disable=no-self-use
"""Custom JMESPath `set_preview` function that suffixes preview version"""
try:
if preview_versions.get(version, False):
return version + '(preview)'
return version
except(TypeError, ValueError):
return version
return CustomFunctions()
示例2: __init__
# 需要导入模块: from jmespath import functions [as 别名]
# 或者: from jmespath.functions import Functions [as 别名]
def __init__(self, options=None):
super(TreeInterpreter, self).__init__()
self._dict_cls = self.MAP_TYPE
if options is None:
options = Options()
self._options = options
if options.dict_cls is not None:
self._dict_cls = self._options.dict_cls
if options.custom_functions is not None:
self._functions = self._options.custom_functions
else:
self._functions = functions.Functions()