mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #12757 from mgedmin/py3k
Python 3: fix AnsibleError formatting
This commit is contained in:
commit
0526b43b5f
2 changed files with 10 additions and 4 deletions
|
@ -19,10 +19,9 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
from ansible.errors.yaml_strings import *
|
||||
from ansible.utils.unicode import to_unicode, to_bytes
|
||||
from ansible.utils.unicode import to_unicode, to_str
|
||||
|
||||
|
||||
class AnsibleError(Exception):
|
||||
'''
|
||||
|
@ -49,7 +48,7 @@ class AnsibleError(Exception):
|
|||
if obj and isinstance(obj, AnsibleBaseYAMLObject):
|
||||
extended_error = self._get_extended_error()
|
||||
if extended_error:
|
||||
self.message = 'ERROR! %s\n\n%s' % (message, to_bytes(extended_error))
|
||||
self.message = 'ERROR! %s\n\n%s' % (message, to_str(extended_error))
|
||||
else:
|
||||
self.message = 'ERROR! %s' % message
|
||||
|
||||
|
|
|
@ -251,3 +251,10 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
|
|||
# ensure that a filter will return unicode values.
|
||||
def unicode_wrap(func, *args, **kwargs):
|
||||
return to_unicode(func(*args, **kwargs), nonstring='passthru')
|
||||
|
||||
|
||||
# Alias for converting to native strings.
|
||||
if PY3:
|
||||
to_str = to_unicode
|
||||
else:
|
||||
to_str = to_bytes
|
||||
|
|
Loading…
Reference in a new issue