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


Python jsonmerge.merge方法代码示例

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


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

示例1: test_version_meta

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_version_meta(self):

        schema = {'mergeStrategy': 'version'}

        merger = jsonmerge.Merger(schema)

        base = None
        base = merger.merge(base, "a", merge_options={
                'version': {'metadata': {'uri': 'http://example.com/a'}}})
        base = merger.merge(base, "b", merge_options={
                'version': {'metadata': {'uri': 'http://example.com/b'}}})

        self.assertEqual(base, [
            {'value': "a",
             'uri': 'http://example.com/a'},
            {'value': "b",
             'uri': 'http://example.com/b'}]) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:19,代码来源:test_jsonmerge.py

示例2: test_internal_refs

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_internal_refs(self):

        schema = {
            'id': 'http://example.com/schema_1.json',
            'properties': {
                'a': {'$ref': "#/definitions/a"},
            },
            'definitions': {
                "a": {
                    "properties": {
                        "b": {'mergeStrategy': 'version'},
                    }
                },
            }
        }

        merger = jsonmerge.Merger(schema)

        base = None
        base = merger.merge(base, {"a": {"b": "c"}})
        base = merger.merge(base, {"a": {"b": "d"}})

        self.assertEqual(base, {"a": {"b": [{"value": "c"}, {"value": "d"}]}}) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:25,代码来源:test_jsonmerge.py

示例3: test_oneof_overwrite_toplevel

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_oneof_overwrite_toplevel(self):
        schema = {
            'mergeStrategy': 'overwrite',
            'oneOf': [
                {
                    'type': 'array'
                },
                {
                    'type': 'string'
                },
            ]
        }

        merger = jsonmerge.Merger(schema)

        self.assertEqual(merger.merge([2, 3, 4], 'a'), 'a')
        self.assertEqual(merger.merge('a', [2, 3, 4]), [2, 3, 4]) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:19,代码来源:test_jsonmerge.py

示例4: test_anyof_overwrite_toplevel

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_anyof_overwrite_toplevel(self):
        schema = {
            'mergeStrategy': 'overwrite',
            'anyOf': [
                {
                    'type': 'array'
                },
                {
                    'type': 'string'
                },
            ]
        }

        merger = jsonmerge.Merger(schema)

        self.assertEqual(merger.merge([2, 3, 4], 'a'), 'a')
        self.assertEqual(merger.merge('a', [2, 3, 4]), [2, 3, 4]) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:19,代码来源:test_jsonmerge.py

示例5: test_custom_strategy

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_custom_strategy(self):

        schema = {'mergeStrategy': 'myStrategy'}

        class MyStrategy(jsonmerge.strategies.Strategy):
            def merge(self, walk, base, head, schema, meta, **kwargs):
                if base is None:
                    ref = ""
                else:
                    ref = base.ref

                return JSONValue("foo", ref)

        merger = jsonmerge.Merger(schema=schema,
                                  strategies={'myStrategy': MyStrategy()})

        base = None
        base = merger.merge(base, {'a': 1})

        self.assertEqual(base, "foo") 
开发者ID:avian2,项目名称:jsonmerge,代码行数:22,代码来源:test_jsonmerge.py

示例6: test_merge_by_id_no_key

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_merge_by_id_no_key(self):
        schema = {
            "mergeStrategy": "arrayMergeById",
        }

        a = [
            {"id": "A", "field": 1},
        ]

        b = [
            {'field': 2}
        ]

        merger = jsonmerge.Merger(schema)

        base = None
        base = merger.merge(base, a)
        base = merger.merge(base, b)

        # it should ignore array elements that do not have the id
        self.assertEqual(base, a) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:23,代码来源:test_jsonmerge.py

示例7: test_merge_by_id_only_integers

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_merge_by_id_only_integers(self):

        # arrayMergeById strategy can be used to treat simple arrays of
        # integers as Python sets by setting idRef to root (i.e. pointing to
        # the array element itself)
        #
        # https://github.com/avian2/jsonmerge/issues/24

        schema = {
            "mergeStrategy": "arrayMergeById",
            "mergeOptions": {"idRef": "/"},
        }

        base = [ 1, 2 ]
        head = [ 2, 3 ]

        expected = [ 1, 2, 3]

        merger = jsonmerge.Merger(schema)

        base = merger.merge(base, head)

        self.assertEqual(base, expected) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:25,代码来源:test_jsonmerge.py

示例8: test_merge_by_id_non_unique_base

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_merge_by_id_non_unique_base(self):
        schema = {
            "mergeStrategy": "arrayMergeById",
        }

        base = [
            {'id': 'a'},
            {'id': 'a'}
        ]

        head = [
            {'id': 'a',
             'foo': 1}
        ]

        merger = jsonmerge.Merger(schema)

        with self.assertRaises(BaseInstanceError) as cm:
            merger.merge(base, head)

        self.assertEqual(cm.exception.value.ref, '#/1') 
开发者ID:avian2,项目名称:jsonmerge,代码行数:23,代码来源:test_jsonmerge.py

示例9: test_append_with_unique

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_append_with_unique(self):

        schema = {
            "mergeStrategy": "append",
            "uniqueItems": True,
        }

        merger = jsonmerge.Merger(schema)

        head = ["a"]
        base = None

        base = merger.merge(base, head)
        base = merger.merge(base, head)

        schema2 = merger.get_schema()

        jsonschema.validate(head, schema2)
        jsonschema.validate(base, schema2) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:21,代码来源:test_jsonmerge.py

示例10: test_discard_null_keep

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_discard_null_keep(self):

        schema = {
                'properties': {
                    'a': {
                        'mergeStrategy': 'discard',
                        'mergeOptions': {
                            'keepIfUndef': True
                        }
                    }
                } }

        base = {}
        head = {'a': 1}

        base = jsonmerge.merge(base, head, schema)
        self.assertEqual(base, {'a': 1})

        head = {'a': 2}

        base = jsonmerge.merge(base, head, schema)
        self.assertEqual(base, {'a': 1}) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:24,代码来源:test_jsonmerge.py

示例11: test_merge_by_index_name_in_exception

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def test_merge_by_index_name_in_exception(self):
        schema = {
            'properties': {
                'a': {
                    'mergeStrategy': 'arrayMergeByIndex'
                }
            }
        }

        head = {'a': {}}
        base = {'a': []}

        merger = jsonmerge.Merger(schema)
        with self.assertRaises(HeadInstanceError) as cm:
            merger.merge(base, head)

        self.assertIn('arrayMergeByIndex', str(cm.exception)) 
开发者ID:avian2,项目名称:jsonmerge,代码行数:19,代码来源:test_jsonmerge.py

示例12: restoreConfig

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def restoreConfig(ldifFolder, newLdif, ldifModFolder):
    logging.info('Comparing old LDAP data and creating `modify` files.')
    ignoreList = ['objectClass', 'ou', 'oxAuthJwks', 'oxAuthConfWebKeys']
    current_config_dns = getDns(newLdif)
    oldDnMap = getOldEntryMap(ldifFolder)
    for dn in oldDnMap.keys():
        old_entry = getEntry("%s/%s" % (ldifFolder, oldDnMap[dn]), dn)
        if dn not in current_config_dns:
            addEntry(dn, old_entry, ldifModFolder)
            continue
        new_entry = getEntry(newLdif, dn)
        for attr in old_entry.keys():
            # Note: Prefixing with part length helps in inserting base
            # before leaf entries in the LDAP
            # Filename = DN_part_length + unique random string
            new_fn = str(len(dn.split(','))) + '_' + str(uuid.uuid4())
            filename = '%s/%s.ldif' % (ldifModFolder, new_fn)

            if attr in ignoreList:
                continue

            if attr not in new_entry:
                writeMod(dn, attr, old_entry[attr], filename, True)
                logging.debug("Adding attr %s to %s", attr, dn)
            elif old_entry[attr] != new_entry[attr]:
                mod_list = None
                if len(old_entry[attr]) == 1:
                    try:
                        logging.debug("Merging json value for %s", attr)
                        old_json = json.loads(old_entry[attr][0])
                        new_json = json.loads(new_entry[attr][0])
                        new_json = merge(new_json, old_json)
                        mod_list = [json.dumps(new_json)]
                    except:
                        mod_list = old_entry[attr]
                        logging.debug("Keeping old value for %s", attr)
                else:
                    mod_list = old_entry[attr]
                    logging.debug("Keeping multiple old value for %s", attr)
                writeMod(dn, attr, mod_list, filename) 
开发者ID:GluuFederation,项目名称:community-edition-setup,代码行数:42,代码来源:import24.py

示例13: restoreConfig

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def restoreConfig(ldifFolder, newLdif, ldifModFolder):
    ignoreList = ['objectClass', 'ou']
    current_config_dns = getDns(newLdif)
    oldDnMap = getOldEntryMap(ldifFolder)
    for dn in oldDnMap.keys():
        old_entry = getEntry("%s/%s" % (ldifFolder, oldDnMap[dn]), dn)
        if dn not in current_config_dns:
            addEntry(dn, old_entry, ldifModFolder)
            continue
        new_entry = getEntry(newLdif, dn)
        for attr in old_entry.keys():
            if attr in ignoreList:
                continue
            if not new_entry.has_key(attr):
                writeMod(dn, attr, old_entry[attr], '%s/%s.ldif' % (ldifModFolder, str(uuid.uuid4())), True)
                logIt("Adding attr %s to %s" % (attr, dn))
            else:
                mod_list = None
                if old_entry[attr] != new_entry[attr]:
                    if len(old_entry[attr]) == 1:
                        try:
                            logIt("Merging json value for %s " % attr)
                            old_json = json.loads(old_entry[attr][0])
                            new_json = json.loads(new_entry[attr][0])
                            new_json = merge(new_json, old_json)
                            mod_list = [json.dumps(new_json)]
                        except:
                            mod_list = old_entry[attr]
                    else:
                        mod_list = old_entry[attr]
                        logIt("Keeping multiple old values for %s" % attr)
                else:
                    continue
                writeMod(dn, attr, mod_list, '%s/%s.ldif' % (ldifModFolder, str(uuid.uuid4()))) 
开发者ID:GluuFederation,项目名称:community-edition-setup,代码行数:36,代码来源:import23.py

示例14: record_histogram

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def record_histogram(self, key, val, name=None):
        if str(key) not in self._histogram_ds:
            with tf.name_scope(name, "record_histogram"):
                self._histogram_ds[str(key)] = tf.Variable(val)
            self._histogram_summary_op.append(
                tf.summary.histogram(str(key), self._histogram_ds[str(key)]))
            self._histogram_summary_op_merge = tf.summary.merge(
                self._histogram_summary_op)

        self._feed[self._histogram_ds[str(key)]] = val 
开发者ID:rlworkgroup,项目名称:gym-sawyer,代码行数:12,代码来源:tensorboard_output.py

示例15: record_histogram_by_type

# 需要导入模块: import jsonmerge [as 别名]
# 或者: from jsonmerge import merge [as 别名]
def record_histogram_by_type(self,
                                 histogram_type,
                                 key=None,
                                 shape=[1000],
                                 name=None,
                                 **kwargs):
        '''
        distribution type and args:
            normal: mean, stddev
            gamma: alpha
            poisson: lam
            uniform: maxval

        example:
            $ python examples/example_tensorboard_logger.py
        '''
        if histogram_type not in self._histogram_distribute_list:
            raise Exception('histogram type error %s' % histogram_type,
                            'builtin type', self._histogram_distribute_list)

        if str(key) not in self._histogram_ds:
            self._histogram_ds[str(key)] = self._get_histogram_var_by_type(
                histogram_type, shape, name, **kwargs)
            self._histogram_summary_op.append(
                tf.summary.histogram(
                    str(key), self._histogram_ds[str(key)][0]))
            self._histogram_summary_op_merge = tf.summary.merge(
                self._histogram_summary_op)

        key_list = self._histogram_ds[str(key)][1]
        val_list = self._get_histogram_val_by_type(histogram_type, **kwargs)

        for key, val in zip(key_list, val_list):
            self._feed[key] = val 
开发者ID:rlworkgroup,项目名称:gym-sawyer,代码行数:36,代码来源:tensorboard_output.py


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