Use salt.utils.to_unicode

This commit is contained in:
twangboy 2018-03-08 15:22:50 -07:00 committed by Daniel A. Wozniak
parent 8c0164fb63
commit 6548d550d0
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61
2 changed files with 3 additions and 7 deletions

View file

@ -33,15 +33,12 @@ def get_encodings():
return encodings
def sdecode(string_, encoding=None):
def sdecode(string_):
'''
Since we don't know where a string is coming from and that string will
need to be safely decoded, this function will attempt to decode the string
until it has a working string that does not stack trace
'''
if encoding:
return salt.utils.to_unicode(string_, encoding)
encodings = get_encodings()
for encoding in encodings:
try:

View file

@ -406,12 +406,11 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None, encoding=None):
decoded_context = {}
for key, value in six.iteritems(context):
if isinstance(value, six.text_type):
if not isinstance(value, six.string_types):
decoded_context[key] = value
continue
decoded_context[key] = salt.utils.locales.sdecode(value,
encoding=encoding)
decoded_context[key] = salt.utils.to_unicode(value, encoding=encoding)
try:
template = jinja_env.from_string(tmplstr)