mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Check if we have a StringIO and grab the string instead
This seems to be specific to Jinja so only do it if needed.
This commit is contained in:
parent
17b8cd755f
commit
76671b6a81
1 changed files with 10 additions and 3 deletions
|
@ -72,6 +72,7 @@ from __future__ import absolute_import
|
|||
import os
|
||||
import logging
|
||||
import smtplib
|
||||
import StringIO
|
||||
from email.utils import formatdate
|
||||
|
||||
# Import Salt libs
|
||||
|
@ -147,19 +148,22 @@ def returner(ret):
|
|||
for field in fields:
|
||||
if field in ret:
|
||||
subject += ' {0}'.format(ret[field])
|
||||
subject = compile_template(':string:', rend, renderer, input_data=subject, **ret).getvalue()
|
||||
subject = compile_template(':string:', rend, renderer, input_data=subject, **ret)
|
||||
if isinstance(subject, StringIO.StringIO):
|
||||
subject = subject.read()
|
||||
|
||||
log.debug("smtp_return: Subject is '{0}'".format(subject))
|
||||
|
||||
template = _options.get('template')
|
||||
if template:
|
||||
content = compile_template(template, rend, renderer, **ret).getvalue()
|
||||
content = compile_template(template, rend, renderer, **ret)
|
||||
else:
|
||||
template = ('id: {{id}}\r\n'
|
||||
'function: {{fun}}\r\n'
|
||||
'function args: {{fun_args}}\r\n'
|
||||
'jid: {{jid}}\r\n'
|
||||
'return: {{return}}\r\n')
|
||||
content = compile_template(':string:', rend, renderer, input_data=template, **ret).getvalue()
|
||||
content = compile_template(':string:', rend, renderer, input_data=template, **ret)
|
||||
|
||||
if HAS_GNUPG and gpgowner:
|
||||
gpg = gnupg.GPG(gnupghome=os.path.expanduser('~{0}/.gnupg'.format(gpgowner)),
|
||||
|
@ -173,6 +177,9 @@ def returner(ret):
|
|||
content = 'Encryption failed, the return data was not sent.\r\n\r\n{0}\r\n{1}'.format(
|
||||
encrypted_data.status, encrypted_data.stderr)
|
||||
|
||||
if isinstance(content, StringIO.StringIO):
|
||||
content = content.read()
|
||||
|
||||
message = ('From: {0}\r\n'
|
||||
'To: {1}\r\n'
|
||||
'Date: {2}\r\n'
|
||||
|
|
Loading…
Add table
Reference in a new issue