Hello,
Here are two patches for problems with using IPA with Python 3.

-- 
Petr Viktorin
From aad8a7ea093e8aaf0d50f395ff0e0d7038fe55ff Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Tue, 26 Apr 2016 14:59:35 +0200
Subject: [PATCH] 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
---
 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 b01ac840fb930ad21dcb50370cc61e23daf3a188..079cb6d989c2d5d6fef64fa6c6590bd07574bcfa 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
 
 
-- 
2.5.5

From 05c15e9effea602cab4b256d910154d517aa78b3 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Tue, 26 Apr 2016 14:26:53 +0200
Subject: [PATCH] sysrestore: Iterate over a list of dict keys

In Python 3, dict.keys() returns a key view. It is not safe to delete
dict keys when iterating over this view.

Convert the keys to list first.

Part of the work for https://fedorahosted.org/freeipa/ticket/4985
---
 ipapython/sysrestore.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py
index c1c2bce8764d6b343a9c14736dd969be2f975c17..e0d090856c368c359372623fb8aa319bc081c4e4 100644
--- a/ipapython/sysrestore.py
+++ b/ipapython/sysrestore.py
@@ -347,7 +347,7 @@ class StateFile:
         """
         root_logger.debug("Saving StateFile to '%s'", self._path)
 
-        for module in self.modules.keys():
+        for module in list(self.modules.keys()):
             if len(self.modules[module]) == 0:
                 del self.modules[module]
 
-- 
2.5.5

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to