def get_template_contents(template_file=None, template_url=None,
files=None):
# Transform a bare file path to a file:// URL.
if template_file: # nosec
template_url = utils.normalise_file_path_to_url(template_file)
tpl = request.urlopen(template_url).read()
else:
raise exceptions.CommandErrorException(_('Need to specify exactly '
'one of %(arg1)s, %(arg2)s '
'or %(arg3)s') %
{'arg1': '--template-file',
'arg2': '--template-url'})
if not tpl:
raise exceptions.CommandErrorException(_('Could not fetch '
'template from %s') %
template_url)
try:
if isinstance(tpl, six.binary_type):
tpl = tpl.decode('utf-8')
template = template_format.parse(tpl)
except ValueError as e:
raise exceptions.CommandErrorException(_('Error parsing template '
'%(url)s %(error)s') %
{'url': template_url,
'error': e})
return template
评论列表
文章目录