dns plugin: Fix zone normalization under Python 3

In Python 3, str.encode('ascii') converts to bytes, and str()
(nicknamed unicode() in IPA) returns the string representation
of an object, which is b'...' for bytes.

So, unicode('...'.encode('ascii')) results in "b'...'".

Change the code to only call encode() for the error.

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-04-26 14:59:35 +02:00 committed by Martin Basti
parent 8689e6be51
commit 28b0bfaefe

View File

@ -1755,9 +1755,11 @@ def _normalize_zone(zone):
if isinstance(zone, unicode): if isinstance(zone, unicode):
# normalize only non-IDNA zones # normalize only non-IDNA zones
try: try:
return unicode(zone.encode('ascii')).lower() zone.encode('ascii')
except UnicodeError: except UnicodeError:
pass pass
else:
return zone.lower()
return zone return zone