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):
# normalize only non-IDNA zones
try:
return unicode(zone.encode('ascii')).lower()
zone.encode('ascii')
except UnicodeError:
pass
else:
return zone.lower()
return zone