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


Python toml.dumps方法代码示例

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


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

示例1: write_config

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def write_config(self) -> None:
        """Write leanpkg.toml for this project."""
        # Fix leanpkg lean_version bug if needed (the lean_version property
        # setter is working here, hence the weird line).
        self.lean_version = self.lean_version

        # Note we can't blindly use toml.dump because we need dict as values
        # for dependencies.
        with (self.directory/'leanpkg.toml').open('w') as cfg:
            cfg.write('[package]\n')
            cfg.write(toml.dumps(self.pkg_config))
            cfg.write('\n[dependencies]\n')
            for dep, val in self.deps.items():
                nval = str(val).replace("'git':", 'git =').replace(
                        "'rev':", 'rev =').replace("'", '"')
                cfg.write('{} = {}\n'.format(dep, nval)) 
开发者ID:leanprover-community,项目名称:mathlib-tools,代码行数:18,代码来源:lib.py

示例2: generate_toml

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def generate_toml(request):
    """Generate the TOML file."""
    toml_dict = {
        "ACCOUNTS": [
            asset.distribution_account
            for asset in Asset.objects.exclude(distribution_seed__isnull=True)
        ],
        "VERSION": "0.1.0",
        "SIGNING_KEY": settings.SIGNING_KEY,
        "NETWORK_PASSPHRASE": settings.STELLAR_NETWORK_PASSPHRASE,
    }

    if "sep-24" in django_settings.ACTIVE_SEPS:
        toml_dict["TRANSFER_SERVER"] = os.path.join(settings.HOST_URL, "sep24")
        toml_dict["TRANSFER_SERVER_SEP0024"] = toml_dict["TRANSFER_SERVER"]
    if "sep-6" in django_settings.ACTIVE_SEPS:
        toml_dict["TRANSFER_SERVER"] = os.path.join(settings.HOST_URL, "sep6")
    if "sep-10" in django_settings.ACTIVE_SEPS:
        toml_dict["WEB_AUTH_ENDPOINT"] = os.path.join(settings.HOST_URL, "auth")
    if "sep-12" in django_settings.ACTIVE_SEPS:
        toml_dict["KYC_SERVER"] = os.path.join(settings.HOST_URL, "kyc")

    toml_dict.update(registered_toml_func())

    return HttpResponse(toml.dumps(toml_dict), content_type="text/plain") 
开发者ID:stellar,项目名称:django-polaris,代码行数:27,代码来源:views.py

示例3: _show_profile

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def _show_profile(profile, defaults, nodefault):
    plogger.profile('>>> %s', profile)
    config._use(profile)
    confs = config.dict() if profile != 'default' else defaults
    conflines = toml.dumps(confs).splitlines()
    if nodefault:
        for line in conflines:
            plogger['=']('    %s', line)
    else:
        defaults = defaults.copy()
        defaults.update(confs)
        for line in toml.dumps(defaults).splitlines():
            if line in conflines or profile == 'default':
                plogger['=']('    %s' % line)
            else:
                plogger['-']('    %s' % line) 
开发者ID:pwwang,项目名称:PyPPL,代码行数:18,代码来源:profile.py

示例4: update_pipfile

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def update_pipfile(stdout: bool):
    import toml
    project = Project()
    LOGGER.debug(f"Processing {project.pipfile_location}")

    top_level_packages, top_level_dev_packages = get_top_level_dependencies()
    all_packages, all_dev_packages = get_all_packages()

    pipfile = toml.load(project.pipfile_location)
    configuration = [{'section': 'packages',
                      'top_level': top_level_packages,
                      'all_packages': all_packages},
                     {'section': 'dev-packages',
                      'top_level': top_level_dev_packages,
                      'all_packages': all_dev_packages}]
    for config in configuration:
        pipfile[config.get('section')] = {package.name: package.full_version
                                          for package in _get_packages(config.get('top_level'),
                                                                       config.get('all_packages'))}

    if stdout:
        LOGGER.debug(f"Outputting Pipfile on stdout")
        print(toml.dumps(pipfile))
    else:
        LOGGER.debug(f"Outputting Pipfile top {project.pipfile_location}")
        with open(project.pipfile_location, 'w') as writer:
            writer.write(toml.dumps(pipfile))

    return True 
开发者ID:costastf,项目名称:toonapilib,代码行数:31,代码来源:core_library.py

示例5: to_toml_string

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def to_toml_string(self):
        return str(toml.dumps(self.to_dict())).strip().split('\n') 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:4,代码来源:validator.py

示例6: _to_json

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def _to_json(obj, filename=None, encoding="utf-8", errors="strict", **json_kwargs):
    json_dump = json.dumps(obj, ensure_ascii=False, **json_kwargs)
    if filename:
        _exists(filename, create=True)
        with open(filename, 'w', encoding=encoding, errors=errors) as f:
            f.write(json_dump if sys.version_info >= (3, 0) else json_dump.decode("utf-8"))
    else:
        return json_dump 
开发者ID:cdgriffith,项目名称:Box,代码行数:10,代码来源:converters.py

示例7: _to_toml

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def _to_toml(obj, filename=None, encoding="utf-8", errors="strict"):
    if filename:
        _exists(filename, create=True)
        with open(filename, 'w', encoding=encoding, errors=errors) as f:
            toml.dump(obj, f)
    else:
        return toml.dumps(obj) 
开发者ID:cdgriffith,项目名称:Box,代码行数:9,代码来源:converters.py

示例8: test_box_list_from_json

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def test_box_list_from_json(self):
        alist = [{'item': 1}, {'CamelBad': 2}]
        json_list = json.dumps(alist)
        bl = BoxList.from_json(json_list, camel_killer_box=True)
        assert bl[0].item == 1
        assert bl[1].camel_bad == 2

        with pytest.raises(BoxError):
            BoxList.from_json(json.dumps({'a': 2})) 
开发者ID:cdgriffith,项目名称:Box,代码行数:11,代码来源:test_box_list.py

示例9: test_box_list_from_tml

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def test_box_list_from_tml(self):
        alist = [{'item': 1}, {'CamelBad': 2}]
        toml_list = toml.dumps({'key': alist})
        bl = BoxList.from_toml(toml_string=toml_list, key_name='key', camel_killer_box=True)
        assert bl[0].item == 1
        assert bl[1].camel_bad == 2

        with pytest.raises(BoxError):
            BoxList.from_toml(toml.dumps({'a': 2}), 'a')

        with pytest.raises(BoxError):
            BoxList.from_toml(toml_list, 'bad_key') 
开发者ID:cdgriffith,项目名称:Box,代码行数:14,代码来源:test_box_list.py

示例10: __str__

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def __str__(self):
        """Formats whitelist as string. Used to dump it to a file."""
        return toml.dumps(self.dump()).replace(',]\n', ' ]\n') 
开发者ID:flyingcircusio,项目名称:vulnix,代码行数:5,代码来源:whitelist.py

示例11: serialise

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def serialise(self, fields=("name", "summary"), recurse=True, format=None):
        if format == "pinned":
            # user-specified fields are ignored/invalid in this case
            fields = ("pinned",)
        data = [OrderedDict([(f, getattr(self, f, None)) for f in fields])]
        if format == "human":
            table = gen_table(self, extra_cols=fields)
            tabulate.PRESERVE_WHITESPACE = True
            return tabulate.tabulate(table, headers="keys")
        if recurse and self.requires:
            deps = flatten_deps(self)
            next(deps)  # skip over root
            data += [d for dep in deps for d in dep.serialise(fields=fields, recurse=False)]
        if format is None or format == "python":
            result = data
        elif format == "json":
            result = json.dumps(data, indent=2, default=str, separators=(",", ": "))
        elif format == "yaml":
            result = oyaml.dump(data)
        elif format == "toml":
            result = "\n".join([toml.dumps(d) for d in data])
        elif format == "pinned":
            result = "\n".join([d["pinned"] for d in data])
        else:
            raise Exception("Unsupported format")
        return result 
开发者ID:wimglenn,项目名称:johnnydep,代码行数:28,代码来源:lib.py

示例12: config_wizard

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def config_wizard():
    click.echo('''
You'll need to create a last.fm API application first. Do so here:

    http://www.last.fm/api/account/create

What you fill in doesn't matter at all, just make sure to save the API
Key and Shared Secret.
''')

    plex_scrobble = {
        'mediaserver_url': 'http://localhost:32400',
        'log_file': '/tmp/plex-scrobble.log',
        'cache_location': '/tmp/plex_scrobble.cache',
        'mediaserver_log_location': platform_log_directory()
    }

    config = {
        'lastfm': {
            key: click.prompt(key, type=str)
            for key in ['user_name', 'password', 'api_key', 'api_secret']
        }
    }

    config['plex-scrobble'] = {
        key: click.prompt(key, default=plex_scrobble[key])
        for key in plex_scrobble
    }

    generated = toml.dumps(config)
    click.echo('Generated config:\n\n%s' % generated)

    if click.confirm('Write to ~/.plex-scrobble.toml?'):
        with open(os.path.expanduser('~/.plex-scrobble.toml'), 'w') as fp:
            fp.write(generated) 
开发者ID:jesseward,项目名称:plex-lastfm-scrobbler,代码行数:37,代码来源:__main__.py

示例13: update_pipfile

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def update_pipfile(stdout: bool):
    import toml
    project = Project()
    LOGGER.debug(f"Processing {project.pipfile_location}")

    top_level_packages, top_level_dev_packages = get_top_level_dependencies()
    all_packages, all_dev_packages = get_all_packages()

    pipfile = toml.load(project.pipfile_location)
    configuration = [{'section': 'packages',
                      'top_level': top_level_packages,
                      'all_packages': all_packages},
                     {'section': 'dev-packages',
                      'top_level': top_level_dev_packages,
                      'all_packages': all_dev_packages}]
    for config in configuration:
        pipfile[config.get('section')] = {package.name: package.full_version
                                          for package in _get_packages(config.get('top_level'),
                                                                       config.get('all_packages'))}

    if stdout:
        LOGGER.debug(f'Outputting Pipfile on stdout')
        print(toml.dumps(pipfile))
    else:
        LOGGER.debug(f'Outputting Pipfile top {project.pipfile_location}')
        with open(project.pipfile_location, 'w') as writer:
            writer.write(toml.dumps(pipfile))

    return True 
开发者ID:schubergphilis,项目名称:towerlib,代码行数:31,代码来源:core_library.py

示例14: export

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def export(self, metadata, **kwargs):
        "Turn metadata into JSON"
        kwargs.setdefault("indent", 4)
        metadata = json.dumps(metadata, **kwargs)
        return u(metadata) 
开发者ID:eyeseast,项目名称:python-frontmatter,代码行数:7,代码来源:default_handlers.py

示例15: dumps

# 需要导入模块: import toml [as 别名]
# 或者: from toml import dumps [as 别名]
def dumps():
    """Format config into toml."""
    from toml import dumps

    return dumps(get()) 
开发者ID:poldracklab,项目名称:mriqc,代码行数:7,代码来源:config.py


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