本文整理汇总了Python中jinja2.Template.split方法的典型用法代码示例。如果您正苦于以下问题:Python Template.split方法的具体用法?Python Template.split怎么用?Python Template.split使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.Template
的用法示例。
在下文中一共展示了Template.split方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_metadata_text_lines
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import split [as 别名]
def prepare_metadata_text_lines(media_info, header_font, header_margin, width, template_path=None):
"""Prepare the metadata header text and return a list containing each line.
"""
template = ""
if template_path is None:
template = """{{filename}}
File size: {{size}}
Duration: {{duration}}
Dimensions: {{sample_width}}x{{sample_height}}"""
else:
with open(template_path) as f:
template = f.read()
params = media_info.template_attributes()
template = Template(template).render(params)
template_lines = template.split("\n")
template_lines = [x.strip() for x in template_lines if len(x) > 0]
header_lines = []
for line in template_lines:
remaining_chars = line
while len(remaining_chars) > 0:
max_metadata_line_length = max_line_length(media_info, header_font, header_margin, width=width, text=remaining_chars)
wraps = textwrap.wrap(remaining_chars, max_metadata_line_length)
header_lines.append(wraps[0])
remaining_chars = remaining_chars[len(wraps[0]):].strip()
return header_lines
示例2: test_rendered_templates
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import split [as 别名]
def test_rendered_templates(self, host, host_os, clean_dir, pallet_name, version, pallet_os):
args = {
'name': pallet_name,
'version': version,
'os': pallet_os,
}
arg_str = ' '.join(f'{key}={value}' for key, value in args.items() if value)
result = host.run(f'stack create new pallet {arg_str}')
assert result.rc == 0
assert host.file(f'./{pallet_name}').exists
assert host.file(f'./{pallet_name}').is_directory
if not pallet_os:
args['os'] = host_os
if not version:
args['version'] = '1.0'
del args['name']
args['pallet_name'] = pallet_name
rendered_fi = Template(versionmk).render(**args)
# collapse whitespace for the sake of string comparison
rendered_fi = ' '.join(rendered_fi.split())
with open(f'./{pallet_name}/version.mk', 'r') as fi:
assert ' '.join(fi.read().split()) == rendered_fi
示例3: get_template
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import split [as 别名]
def get_template(self, template):
try:
template = Template(codecs.open(template,
encoding='utf-8').read())
return template
except IOError:
error = "Ops! Theme '{}' not configured properly.\n"
error_description = "Template '{}' does not exist\n."
report_error(error.format(self.theme) +
error_description.format(template.split('/')[-1]))
sys.exit(1)
示例4: get_file_tokens
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import split [as 别名]
def get_file_tokens(file_name, service_fullname=None):
""" Returns a local file as a series of tokens and CloudFormation variables/functions """
with open(file_name, "r") as f:
cnt = f.read()
if service_fullname:
rendered = Template(cnt).render(service_fullname=service_fullname)
tokens = rendered.split("|||")
tokens = [json.loads(token) if re.match(r"^\{.*\}$", token) else token for token in tokens]
return tokens
else:
return [cnt]