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