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


Python TextIO.read方法代码示例

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


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

示例1: load

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import read [as 别名]
    def load(self, *, config_fd: TextIO = None) -> None:
        config = ""
        if config_fd:
            config = config_fd.read()
        else:
            # Local configurations (per project) are supposed to be static.
            # That's why it's only checked for 'loading' and never written to.
            # Essentially, all authentication-related changes, like
            # login/logout or macaroon-refresh, will not be persisted for the
            # next runs.
            file_path = ""
            if os.path.exists(LOCAL_CONFIG_FILENAME):
                file_path = LOCAL_CONFIG_FILENAME

                # FIXME: We don't know this for sure when loading the config.
                # Need a better separation of concerns.
                logger.warn(
                    "Using local configuration ({!r}), changes will not be "
                    "persisted.".format(file_path)
                )
            else:
                file_path = BaseDirectory.load_first_config(
                    "snapcraft", "snapcraft.cfg"
                )
            if file_path and os.path.exists(file_path):
                with open(file_path, "r") as f:
                    config = f.read()

        if config:
            _load_potentially_base64_config(self.parser, config)
开发者ID:mvo5,项目名称:snapcraft,代码行数:32,代码来源:config.py

示例2: _prepare_graph_struct

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import read [as 别名]
def _prepare_graph_struct(name: Optional[str], graph: TextIO, hosts: List[str], graph_format: str) -> dict:
    if graph_format == 'raw':
        return json.load(graph)
    assert name and hosts, 'Only raw graph format can not set hosts and name'
    result = GraphStruct()
    result.graph_name = name
    result.clusters.from_json({'I': hosts})
    if graph_format == 'script':
        task = ExtendedTaskStruct()
        task.task_name = 'main'
        task.hosts.append('I')
        task.task_struct.executor.name = 'shell'
        executor_cfg = ShellExecutorConfig()
        executor_cfg.shell_script = graph.read()
        task.task_struct.executor.config = executor_cfg.to_json()
        result.tasks.from_json([task.to_json()])
    elif graph_format == 'makefile':
        raise NotImplementedError()
    return result.to_json()
开发者ID:LuckyGeck,项目名称:dedalus,代码行数:21,代码来源:app.py

示例3: map_input

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import read [as 别名]
    def map_input(self, data: typing.TextIO) -> libioc.Config.Data.Data:
        """Parse and normalize JSON data."""
        try:
            content = data.read().strip()
        except (FileNotFoundError, PermissionError) as e:
            raise libioc.errors.JailConfigError(
                message=str(e),
                logger=self.logger
            )

        if content == "":
            return libioc.Config.Data.Data()

        try:
            result = json.loads(content)  # type: typing.Dict[str, typing.Any]
            return libioc.Config.Data.Data(result)
        except json.decoder.JSONDecodeError as e:
            raise libioc.errors.JailConfigError(
                message=str(e),
                logger=self.logger
            )
开发者ID:iocage,项目名称:libiocage,代码行数:23,代码来源:JSON.py

示例4: lex

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import read [as 别名]
def lex(input: TextIO) -> Iterator[Command]:
    whitespace = re.compile('\s+')

    parsing_item    = False
    parsing_command = False
    command, args   = '', []
    while True:
        char = input.read(1)
        if char is '':
            break
        if whitespace.match(char):
            if parsing_item:
                if parsing_command:
                    args.append('')
                else:
                    command += char
            parsing_item = False
        elif char == '(':
            if parsing_command:
                raise RuntimeError('Nested command')
            args.append('')
            parsing_command = True
            parsing_item    = False
        elif char == ')':
            if not parsing_command:
                raise RuntimeError('Unexpected ")"')
            if args[-1] == '':
                args = args[:-1]
            yield command, args
            command, args   = '', []
            parsing_item    = False
            parsing_command = False
        else:
            if parsing_command:
                args[-1] += char
            else:
                command += char
            parsing_item = True
开发者ID:cppguru,项目名称:bdemeta,代码行数:40,代码来源:cmake_parser.py

示例5: _read_file_handle

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import read [as 别名]
 def _read_file_handle(self, f: typing.TextIO) -> None:
     self.parse_lines(f.read())
开发者ID:iocage,项目名称:libiocage,代码行数:4,代码来源:Fstab.py

示例6: map_input

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import read [as 别名]
 def map_input(self, data: typing.TextIO) -> typing.Dict[str, typing.Any]:
     """Normalize data read from the UCL file."""
     import ucl
     result = ucl.load(data.read())  # type: typing.Dict[str, typing.Any]
     result["legacy"] = True
     return result
开发者ID:iocage,项目名称:libiocage,代码行数:8,代码来源:UCL.py


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