本文整理汇总了Python中exactly_lib.util.textformat.textformat_parser.TextParser.format方法的典型用法代码示例。如果您正苦于以下问题:Python TextParser.format方法的具体用法?Python TextParser.format怎么用?Python TextParser.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exactly_lib.util.textformat.textformat_parser.TextParser
的用法示例。
在下文中一共展示了TextParser.format方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IndividualActorConstructor
# 需要导入模块: from exactly_lib.util.textformat.textformat_parser import TextParser [as 别名]
# 或者: from exactly_lib.util.textformat.textformat_parser.TextParser import format [as 别名]
class IndividualActorConstructor(ArticleContentsConstructor):
def __init__(self, actor: ActorDocumentation):
self.actor = actor
self.rendering_environment = None
format_map = {
'actor_concept': formatting.concept_(concepts.ACTOR_CONCEPT_INFO),
'act_phase': phase_names.ACT.emphasis,
}
self._parser = TextParser(format_map)
def apply(self, environment: ConstructionEnvironment) -> doc.ArticleContents:
self.rendering_environment = environment
initial_paragraphs = self._default_reporter_info()
initial_paragraphs.extend(self.actor.main_description_rest())
sub_sections = []
append_sections_if_contents_is_non_empty(
sub_sections,
[(self._parser.format('{act_phase} phase contents'), self.actor.act_phase_contents()),
(self._parser.format('Syntax of {act_phase} phase contents'), self.actor.act_phase_contents_syntax())])
sub_sections += see_also_sections(self.actor.see_also_targets(), environment)
return doc.ArticleContents(docs.paras(self.actor.single_line_description()),
doc.SectionContents(initial_paragraphs,
sub_sections))
def _default_reporter_info(self) -> List[ParagraphItem]:
from exactly_lib.definitions.entity.actors import DEFAULT_ACTOR
if self.actor.singular_name() == DEFAULT_ACTOR.singular_name:
return self._parser.fnap('This is the default {actor_concept}.')
else:
return []
示例2: _TypeConcept
# 需要导入模块: from exactly_lib.util.textformat.textformat_parser import TextParser [as 别名]
# 或者: from exactly_lib.util.textformat.textformat_parser.TextParser import format [as 别名]
class _TypeConcept(ConceptDocumentation):
def __init__(self):
super().__init__(concepts.TYPE_CONCEPT_INFO)
self._parser = TextParser({
'program_name': formatting.program_name(program_info.PROGRAM_NAME),
'data': type_system.DATA_TYPE_CATEGORY_NAME,
'logic': type_system.LOGIC_TYPE_CATEGORY_NAME,
})
def purpose(self) -> DescriptionWithSubSections:
rest_paragraphs = self._parser.fnap(_REST_DESCRIPTION_1)
rest_paragraphs += [
_categories_list(self._list_header('{data} types'),
self._list_header('{logic} types'))
]
rest_paragraphs += self._parser.fnap(_REST_DESCRIPTION_2)
sub_sections = []
return DescriptionWithSubSections(self.single_line_description(),
SectionContents(rest_paragraphs,
sub_sections))
def _list_header(self, template_string: str) -> str:
return self._parser.format(template_string).capitalize()
def see_also_targets(self) -> List[SeeAlsoTarget]:
return list(map(lambda type_doc: type_doc.cross_reference_target(),
all_types.all_types()))
示例3: __init__
# 需要导入模块: from exactly_lib.util.textformat.textformat_parser import TextParser [as 别名]
# 或者: from exactly_lib.util.textformat.textformat_parser.TextParser import format [as 别名]
class EnvironmentVariableDescription:
def __init__(self):
self.text_parser = TextParser({
'program_name': formatting.program_name(program_info.PROGRAM_NAME),
'case_home_directory': formatting.conf_param_(conf_params.HOME_CASE_DIRECTORY_CONF_PARAM_INFO),
'act_home_directory': formatting.concept_(conf_params.HOME_ACT_DIRECTORY_CONF_PARAM_INFO),
'act_sub_dir': sds.SUB_DIRECTORY__ACT,
'tmp_sub_dir': sds.PATH__TMP_USER,
'result_sub_dir': sds.SUB_DIRECTORY__RESULT,
'sandbox': concepts.SANDBOX_CONCEPT_INFO.name,
'conf_param': concepts.CONFIGURATION_PARAMETER_CONCEPT_INFO.name,
}
)
self.all_variables_dict = dict(ENVIRONMENT_VARIABLES_SET_BEFORE_ACT + ENVIRONMENT_VARIABLES_SET_AFTER_ACT)
def as_single_line_description_str(self, environment_variable_name: str) -> str:
return self.text_parser.format(self.all_variables_dict[environment_variable_name])
def as_description_paragraphs(self, environment_variable_name: str) -> list:
return self.text_parser.paragraph_items(self.all_variables_dict[environment_variable_name])
示例4: _HdsConcept
# 需要导入模块: from exactly_lib.util.textformat.textformat_parser import TextParser [as 别名]
# 或者: from exactly_lib.util.textformat.textformat_parser.TextParser import format [as 别名]
class _HdsConcept(ConceptDocumentation):
def __init__(self):
super().__init__(concepts.HOME_DIRECTORY_STRUCTURE_CONCEPT_INFO)
self._tp = TextParser({
'HDS': formatting.concept_(concepts.HOME_DIRECTORY_STRUCTURE_CONCEPT_INFO),
'phase': phase_names.PHASE_NAME_DICTIONARY,
'program_name': formatting.program_name(program_info.PROGRAM_NAME),
'symbol': formatting.concept_(concepts.SYMBOL_CONCEPT_INFO),
'symbols': formatting.concept(concepts.SYMBOL_CONCEPT_INFO.plural_name),
'conf_params': formatting.concept(concepts.CONFIGURATION_PARAMETER_CONCEPT_INFO.plural_name),
'PATH': syntax_elements.PATH_SYNTAX_ELEMENT.singular_name,
})
def purpose(self) -> DescriptionWithSubSections:
rest_paragraphs = []
rest_paragraphs += self._tp.fnap(_MAIN_DESCRIPTION_REST)
rest_paragraphs += self._directory_listing()
sub_sections = [
self._section(concepts.CONFIGURATION_PARAMETER_CONCEPT_INFO.singular_name.capitalize(),
_CONFIGURATION_PARAMETER),
self._section('Relative paths',
_RELATIVITY),
self._section(self._tp.format('Builtin {symbols} and environment variables'),
_BUILTIN_SYMBOL_ENVIRONMENT_VARIABLE),
]
return DescriptionWithSubSections(self.single_line_description(),
SectionContents(rest_paragraphs, sub_sections))
def _section(self, header: str, text_to_format: str) -> docs.Section:
return docs.section(header,
self._tp.fnap(text_to_format))
def see_also_targets(self) -> List[SeeAlsoTarget]:
ret_val = [
concepts.TEST_CASE_DIRECTORY_STRUCTURE_CONCEPT_INFO.cross_reference_target,
concepts.CONFIGURATION_PARAMETER_CONCEPT_INFO.cross_reference_target,
types.PATH_TYPE_INFO.cross_reference_target,
]
ret_val += [
dir_info.conf_param.cross_reference_target
for dir_info in _ALL_DIRECTORIES
]
ret_val += [
phase_infos.CONFIGURATION.instruction_cross_reference_target(dir_info.instruction_name)
for dir_info in _ALL_DIRECTORIES
]
return ret_val
def _directory_listing(self) -> List[docs.ParagraphItem]:
items = [
self._dir_item(d)
for d in _ALL_DIRECTORIES
]
return [
docs.simple_list(items, lists.ListType.VARIABLE_LIST)
]
def _dir_item(self, x: _DirInfo) -> HeaderContentListItem:
def prop_row(header: str, value_str_or_text) -> List[docs.TableCell]:
return [docs.text_cell(header),
docs.text_cell(value_str_or_text),
]
from exactly_lib.test_case_file_structure.relative_path_options import REL_HOME_OPTIONS_MAP
properties_table = docs.first_column_is_header_table(
[
prop_row('Default value',
x.default_value_description),
prop_row(concepts.CONFIGURATION_PARAMETER_CONCEPT_INFO.singular_name.capitalize(),
x.conf_param.configuration_parameter_name_text),
prop_row('Set by instruction',
instruction_name_text(x.instruction_name)),
prop_row('Variable name',
REL_HOME_OPTIONS_MAP[x.relativity_option_type].directory_variable_name_text),
prop_row('Relativity option',
REL_HOME_OPTIONS_MAP[x.relativity_option_type].option_name_text),
]
)
paras = [
docs.para(x.conf_param.single_line_description_str),
properties_table,
]
return docs.list_item(self._tp.text(x.item_name), paras)
示例5: _SandboxConcept
# 需要导入模块: from exactly_lib.util.textformat.textformat_parser import TextParser [as 别名]
# 或者: from exactly_lib.util.textformat.textformat_parser.TextParser import format [as 别名]
class _SandboxConcept(ConceptDocumentation):
def __init__(self):
super().__init__(concepts.SANDBOX_CONCEPT_INFO)
self._tp = TextParser({
'program_name': formatting.program_name(program_info.PROGRAM_NAME),
'phase': phase_names.PHASE_NAME_DICTIONARY,
'instruction': AnyInstructionNameDictionary(),
'cwd': formatting.concept_(concepts.CURRENT_WORKING_DIRECTORY_CONCEPT_INFO),
'cd_instruction': InstructionName(CHANGE_DIR_INSTRUCTION_NAME),
'keep_sandbox_option': formatting.cli_option(command_line_options.OPTION_FOR_KEEPING_SANDBOX_DIRECTORY),
})
def purpose(self) -> DescriptionWithSubSections:
rest_paragraphs = []
sub_sections = []
rest_paragraphs += self._tp.fnap(_SANDBOX_PRE_DIRECTORY_TREE)
sub_sections.append(directory_structure_list_section(sds.execution_directories))
sub_sections += self._sandbox_directories_info_sections()
return DescriptionWithSubSections(self.single_line_description(),
SectionContents(rest_paragraphs, sub_sections))
def see_also_targets(self) -> List[SeeAlsoTarget]:
return [
concepts.TEST_CASE_DIRECTORY_STRUCTURE_CONCEPT_INFO.cross_reference_target,
concepts.CURRENT_WORKING_DIRECTORY_CONCEPT_INFO.cross_reference_target,
concepts.ENVIRONMENT_VARIABLE_CONCEPT_INFO.cross_reference_target,
types.PATH_TYPE_INFO.cross_reference_target,
phase_infos.SETUP.instruction_cross_reference_target(CHANGE_DIR_INSTRUCTION_NAME),
PredefinedHelpContentsPartReference(HelpPredefinedContentsPart.TEST_CASE_CLI),
SeeAlsoUrlInfo('Platform dependent location of sandbox',
'https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir')
]
def _sandbox_directories_info_sections(self) -> List[docs.SectionItem]:
def section(directory_name: str,
dir_info: tcds.TcDirInfo,
paragraph_items: List[ParagraphItem]) -> Section:
return docs.section(dir_name_text(directory_name),
docs.paras(dir_info.single_line_description_str + '.') +
paragraph_items)
return [
section(sds.SUB_DIRECTORY__ACT,
tcds.SDS_ACT_INFO,
self._act_dir_description_paragraphs()),
section(sds.SUB_DIRECTORY__RESULT,
tcds.SDS_RESULT_INFO,
self._result_dir_description_paragraphs()),
section(sds.PATH__TMP_USER,
tcds.SDS_TMP_INFO,
self._tmp_user_dir_description_paragraphs()),
docs.section(dir_name_text(sds.SUB_DIRECTORY__INTERNAL),
self._internal_dir_description_paragraphs())
]
def _act_dir_description_paragraphs(self) -> List[ParagraphItem]:
rel_opt_info = REL_SDS_OPTIONS_MAP[RelSdsOptionType.REL_ACT]
ret_val = []
ret_val += self._tp.fnap(_ACT_DIR_DESCRIPTION)
ret_val += _dir_env_variables_and_rel_options(env_var_name=rel_opt_info.directory_variable_name_text,
rel_option=rel_opt_info.option_name_text)
return ret_val
def _result_dir_description_paragraphs(self) -> List[ParagraphItem]:
ret_val = []
ret_val += self._tp.fnap(_RESULT_DIR_DESCRIPTION)
ret_val.append(docs.simple_header_only_list(map(file_name_text, sds.RESULT_FILE_ALL),
lists.ListType.ITEMIZED_LIST))
ret_val += self._result_dir_env_variable_and_rel_option()
return ret_val
def _tmp_user_dir_description_paragraphs(self) -> List[ParagraphItem]:
rel_opt_info = REL_SDS_OPTIONS_MAP[RelSdsOptionType.REL_TMP]
ret_val = []
ret_val += self._tp.fnap(_USR_TMP_DIR_DESCRIPTION)
ret_val += _dir_env_variables_and_rel_options(env_var_name=rel_opt_info.directory_variable_name_text,
rel_option=rel_opt_info.option_name_text)
return ret_val
def _result_dir_env_variable_and_rel_option(self) -> List[ParagraphItem]:
rel_opt_info = REL_SDS_OPTIONS_MAP[RelSdsOptionType.REL_RESULT]
return [_dir_info_items_table(rel_opt_info.directory_variable_name_text,
rel_opt_info.option_name_text,
self._tp.format(_RESULT_DIR_ENV_VARIABLE))
]
def _internal_dir_description_paragraphs(self) -> List[ParagraphItem]:
return self._tp.fnap(_INTERNAL_DIRECTORIES)
示例6: _Documentation
# 需要导入模块: from exactly_lib.util.textformat.textformat_parser import TextParser [as 别名]
# 或者: from exactly_lib.util.textformat.textformat_parser.TextParser import format [as 别名]
class _Documentation(SyntaxElementDocumentation):
def __init__(self):
super().__init__(TypeCategory.DATA,
syntax_elements.STRING_SYNTAX_ELEMENT)
self._tp = TextParser({
'string_type': formatting.keyword(types.STRING_TYPE_INFO.name.singular),
'list_type': formatting.keyword(types.LIST_TYPE_INFO.name.singular),
'path_type': formatting.keyword(types.PATH_TYPE_INFO.name.singular),
'symbol': formatting.concept_(concepts.SYMBOL_CONCEPT_INFO),
'CHR': 'CHARACTER',
'SOFT_Q': token.SOFT_QUOTE_CHAR,
'HARD_Q': token.HARD_QUOTE_CHAR,
'soft_quotes': formatting.concept(token.SOFT_QUOTE_NAME.plural),
'hard_quotes': formatting.concept(token.HARD_QUOTE_NAME.plural),
'SYMBOL_REFERENCE_SYNTAX_ELEMENT': syntax_elements.SYMBOL_REFERENCE_SYNTAX_ELEMENT.singular_name,
'REL_CD_OPTION': file_ref.REL_CWD_OPTION,
})
def invokation_variants(self) -> List[InvokationVariant]:
return [
InvokationVariant(self._tp.format('{CHR}...'),
self._tp.fnap(_DESCRIPTION_OF_NAKED)),
InvokationVariant(self._tp.format('{SOFT_Q}{CHR}...{SOFT_Q}'),
self._tp.fnap(_DESCRIPTION_OF_SOFT_Q)),
InvokationVariant(self._tp.format('{HARD_Q}{CHR}...{HARD_Q}'),
self._tp.fnap(_DESCRIPTION_OF_HARD_Q)),
]
def syntax_element_descriptions(self) -> list:
return [
self._symbol_reference_sed(),
]
def main_description_rest_paragraphs(self) -> list:
return []
def see_also_targets(self) -> list:
info_refs = cross_reference_id_list([
syntax_elements.SYMBOL_REFERENCE_SYNTAX_ELEMENT,
types.STRING_TYPE_INFO,
types.LIST_TYPE_INFO,
types.PATH_TYPE_INFO,
concepts.SYMBOL_CONCEPT_INFO,
])
plain_refs = [
define_symbol.DEFINE_SYMBOL_INSTRUCTION_CROSS_REFERENCE,
]
return info_refs + plain_refs
def _symbol_reference_sed(self) -> SyntaxElementDescription:
return SyntaxElementDescription(syntax_elements.SYMBOL_REFERENCE_SYNTAX_ELEMENT.argument.name,
self._tp.fnap(_SYMBOL_REFERENCE_DESCRIPTION))
@staticmethod
def _cl_arguments() -> list:
return [
a.Choice(a.Multiplicity.ZERO_OR_MORE,
[
syntax_elements.STRING_SYNTAX_ELEMENT.argument,
syntax_elements.SYMBOL_REFERENCE_SYNTAX_ELEMENT.argument,
]),
]
示例7: _Documentation
# 需要导入模块: from exactly_lib.util.textformat.textformat_parser import TextParser [as 别名]
# 或者: from exactly_lib.util.textformat.textformat_parser.TextParser import format [as 别名]
class _Documentation(SyntaxElementDocumentation):
def __init__(self):
super().__init__(TypeCategory.DATA,
syntax_elements.PATH_SYNTAX_ELEMENT)
self._string_name = a.Named(syntax_elements.STRING_SYNTAX_ELEMENT.singular_name)
self._relativity_name = instruction_arguments.RELATIVITY_ARGUMENT
path_type_symbol = 'MY_PATH_SYMBOL'
self._parser = TextParser({
'RELATIVITY_OPTION': self._relativity_name.name,
'PATH_STRING': self._string_name.name,
'posix_syntax': documentation_text.POSIX_SYNTAX,
'string_type': formatting.keyword(types.STRING_TYPE_INFO.name.singular),
'path_type': formatting.keyword(types.PATH_TYPE_INFO.name.singular),
'string_syntax_element': syntax_elements.STRING_SYNTAX_ELEMENT.singular_name,
'cd': formatting.concept_(concepts.CURRENT_WORKING_DIRECTORY_CONCEPT_INFO),
'symbol': formatting.concept_(concepts.SYMBOL_CONCEPT_INFO),
'SYMBOL_NAME': syntax_elements.SYMBOL_NAME_SYNTAX_ELEMENT.argument.name,
'define_symbol': formatting.InstructionName(instruction_names.SYMBOL_DEFINITION_INSTRUCTION_NAME),
'current_directory': formatting.concept_(concepts.CURRENT_WORKING_DIRECTORY_CONCEPT_INFO),
'REFERENCED_SYMBOL': path_type_symbol,
'SYMBOL_REFERENCE': symbol_reference_syntax_for_name(path_type_symbol),
'def_of_path_symbol': define_symbol.def_syntax_string(ValueType.PATH, path_type_symbol, '...'),
'ref_of_path_symbol': '... ' + str(PurePosixPath(symbol_reference_syntax_for_name(path_type_symbol)) /
'a' / 'path' / 'relative' / 'to' / path_type_symbol),
})
def invokation_variants(self) -> list:
return [
InvokationVariant(
cl_syntax.cl_syntax_for_args(self._cl_arguments())
)
]
def syntax_element_descriptions(self) -> List[SyntaxElementDescription]:
return [
self._string_sed(),
self._relativity_sed(),
self._symbol_name_sed(),
]
def main_description_rest_paragraphs(self) -> List[ParagraphItem]:
return []
def main_description_rest_sub_sections(self) -> List[SectionItem]:
return [
docs.section('Relativity',
self._parser.fnap(_MAIN_DESCRIPTION_RELATIVITY),
[docs.section('NOTE',
self._parser.fnap(_MAIN_DESCRIPTION_RELATIVITY_NOTE))]),
path_type_path_rendering()
]
def see_also_targets(self) -> List[SeeAlsoTarget]:
return cross_reference_id_list([
concepts.TEST_CASE_DIRECTORY_STRUCTURE_CONCEPT_INFO,
concepts.CURRENT_WORKING_DIRECTORY_CONCEPT_INFO,
concepts.SYMBOL_CONCEPT_INFO,
syntax_elements.STRING_SYNTAX_ELEMENT,
syntax_elements.SYMBOL_NAME_SYNTAX_ELEMENT,
types.PATH_TYPE_INFO,
]) + [DEFINE_SYMBOL_INSTRUCTION_CROSS_REFERENCE]
def _relativity_sed(self) -> SyntaxElementDescription:
description_rest = self._parser.fnap(_RELATIVITY_DESCRIPTION_REST)
description_rest.append(self._relativity_options_paragraph())
return SyntaxElementDescription(self._relativity_name.name,
description_rest)
def _string_sed(self) -> SyntaxElementDescription:
return SyntaxElementDescription(self._string_name.name,
self._parser.fnap(_STRING_DESCRIPTION_REST))
def _symbol_name_sed(self) -> SyntaxElementDescription:
return SyntaxElementDescription(syntax_elements.SYMBOL_NAME_SYNTAX_ELEMENT.singular_name,
self._parser.fnap(_SYMBOL_NAME_DESCRIPTION))
def _cl_arguments(self) -> List[a.ArgumentUsage]:
return [
a.Single(a.Multiplicity.OPTIONAL,
self._relativity_name),
a.Single(a.Multiplicity.MANDATORY,
self._string_name),
]
def _relativity_options_paragraph(self) -> ParagraphItem:
return docs.simple_list_with_space_between_elements_and_content([
docs.list_item(
self._options_for_directories_in_the(concepts.HOME_DIRECTORY_STRUCTURE_CONCEPT_INFO),
self._options_for_directories_in_the_hds(),
),
docs.list_item(
self._options_for_directories_in_the(concepts.SANDBOX_CONCEPT_INFO),
self._options_for_directories_in_the_sds(),
),
docs.list_item(
#.........这里部分代码省略.........