当前位置: 首页>>代码示例>>Python>>正文


Python jsonpatch.JsonPatch方法代码示例

本文整理汇总了Python中jsonpatch.JsonPatch方法的典型用法代码示例。如果您正苦于以下问题:Python jsonpatch.JsonPatch方法的具体用法?Python jsonpatch.JsonPatch怎么用?Python jsonpatch.JsonPatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonpatch的用法示例。


在下文中一共展示了jsonpatch.JsonPatch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _apply_patches

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def _apply_patches(self, resources):
        for _, resource in resources.iteritems():
            if self.namespace:
                if 'namespace' in resource['value']['metadata']:
                    op = 'replace'
                else:
                    op = 'add'
                resource['patch'].append({
                    "op": op,
                    "path": "/metadata/namespace",
                    "value": self.namespace})

            if len(resource['patch']):
                patch = jsonpatch.JsonPatch(resource['patch'])
                result = patch.apply(resource['value'])
                resource['value'] = result
        return resources 
开发者ID:app-registry,项目名称:appr,代码行数:19,代码来源:kub.py

示例2: _apply_patches

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def _apply_patches(self, resources):
        for _, resource in resources.iteritems():
            if self.namespace:
                if 'namespace' in resource['value']['metadata']:
                    op = 'replace'
                else:
                    op = 'add'
                resource['patch'].append({
                    "op": op,
                    "path": "/metadata/namespace",
                    "value": self.namespace
                })

            if len(resource['patch']):
                patch = jsonpatch.JsonPatch(resource['patch'])
                result = patch.apply(resource['value'])
                resource['value'] = result
        return resources 
开发者ID:coreos,项目名称:kpm,代码行数:20,代码来源:kub.py

示例3: model

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def model(self, **config_kwargs):
        """
        Create a model object with/without patches applied.

        See :func:`pyhf.workspace.Workspace.get_measurement` and :class:`pyhf.pdf.Model` for possible keyword arguments.

        Args:
            patches: A list of JSON patches to apply to the model specification
            config_kwargs: Possible keyword arguments for the measurement and model configuration

        Returns:
            ~pyhf.pdf.Model: A model object adhering to the schema model.json

        """

        poi_name = config_kwargs.pop('poi_name', None)
        measurement_name = config_kwargs.pop('measurement_name', None)
        measurement_index = config_kwargs.pop('measurement_index', None)
        measurement = self.get_measurement(
            poi_name=poi_name,
            measurement_name=measurement_name,
            measurement_index=measurement_index,
        )
        log.debug(
            'model being created for measurement {0:s}'.format(measurement['name'])
        )

        patches = config_kwargs.pop('patches', [])

        modelspec = {
            'channels': self['channels'],
            'parameters': measurement['config']['parameters'],
        }
        for patch in patches:
            modelspec = jsonpatch.JsonPatch(patch).apply(modelspec)

        return Model(modelspec, poi_name=measurement['config']['poi'], **config_kwargs) 
开发者ID:scikit-hep,项目名称:pyhf,代码行数:39,代码来源:workspace.py

示例4: json2xml

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def json2xml(workspace, output_dir, specroot, dataroot, resultprefix, patch):
    """Convert pyhf JSON back to XML + ROOT files."""
    try:
        import uproot

        assert uproot
    except ImportError:
        log.error(
            "json2xml requires uproot, please install pyhf using the "
            "xmlio extra: python -m pip install pyhf[xmlio]"
        )
    from .. import writexml

    os.makedirs(output_dir, exist_ok=True)
    with click.open_file(workspace, 'r') as specstream:
        spec = json.load(specstream)
        for pfile in patch:
            patch = json.loads(click.open_file(pfile, 'r').read())
            spec = jsonpatch.JsonPatch(patch).apply(spec)
        os.makedirs(Path(output_dir).joinpath(specroot), exist_ok=True)
        os.makedirs(Path(output_dir).joinpath(dataroot), exist_ok=True)
        with click.open_file(
            Path(output_dir).joinpath(f'{resultprefix}.xml'), 'w'
        ) as outstream:
            outstream.write(
                writexml.writexml(
                    spec,
                    Path(output_dir).joinpath(specroot),
                    Path(output_dir).joinpath(dataroot),
                    resultprefix,
                ).decode('utf-8')
            ) 
开发者ID:scikit-hep,项目名称:pyhf,代码行数:34,代码来源:rootio.py

示例5: __eq__

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def __eq__(self, other):
        """ Equality for subclass with new attributes """
        if not isinstance(other, Patch):
            return False
        return (
            jsonpatch.JsonPatch.__eq__(self, other) and self.metadata == other.metadata
        ) 
开发者ID:scikit-hep,项目名称:pyhf,代码行数:9,代码来源:patchset.py

示例6: apply_jsonpatch

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def apply_jsonpatch(doc, patch):
    for p in patch:
        if p['op'] == 'add' and p['path'].count('/') == 1:
            if p['path'].lstrip('/') not in doc:
                msg = _('Adding a new attribute (%s) to the root of '
                        ' the resource is not allowed')
                raise wsme.exc.ClientSideError(msg % p['path'])
    return jsonpatch.apply_patch(doc, jsonpatch.JsonPatch(patch)) 
开发者ID:openstack,项目名称:watcher,代码行数:10,代码来源:utils.py

示例7: patch

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def patch(operations):
    if jsonpatch:
        json_patch = jsonpatch.JsonPatch(operations)

        def patcher(doc):
            return json_patch.apply(doc)

    else:

        def patcher(doc):
            # If jsonpatch could not be imported, then `@chaos_utils.patch()`
            # will be disabled, and will silently return values unmodified,
            # without applying the JSON patch operations.
            return doc

    def inner(patched_function):
        def patched_inner(*args, **kwargs):
            return_value = patched_function(*args, **kwargs)
            not_json = False
            if not isinstance(return_value, six.text_type):
                return_value = json.dumps(return_value)
                not_json = True
            return_value = patcher(return_value)
            if not_json:
                return_value = json.loads(return_value)
            return return_value
        return patched_inner
    return inner 
开发者ID:box,项目名称:box-python-sdk,代码行数:30,代码来源:chaos_utils.py

示例8: default

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def default(self, obj):
        """Set defaults

		:param obj: json object.
        :type obj: str.

		"""
        if isinstance(obj, Dictable):
            return obj.to_dict()
        elif isinstance(obj, jsonpatch.JsonPatch):
            return obj.patch
        return super(JSONEncoder, self).default(obj) 
开发者ID:HewlettPackard,项目名称:python-ilorest-library-old,代码行数:14,代码来源:sharedtypes.py

示例9: diff

# 需要导入模块: import jsonpatch [as 别名]
# 或者: from jsonpatch import JsonPatch [as 别名]
def diff(self, hash1, hash2=None, txid=None):
        branch = self._branches[txid]
        rev1 = branch[hash1]
        rev2 = branch[hash2] if hash2 else branch._latest
        if rev1.hash == rev2.hash:
            return JsonPatch([])
        else:
            dict1 = message_to_dict(rev1.data)
            dict2 = message_to_dict(rev2.data)
            return make_patch(dict1, dict2)

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tagging utility ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
开发者ID:opencord,项目名称:voltha,代码行数:14,代码来源:config_node.py


注:本文中的jsonpatch.JsonPatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。