mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use salt.utils.to_unicode
This commit is contained in:
parent
8c0164fb63
commit
6548d550d0
2 changed files with 3 additions and 7 deletions
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue