mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Move to_str alias into ansible.utils.unicode
@abadger suggested on IRC that it's useful enough to go into ansible.utils.unicode.
This commit is contained in:
parent
ca826508d9
commit
ab569cea22
2 changed files with 8 additions and 9 deletions
|
@ -20,15 +20,7 @@ from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
from ansible.errors.yaml_strings import *
|
from ansible.errors.yaml_strings import *
|
||||||
from ansible.utils.unicode import to_unicode, to_bytes
|
from ansible.utils.unicode import to_unicode, to_str
|
||||||
|
|
||||||
|
|
||||||
if str is bytes:
|
|
||||||
# Python 2
|
|
||||||
to_str = to_bytes
|
|
||||||
else:
|
|
||||||
# Python 3
|
|
||||||
to_str = to_unicode
|
|
||||||
|
|
||||||
|
|
||||||
class AnsibleError(Exception):
|
class AnsibleError(Exception):
|
||||||
|
|
|
@ -251,3 +251,10 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
|
||||||
# ensure that a filter will return unicode values.
|
# ensure that a filter will return unicode values.
|
||||||
def unicode_wrap(func, *args, **kwargs):
|
def unicode_wrap(func, *args, **kwargs):
|
||||||
return to_unicode(func(*args, **kwargs), nonstring='passthru')
|
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…
Add table
Reference in a new issue