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