本文整理汇总了Python中jsonpointer.JsonPointer.get方法的典型用法代码示例。如果您正苦于以下问题:Python JsonPointer.get方法的具体用法?Python JsonPointer.get怎么用?Python JsonPointer.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonpointer.JsonPointer
的用法示例。
在下文中一共展示了JsonPointer.get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WorkflowView
# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import get [as 别名]
class WorkflowView(object):
'''
Provides a 'view' of the overall workflow object that corresponds
to a particular level of nesting. That is, this presents the scope
within which extension rules operate (i.e. add steps, reference
other steps, etc)
'''
def __init__(self, workflowobj, offset=''):
self.wflow = workflowobj
self.dag = workflowobj.dag
self.rules = workflowobj.rules
self.applied_rules = workflowobj.applied_rules
self.offset = offset
self.steps = JsonPointer(self.offset).resolve(workflowobj.stepsbystage)
self.bookkeeper = JsonPointer(self.offset).resolve(workflowobj.bookkeeping)
self.values = JsonPointer(self.offset).resolve(workflowobj.values)
def view(self, offset):
'''
return a view with an additional offset to this view's offset
'''
return self.wflow.view(self._makeoffset(offset))
def query(self, query, collection):
'''
:return
'''
matches = jsonpath_rw.parse(query).find(collection)
return matches
def getSteps(self, query):
'''
returns steps related to the JSONPath query.
if a query points to a stage (say 'stagename'):
will return all toplevel steps.. no recursion into subworkflows
if a query points to steps (e.g. 'stagename[*]')
will return a steps directly
'''
nodeids = []
matches = self.query(query, self.steps)
for match in matches:
value = match.value
#step endpoint case
if isinstance(value,dict) and '_nodeid' in value:
nodeids.append(value['_nodeid'])
#stage endpoint case
elif isinstance(value,list):
for item in value:
if '_nodeid' in item:
nodeids.append(item['_nodeid'])
result = [self.dag.getNode(nodeid) for nodeid in nodeids]
return result
def _makeoffset(self, offset):
'''
prepare a full offset based on this views' offset and a relative offset
:param offset: the relative offset
'''
thisoffset = JsonPointer(offset)
if self.offset:
fulloffset = JsonPointer.from_parts(JsonPointer(self.offset).parts + thisoffset.parts).path
else:
fulloffset = thisoffset.path
return fulloffset
def getRule(self, name=None, offset='', identifier=None):
'''retrieve a rule by offset or name or identifier'''
fulloffset = self._makeoffset(offset)
for x in self.rules + self.applied_rules:
if x.identifier == identifier or (x.offset == fulloffset and x.rule.name == name):
return x
return None
def init(self, initdata, init_provider = None, used_inputs = None, name='init', discover = False, relative = True):
'''
initialize this scope by adding an initialization stage.
:param inidata: initialization JSON data
'''
spec = init_stage_spec(
initdata, discover, used_inputs or [], name, relative = relative)
self.addRule(JsonStage(spec, init_provider), self.offset)
def addRule(self, rule, offset='', identifier = None):
'''
add a DAG extension rule, possibly with a scope offset
'''
thisoffset = JsonPointer(offset)
if offset != '':
createIndexData(thisoffset.path, self.steps, self.values)
createOffsetMeta(thisoffset.path, self.bookkeeper)
offsetstage = OffsetStage(rule, self._makeoffset(offset), identifier = identifier)
self.rules += [offsetstage]
thisoffset.resolve(self.bookkeeper)['_meta']['stages'] += [offsetstage.identifier]
#.........这里部分代码省略.........