當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。