本文整理汇总了Python中typing.TextIO.seek方法的典型用法代码示例。如果您正苦于以下问题:Python TextIO.seek方法的具体用法?Python TextIO.seek怎么用?Python TextIO.seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typing.TextIO
的用法示例。
在下文中一共展示了TextIO.seek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump_conditions
# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import seek [as 别名]
def dump_conditions(file: TextIO) -> None:
"""Dump docs for all the condition flags, results and metaconditions."""
LOGGER.info('Dumping conditions...')
# Delete existing data, after the marker.
file.seek(0, io.SEEK_SET)
prelude = []
for line in file:
if DOC_MARKER in line:
break
prelude.append(line)
file.seek(0, io.SEEK_SET)
file.truncate(0)
if not prelude:
# No marker, blank the whole thing.
LOGGER.warning('No intro text before marker!')
for line in prelude:
file.write(line)
file.write(DOC_MARKER + '\n\n')
file.write(DOC_META_COND)
ALL_META.sort(key=lambda i: i[1]) # Sort by priority
for flag_key, priority, func in ALL_META:
file.write('#### `{}` ({}):\n\n'.format(flag_key, priority))
dump_func_docs(file, func)
file.write('\n')
for lookup, name in [
(ALL_FLAGS, 'Flags'),
(ALL_RESULTS, 'Results'),
]:
print('<!------->', file=file)
print('# ' + name, file=file)
print('<!------->', file=file)
lookup_grouped = defaultdict(list) # type: Dict[str, List[Tuple[str, Tuple[str, ...], Callable]]]
for flag_key, aliases, func in lookup:
group = getattr(func, 'group', 'ERROR')
if group is None:
group = '00special'
lookup_grouped[group].append((flag_key, aliases, func))
# Collapse 1-large groups into Ungrouped.
for group in list(lookup_grouped):
if len(lookup_grouped[group]) < 2:
lookup_grouped[''].extend(lookup_grouped[group])
del lookup_grouped[group]
if not lookup_grouped['']:
del lookup_grouped['']
for header_ind, (group, funcs) in enumerate(sorted(lookup_grouped.items())):
if group == '':
group = 'Ungrouped Conditions'
if header_ind:
# Not before the first one...
print('---------\n', file=file)
if group == '00special':
print(DOC_SPECIAL_GROUP, file=file)
else:
print('### ' + group + '\n', file=file)
LOGGER.info('Doing {} group...', group)
for flag_key, aliases, func in funcs:
print('#### `{}`:\n'.format(flag_key), file=file)
if aliases:
print('**Aliases:** `' + '`, `'.join(aliases) + '`' + ' \n', file=file)
dump_func_docs(file, func)
file.write('\n')