ipalib.cli: Improve reporting of binary values in the CLI

Make sure the base64-encoded value is a string, so it is printed
without the b'' markers.

Part of the work for: https://fedorahosted.org/freeipa/ticket/4985

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Petr Viktorin 2016-05-05 16:49:24 +02:00 committed by Martin Basti
parent a9a1353098
commit 5dbb0f6fec

View File

@ -164,10 +164,11 @@ class textui(backend.Backend):
def encode_binary(self, value):
"""
Convert a binary value to base64. We know a value is binary
if it is a python str type, otherwise it is a plain string.
if it is a python bytes type, otherwise it is a plain string.
This function also converts datetime and DNSName values to string.
"""
if type(value) is bytes:
return base64.b64encode(value)
return base64.b64encode(value).decode('ascii')
elif type(value) is datetime.datetime:
return value.strftime(LDAP_GENERALIZED_TIME_FORMAT)
elif isinstance(value, DNSName):