1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix to_bytes(None) on Python 3

You cannot call bytes(obj) to get a simple representation of obj on
Python 3!  E.g. bytes(42) returns a byte string with 42 NUL characters
instead of b'42'.
This commit is contained in:
Marius Gedminas 2015-08-27 09:38:12 +03:00
parent df1b41d3d3
commit eb99aa8c68

View file

@ -215,7 +215,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
return obj
elif nonstring == 'simplerepr':
try:
simple = binary_type(obj)
simple = str(obj)
except UnicodeError:
try:
simple = obj.__str__()