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