本文整理匯總了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()