本文整理汇总了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)
示例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()
示例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
)
示例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
示例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())
示例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