本文整理汇总了Python中string.Template.splitlines方法的典型用法代码示例。如果您正苦于以下问题:Python Template.splitlines方法的具体用法?Python Template.splitlines怎么用?Python Template.splitlines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string.Template
的用法示例。
在下文中一共展示了Template.splitlines方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_full_address
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import splitlines [as 别名]
def get_full_address(self, name):
pool = Pool()
AddressFormat = pool.get('party.address.format')
full_address = Template(AddressFormat.get_format(self)).substitute(
**self._get_address_substitutions())
return '\n'.join(
[_f for _f in (x.strip() for x in full_address.splitlines()) if _f])
示例2: write_normal_data_driven_case_content
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import splitlines [as 别名]
def write_normal_data_driven_case_content(
self, out, valid_combinations, case_name_template, case_step_template, case_tag_template
):
for line in valid_combinations:
kwargs = line
tags = Template(case_tag_template).substitute(**kwargs) if case_tag_template else None
testcase_name = Template(case_name_template).substitute(**kwargs)
steps = Template(case_step_template).substitute(**kwargs)
out.write("%s\n" % testcase_name)
if tags:
out.write(" [Tags] %s\n" % tags)
for step in steps.splitlines():
out.write(" %s\n" % step.strip())
示例3: _expand_canonical
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import splitlines [as 别名]
def _expand_canonical(canonical, ext, long_slash_star):
canonical = Template(canonical).substitute({'year': date.today().year})
lines = canonical.splitlines()
outlines = []
if ext in ['.c', '.cpp', '.cc', '.h', '.java', '.js', '.S']:
if long_slash_star or ext == '.S':
outlines = ['/*'] + [' *' + l for l in lines] + [' */']
else:
outlines = ['//' + l for l in lines]
elif ext in ['.gypi', '.py']:
outlines = ['#' + l for l in lines]
elif ext in ['.css', '.html']:
outlines = (['<!--' + lines[0]] + [' ' + l for l in lines[1:-1]] +
[' ' + lines[-1] + ' -->'])
else:
sys.exit('Unknown comment style for file with ext ' + ext)
return ''.join([l + '\n' for l in outlines])
示例4: file
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import splitlines [as 别名]
hostname = netinfo.get_hostname().upper()
try:
#backwards compatible - use usage.txt if it exists
t = file(conf.path("usage.txt"), 'r').read()
text = Template(t).substitute(hostname=hostname, ipaddr=ip_addr)
retcode = self.console.msgbox("Usage", text,
button_label=default_button_label)
except conf.Error:
t = file(conf.path("services.txt"), 'r').read().rstrip()
text = Template(t).substitute(ipaddr=ip_addr)
text += "\n\n%s\n\n" % tklbam_status
text += "\n" * (self.height - len(text.splitlines()) - 7)
text += " TurnKey Backups and Cloud Deployment\n"
text += " https://hub.turnkeylinux.org"
retcode = self.console.msgbox("%s appliance services" % hostname,
text, button_label=default_button_label)
if retcode is not self.OK:
self.running = False
return default_return_value
def advanced(self):
#dont display cancel button when no interfaces at all
no_cancel = False
if len(self._get_filtered_ifnames()) == 0:
示例5: parse_story_file
# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import splitlines [as 别名]
def parse_story_file(self, story_file_path, settings):
story_text = self.file_object.read_file(story_file_path)
story_text = Template(story_text).safe_substitute(settings.extra_args)
story_lines = [line for line in story_text.splitlines() if line.strip() != ""]
headers = self.assert_header(story_lines, settings.default_culture)
if not headers:
return (False, self.language.get('no_header_failure'), None)
as_a = headers[0]
i_want_to = headers[1]
so_that = headers[2]
current_story = Story(as_a=as_a, i_want_to=i_want_to, so_that=so_that, identity=story_file_path)
scenario_lines = story_lines[3:]
current_scenario = None
offset = 0
for line_index, line in enumerate(scenario_lines):
if offset > 0:
offset -= 1
continue
offset = 0
if self.is_scenario_starter_line(line):
current_scenario = self.parse_scenario_line(current_story, line, settings)
current_area = None
continue
if self.is_keyword(line, "given"):
current_area = "given"
continue
if self.is_keyword(line, "when"):
current_area = "when"
continue
if self.is_keyword(line, "then"):
current_area = "then"
continue
if current_scenario is None:
if settings.scenarios_to_run:
continue
else:
raise InvalidScenarioError("NoScenario")
if not current_area:
raise InvalidScenarioError("NoGivenWhenThen")
add_method = getattr(current_scenario, "add_%s" % current_area)
if line.strip().startswith("#"):
add_method(line, lambda context, *args, **kwargs: None, [], {})
continue
action, args, kwargs = self.action_registry.suitable_for(line.strip(), settings.default_culture)
rows = []
parsed_rows = []
if line.strip().endswith(':'):
if line_index >= len(scenario_lines):
self.raise_action_not_found_for_line(line, current_scenario, story_file_path)
offset, rows, parsed_rows = self.parse_rows(line_index,
line,
scenario_lines)
args=[]
if not action:
self.raise_action_not_found_for_line(line, current_scenario, story_file_path)
if not action in self.used_actions:
self.used_actions.append(action)
instance = action()
if kwargs:
args = []
instance.number_of_rows = 1
parsed_line = line
if parsed_rows:
kwargs['table'] = parsed_rows
for row in rows:
parsed_line = parsed_line + "\n%s%s" % (" " * \
(self.get_line_identation(line) + 4),\
row)
add_method(parsed_line, instance.execute, args, kwargs)
return (True, None, current_story)