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


Python jsonutils.dump方法代码示例

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


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

示例1: print_table

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def print_table(table, format_):
    if table == db_common.UNIQUE_KEY_TABLE:
        keys = nb_api.driver.get_all_keys(table)
        values = [{'id': key} for key in keys]
        _print_list(['id'], values, format_)
        return
    model = _get_model_or_exit(table)
    instances = nb_api.get_all(model)

    if not instances:
        if format_ == FORMAT_PRETTY:
            print('Table is empty: ' + table)
        elif format_ == FORMAT_JSON:
            jsonutils.dump([], sys.stdout)
        return

    keys = [{'key': instance.id} for instance in instances]
    _print_list(['key'], keys, 'Keys for table', format_) 
开发者ID:openstack,项目名称:dragonflow,代码行数:20,代码来源:df_db.py

示例2: _write_dict

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def _write_dict(self, fout, dct):
        output = {'cniVersion': self.VERSION}
        output.update(dct)
        LOG.debug("CNI output: %s", output)
        jsonutils.dump(output, fout, sort_keys=True) 
开发者ID:openstack,项目名称:zun,代码行数:7,代码来源:api.py

示例3: _write_config

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def _write_config(self, container_id, ifname, port_name, vif):
        """Write vhostuser configuration file

        This function writes configuration file, this file will be used by
        application inside container and for cleanup (def disconnect)
        procedure.
        """
        vhost_conf = {}
        vhost_conf["vhostname"] = port_name
        vhost_conf["vhostmac"] = vif.address
        vhost_conf["mode"] = vif.mode
        with open(self._config_file_path(container_id, ifname), "w") as f:
            jsonutils.dump(vhost_conf, f) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:15,代码来源:vhostuser.py

示例4: dump

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def dump(self, obj, fp):
        return jsonutils.dump(obj, fp) 
开发者ID:openstack,项目名称:oslo.serialization,代码行数:4,代码来源:json_serializer.py

示例5: test_dump

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def test_dump(self):
        expected = '{"a": "b"}'
        json_dict = {'a': 'b'}

        fp = io.StringIO()
        jsonutils.dump(json_dict, fp)

        self.assertEqual(expected, fp.getvalue()) 
开发者ID:openstack,项目名称:oslo.serialization,代码行数:10,代码来源:test_jsonutils.py

示例6: test_dump_namedtuple

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def test_dump_namedtuple(self):
        expected = '[1, 2]'
        json_dict = collections.namedtuple("foo", "bar baz")(1, 2)

        fp = io.StringIO()
        jsonutils.dump(json_dict, fp)

        self.assertEqual(expected, fp.getvalue()) 
开发者ID:openstack,项目名称:oslo.serialization,代码行数:10,代码来源:test_jsonutils.py

示例7: _modify_policy_file

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def _modify_policy_file(self, rules):
        with open(self.policy_file, 'r+b') as policy_file:
            existing_policy = jsonutils.load(policy_file)

        existing_policy.update(rules)

        with open(self.policy_file, 'w') as policy_file:
            jsonutils.dump(existing_policy, policy_file)

        time.sleep(2) 
开发者ID:openstack,项目名称:searchlight,代码行数:12,代码来源:test_api.py

示例8: _write_policy_file

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def _write_policy_file(self, filename, rules):
        with open(os.path.join(self.conf_dir, filename), 'w') as pol_file:
            jsonutils.dump(rules, pol_file) 
开发者ID:openstack,项目名称:searchlight,代码行数:5,代码来源:test_api.py

示例9: emit

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def emit(self, record):
        try:
            msg = self.format(record)
            jsonutils.dump(msg, self.stream)
            self.stream.flush()
        except AttributeError:
            self.handleError(record) 
开发者ID:openstack,项目名称:oslo.log,代码行数:9,代码来源:test_log.py

示例10: _prepare_policy

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def _prepare_policy(self):
        self.policy_dir = self.useFixture(fixtures.TempDir())
        self.policy_file = os.path.join(self.policy_dir.path, 'policy.json')

        # load the fake_policy data and add the missing default rules.
        policy_rules = jsonutils.loads(fake_policy.policy_data)

        with open(self.policy_file, 'w') as f:
            jsonutils.dump(policy_rules, f)
        CONF.set_override('policy_dirs', [], group='oslo_policy') 
开发者ID:openstack,项目名称:masakari,代码行数:12,代码来源:policy_fixture.py

示例11: write_datapath_allocation

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def write_datapath_allocation(self):
        if not cfg.CONF.df.write_datapath_allocation:
            return
        dppath = cfg.CONF.df.datapath_allocation_output_path
        if (path.isfile(dppath) and
                not cfg.CONF.df.overwrite_datapath_allocation_output_path):
            LOG.warning("File %s exists, but cannot overwrite", dppath)
            return
        try:
            with open(dppath, 'w') as f:
                dp_allocs = self._get_dp_allocs_basic_dictionary()
                jsonutils.dump(dp_allocs, f)
        except IOError:
            LOG.exception("Cannot open file %s", dppath) 
开发者ID:openstack,项目名称:dragonflow,代码行数:16,代码来源:datapath.py

示例12: _print_dict

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def _print_dict(dct, format_):
    if format_ == FORMAT_PRETTY:
        cli_utils.print_dict(dct)
    elif format_ == FORMAT_JSON:
        jsonutils.dump(dct, sys.stdout) 
开发者ID:openstack,项目名称:dragonflow,代码行数:7,代码来源:df_db.py

示例13: _print_list_json

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def _print_list_json(columns, values):
    result = [{column: value[column]}
              for column in columns for value in values]
    jsonutils.dump(result, sys.stdout) 
开发者ID:openstack,项目名称:dragonflow,代码行数:6,代码来源:df_db.py

示例14: dump_tables

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def dump_tables(format_):
    if format_ == FORMAT_PRETTY:
        for table in db_tables:
            print_whole_table(table)
    elif format_ == FORMAT_JSON:
        result = {table: _get_table_struct(table) for table in db_tables}
        jsonutils.dump(result, sys.stdout) 
开发者ID:openstack,项目名称:dragonflow,代码行数:9,代码来源:df_db.py

示例15: output_end

# 需要导入模块: from oslo_serialization import jsonutils [as 别名]
# 或者: from oslo_serialization.jsonutils import dump [as 别名]
def output_end(self):
        jsonutils.dump(self._models_obj, self._output, indent=2) 
开发者ID:openstack,项目名称:dragonflow,代码行数:4,代码来源:df_model.py


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