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


Python toml.TomlDecodeError方法代码示例

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


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

示例1: load

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def load(cls, fobj):
        """Loads whitelist from file-like object.

        The format (TOML or YAML) is guessed using a heuristic.
        """
        content = fobj.read()
        if isinstance(content, bytes):
            content = content.decode('utf-8')
        filename = ''
        if hasattr(fobj, 'name') and fobj.name:
            filename = fobj.name
        elif hasattr(fobj, 'geturl'):
            filename = fobj.geturl()
        try:
            return cls._parse_cfg(content, filename)
        except (toml.TomlDecodeError, IndexError) as e:
            raise RuntimeError('failed to load `{}`: {}'.format(filename, e)) 
开发者ID:flyingcircusio,项目名称:vulnix,代码行数:19,代码来源:whitelist.py

示例2: write_version_to_pyproject

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def write_version_to_pyproject(version: Version) -> None:
    """Dump a new version into the pyproject.toml."""

    import toml

    pyproject_file = pyproject_file_path()

    try:
        data = toml.load(pyproject_file)
        data["tool"]["poetry"]["version"] = str(version)
        with pyproject_file.open("w") as f:
            toml.dump(data, f)
    except (FileNotFoundError, TypeError):
        print(f"Unable to update {pyproject_file}: file not found.")
        sys.exit(1)
    except toml.TomlDecodeError:
        print(f"Unable to parse {pyproject_file}: incorrect TOML file.")
        sys.exit(1)

    check_call(["git", "add", str(pyproject_file.absolute())]) 
开发者ID:RasaHQ,项目名称:rasa-sdk,代码行数:22,代码来源:release.py

示例3: write_version_to_pyproject

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def write_version_to_pyproject(version: Version) -> None:
    """Dump a new version into the pyproject.toml."""
    pyproject_file = pyproject_file_path()

    try:
        data = toml.load(pyproject_file)
        data["tool"]["poetry"]["version"] = str(version)
        with pyproject_file.open("w", encoding="utf8") as f:
            toml.dump(data, f)
    except (FileNotFoundError, TypeError):
        print(f"Unable to update {pyproject_file}: file not found.")
        sys.exit(1)
    except toml.TomlDecodeError:
        print(f"Unable to parse {pyproject_file}: incorrect TOML file.")
        sys.exit(1)

    check_call(["git", "add", str(pyproject_file.absolute())]) 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:19,代码来源:release.py

示例4: read_config_toml

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def read_config_toml(project_root: Path, config_file: str) -> Config:
    path = project_root / config_file
    if not path.is_file():
        return {}

    try:
        pyproject_toml = toml.load(str(path))
        config = pyproject_toml.get("tool", {}).get("ward", {})
    except (toml.TomlDecodeError, OSError) as e:
        raise click.FileError(
            filename=config_file, hint=f"Error reading {config_file}:\n{e}"
        )

    if not config:
        return {}

    config = {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}
    return config 
开发者ID:darrenburns,项目名称:ward,代码行数:20,代码来源:config.py

示例5: parse

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def parse(cls, f):
        entry_map = {}
        for entry in ENTRIES:
            entry_map[entry.name] = entry.copy()

        try:
            loaded = toml.load(f)

            for k, v in loaded.items():
                if entry.type_ in data_constructors:
                    v = data_constructors[entry.type_](k, v)
                if k not in entry_map:
                    _l.warning('Unknown configuration option \'%s\'. Ignoring...', k)
                    continue
                entry = entry_map[k]
                if type(v) is not entry.type_:
                    _l.warning('Value \'%s\' for configuration option \'%s\' has type \'%s\', expected type \'%s\'. Ignoring...',
                             v, k, type(v), entry.type_)
                    continue
                entry.value = v
        except toml.TomlDecodeError as e:
            _l.error('Failed to parse configuration file: \'%s\'. Continuing with default options...', e.msg)

        return cls(entry_map) 
开发者ID:angr,项目名称:angr-management,代码行数:26,代码来源:config_manager.py

示例6: check

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def check(source_dir):
    pyproject = pjoin(source_dir, 'pyproject.toml')
    if isfile(pyproject):
        log.info('Found pyproject.toml')
    else:
        log.error('Missing pyproject.toml')
        return False

    try:
        with open(pyproject) as f:
            pyproject_data = toml_load(f)
        # Ensure the mandatory data can be loaded
        buildsys = pyproject_data['build-system']
        requires = buildsys['requires']
        backend = buildsys['build-backend']
        backend_path = buildsys.get('backend-path')
        log.info('Loaded pyproject.toml')
    except (TomlDecodeError, KeyError):
        log.error("Invalid pyproject.toml", exc_info=True)
        return False

    hooks = Pep517HookCaller(source_dir, backend, backend_path)

    sdist_ok = check_build_sdist(hooks, requires)
    wheel_ok = check_build_wheel(hooks, requires)

    if not sdist_ok:
        log.warning('Sdist checks failed; scroll up to see')
    if not wheel_ok:
        log.warning('Wheel checks failed')

    return sdist_ok 
开发者ID:pypa,项目名称:pep517,代码行数:34,代码来源:check.py

示例7: _config_from_pyproject

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def _config_from_pyproject(path):
    if not os.path.isfile(path):
        return {}

    try:
        pyproject = toml.load(path)
        return pyproject.get("tool", {}).get("semantic_release", {})

    except toml.TomlDecodeError:
        logger.debug("Could not decode pyproject.toml")
        return {} 
开发者ID:relekang,项目名称:python-semantic-release,代码行数:13,代码来源:settings.py

示例8: parse

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def parse(self):
        """
        Parse a Pipfile (as seen in pipenv)
        :return:
        """
        try:
            data = toml.loads(self.obj.content, _dict=OrderedDict)
            if data:
                for package_type in ['packages', 'dev-packages']:
                    if package_type in data:
                        for name, specs in data[package_type].items():
                            # skip on VCS dependencies
                            if not isinstance(specs, str):
                                continue
                            if specs == '*':
                                specs = ''
                            self.obj.dependencies.append(
                                Dependency(
                                    name=name, specs=SpecifierSet(specs),
                                    dependency_type=filetypes.pipfile,
                                    line=''.join([name, specs]),
                                    section=package_type
                                )
                            )
        except (toml.TomlDecodeError, IndexError) as e:
            pass 
开发者ID:pypa,项目名称:pipenv,代码行数:28,代码来源:parser.py

示例9: _to_toml

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def _to_toml(data):
    try:
        return Box.from_toml(data)
    except TomlDecodeError:
        raise BoxError('File is not TOML as expected') 
开发者ID:cdgriffith,项目名称:Box,代码行数:7,代码来源:from_file.py

示例10: main

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument('filenames', nargs='*', help='Filenames to check.')
    args = parser.parse_args(argv)

    retval = 0
    for filename in args.filenames:
        try:
            toml.load(filename)
        except toml.TomlDecodeError as exc:
            print(f'{filename}: {exc}')
            retval = 1
    return retval 
开发者ID:pre-commit,项目名称:pre-commit-hooks,代码行数:15,代码来源:check_toml.py

示例11: __load_toml_file

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def __load_toml_file(file_path: Union[str, Path]) -> MutableMapping[str, Any]:
        try:
            if isinstance(file_path, str):
                file_path = Path(file_path).resolve()

            return toml.load(file_path)
        except FileNotFoundError:
            raise MissingPyProjectFileError()
        except toml.TomlDecodeError:
            raise MalformedPyProjectError() 
开发者ID:illBeRoy,项目名称:taskipy,代码行数:12,代码来源:pyproject.py

示例12: read_pyproject_toml

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def read_pyproject_toml(
    ctx: click.Context, _param: click.Parameter, value: str
) -> Optional[str]:
    if not value:
        root_path = ctx.params.get("repo_path", None)
        if not root_path:
            root_path = "."
        root_path = pathlib.Path(root_path).resolve()
        config_path = root_path / "pyproject.toml"
        if config_path.is_file():
            value = str(config_path)
        else:
            config_path = root_path / "tartufo.toml"
            if config_path.is_file():
                value = str(config_path)
            else:
                return None
    try:
        toml_file = toml.load(value)
        config = toml_file.get("tool", {}).get("tartufo", {})
    except (toml.TomlDecodeError, OSError) as exc:
        raise click.FileError(
            filename=str(config_path),
            hint="Error reading configuration file: {}".format(exc),
        )
    if not config:
        return None
    if ctx.default_map is None:
        ctx.default_map = {}
    ctx.default_map.update(  # type: ignore
        {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}
    )
    return str(value) 
开发者ID:godaddy,项目名称:tartufo,代码行数:35,代码来源:config.py

示例13: load_config

# 需要导入模块: import toml [as 别名]
# 或者: from toml import TomlDecodeError [as 别名]
def load_config(filename: str) -> Dict:
    defaults = {
        "line_length": 88,
        "fast": False,
        "pyi": filename.endswith(".pyi"),
        "skip_string_normalization": False,
        "target_version": set(),
    }

    root = black.find_project_root((filename,))

    pyproject_filename = root / "pyproject.toml"

    if not pyproject_filename.is_file():
        return defaults

    try:
        pyproject_toml = toml.load(str(pyproject_filename))
    except (toml.TomlDecodeError, OSError):
        return defaults

    file_config = pyproject_toml.get("tool", {}).get("black", {})
    file_config = {
        key.replace("--", "").replace("-", "_"): value
        for key, value in file_config.items()
    }

    config = {
        key: file_config.get(key, default_value)
        for key, default_value in defaults.items()
    }

    if file_config.get("target_version"):
        target_version = set(
            black.TargetVersion[x.upper()] for x in file_config["target_version"]
        )
    elif file_config.get("py36"):
        target_version = black.PY36_VERSIONS
    else:
        target_version = set()

    config["target_version"] = target_version

    return config 
开发者ID:rupert,项目名称:pyls-black,代码行数:46,代码来源:plugin.py


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