本文整理汇总了Python中jsonpointer.JsonPointer.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python JsonPointer.setdefault方法的具体用法?Python JsonPointer.setdefault怎么用?Python JsonPointer.setdefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonpointer.JsonPointer
的用法示例。
在下文中一共展示了JsonPointer.setdefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WorkflowView
# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import setdefault [as 别名]
#.........这里部分代码省略.........
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]
return offsetstage.identifier
def addValue(self, key, value):
v = self.values.setdefault('_values', {})
if key in v:
raise RuntimeError('cannot overwrite value')
v[key] = value
def getValue(self, key):
return self.values.setdefault('_values', {}).get(key)
def addStep(self, task, stage, depends_on=None):
'''
adds a node to the DAG connecting it to the passed depending nodes
while tracking that it was added by the specified stage
:param task: the task object for the step
:param stage: the stage name
:param depends_on: dependencies of this step
'''
self.steps.setdefault(stage,[])
node = YadageNode(task.metadata['name'], task, identifier=get_obj_id(task))
node.task.metadata['wflow_node_id'] = node.identifier
node.task.metadata['wflow_offset'] = self.offset
node.task.metadata['wflow_stage'] = stage
node.task.metadata['wflow_stage_node_idx'] = len(self.steps[stage])
node.task.metadata['wflow_hints'] = {'is_purepub': task.pubOnlyTask()}
self.dag.addNode(node, depends_on=depends_on)
self.steps[stage].append({'_nodeid': node.identifier})
self.bookkeeper['_meta']['steps'] += [node.identifier]
log.info('added %s',node)
return node
def addWorkflow(self, rules, stage=None):
'''
add a (sub-)workflow (i.e. list of stages) to the overall workflow
'''
offset = ''
if stage is not None:
#make sure storage for the 'authoring' stage is present and
#register the workflow as part of that 'author'
#needed e.g. for predicate handlers trying to determing if
#the author stage is done
nextindex = len(self.steps.get(stage,[]))
offset = JsonPointer.from_parts([stage, nextindex]).path
self.steps.setdefault(stage,[]).append({})
self.values.setdefault(stage,[]).append({})
for rule in rules:
self.addRule(rule, offset)