py3: ldapupdate: fix logging str(bytes) issue

bytes as argument of str() gives unexpected result by adding prefix "b"
there.

Also add missing safe_option() call to logging (it will fix another
str(bytes) issue)

https://fedorahosted.org/freeipa/ticket/4985

Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
Martin Basti 2017-02-02 00:20:48 +01:00
parent 387a1513bb
commit b24787a67f

View File

@ -119,10 +119,10 @@ def safe_output(attr, values):
values = [values]
try:
all(v.decode('ascii') for v in values)
values = [v.decode('ascii') for v in values]
except UnicodeDecodeError:
try:
values = [base64.b64encode(v) for v in values]
values = [base64.b64encode(v).decode('ascii') for v in values]
except TypeError:
pass
@ -656,7 +656,9 @@ class LDAPUpdate(object):
try:
entry_values.remove(update_value)
except ValueError:
self.debug("remove: '%s' not in %s", update_value, attr)
self.debug(
"remove: '%s' not in %s",
safe_output(attr, update_value), attr)
else:
entry[attr] = entry_values
self.debug('remove: updated value %s', safe_output(