mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Re-factor dedent to fix warts
- textwarp.dedent does not support bytes on py3 - make sure to preserve trailing newlines
This commit is contained in:
parent
75b2e3d990
commit
6abc2daf56
1 changed files with 8 additions and 5 deletions
|
@ -1572,8 +1572,11 @@ def dedent(text, linesep=os.linesep):
|
|||
'''
|
||||
A wrapper around textwrap.dedent that also sets line endings.
|
||||
'''
|
||||
if isinstance(text, six.text_type):
|
||||
linesep = salt.utils.to_unicode(linesep)
|
||||
else:
|
||||
linesep = salt.utils.to_str(linesep)
|
||||
return linesep.join(textwrap.dedent(text).splitlines())
|
||||
linesep = salt.utils.to_unicode(linesep)
|
||||
unicode_text = textwrap.dedent(salt.utils.to_unicode(text))
|
||||
clean_text = linesep.join(unicode_text.splitlines())
|
||||
if unicode_text.endswith(salt.utils.to_unicode('\n')):
|
||||
clean_text = clean_text + linesep
|
||||
if not isinstance(text, six.text_type):
|
||||
return salt.utils.to_bytes(clean_text)
|
||||
return clean_text
|
||||
|
|
Loading…
Add table
Reference in a new issue