From 28b0bfaefea02fe188b57b602396f5ef62863726 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 26 Apr 2016 14:59:35 +0200 Subject: 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 --- ipalib/plugins/dns.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index b01ac840f..079cb6d98 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -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 -- cgit