URL: https://github.com/freeipa/freeipa/pull/2097
Author: tiran
 Title: #2097: [py37] Import ABCs from collections.abc
Action: opened

PR body:
"""
Python 3 has moved all collection abstract base classes to
collections.abc. Python 3.7 started to deprecate the old aliases.

The whole import block needs to be protected with import-error and
no-name-in-module, because Python 2 doesn't have collections.abc module and
collections.abc.Mapping, while Python 3 doesn't have collections.Mapping.

Fixes: https://pagure.io/freeipa/issue/7609
Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/2097/head:pr2097
git checkout pr2097
From aaf01f2bb481923dcd1912bb2a79186a61799c06 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Wed, 4 Jul 2018 10:07:49 +0200
Subject: [PATCH] [py37] Import ABCs from collections.abc

Python 3 has moved all collection abstract base classes to
collections.abc. Python 3.7 started to deprecate the old aliases.

The whole import block needs to be protected with import-error and
no-name-in-module, because Python 2 doesn't have collections.abc module and
collections.abc.Mapping, while Python 3 doesn't have collections.Mapping.

Fixes: https://pagure.io/freeipa/issue/7609
Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipaclient/remote_plugins/__init__.py | 12 ++++++++++--
 ipaclient/remote_plugins/schema.py   | 12 +++++++++---
 ipalib/plugable.py                   |  9 ++++++++-
 ipaplatform/base/services.py         |  9 +++++++--
 ipapython/ipaldap.py                 | 12 +++++++++---
 ipaserver/dnssec/ldapkeydb.py        | 12 ++++++++++--
 ipaserver/dnssec/localhsm.py         | 13 +++++++++++--
 ipatests/test_xmlrpc/xmlrpc_test.py  |  9 +++++++--
 8 files changed, 71 insertions(+), 17 deletions(-)

diff --git a/ipaclient/remote_plugins/__init__.py b/ipaclient/remote_plugins/__init__.py
index f1ff22e28e..fe75b81b88 100644
--- a/ipaclient/remote_plugins/__init__.py
+++ b/ipaclient/remote_plugins/__init__.py
@@ -2,7 +2,6 @@
 # Copyright (C) 2016  FreeIPA Contributors see COPYING for license
 #
 
-import collections
 import errno
 import json
 import locale
@@ -10,16 +9,25 @@
 import os
 import time
 
+import six
+
 from . import compat
 from . import schema
 from ipaclient.plugins.rpcclient import rpcclient
 from ipalib.constants import USER_CACHE_PATH
 from ipapython.dnsutil import DNSName
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import MutableMapping
+else:
+    from collections import MutableMapping
+# pylint: enable=no-name-in-module, import-error
+
 logger = logging.getLogger(__name__)
 
 
-class ServerInfo(collections.MutableMapping):
+class ServerInfo(MutableMapping):
     _DIR = os.path.join(USER_CACHE_PATH, 'ipa', 'servers')
 
     def __init__(self, api):
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index 863d8f1992..d9a5fb0361 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -2,7 +2,6 @@
 # Copyright (C) 2016  FreeIPA Contributors see COPYING for license
 #
 
-import collections
 import errno
 import json
 import logging
@@ -27,6 +26,13 @@
 from ipapython.dn import DN
 from ipapython.dnsutil import DNSName
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import Mapping, Sequence
+else:
+    from collections import Mapping, Sequence
+# pylint: enable=no-name-in-module, import-error
+
 logger = logging.getLogger(__name__)
 
 FORMAT = '1'
@@ -39,7 +45,7 @@
     'DNSName': DNSName,
     'Principal': unicode,
     'NoneType': type(None),
-    'Sequence': collections.Sequence,
+    'Sequence': Sequence,
     'bool': bool,
     'dict': dict,
     'int': int,
@@ -315,7 +321,7 @@ class _SchemaObjectPlugin(_SchemaPlugin):
     schema_key = 'classes'
 
 
-class _SchemaNameSpace(collections.Mapping):
+class _SchemaNameSpace(Mapping):
 
     def __init__(self, schema, name):
         self.name = name
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index d78a607123..7cf99a0c60 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -51,6 +51,13 @@
     LOGGING_FORMAT_STDERR)
 from ipapython.version import VERSION, API_VERSION, DEFAULT_PLUGINS
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import Mapping
+else:
+    from collections import Mapping
+# pylint: enable=no-name-in-module, import-error
+
 if six.PY3:
     unicode = str
 
@@ -282,7 +289,7 @@ def __repr__(self):
         )
 
 
-class APINameSpace(collections.Mapping):
+class APINameSpace(Mapping):
     def __init__(self, api, base):
         self.__api = api
         self.__base = base
diff --git a/ipaplatform/base/services.py b/ipaplatform/base/services.py
index 13168585ca..95a9302463 100644
--- a/ipaplatform/base/services.py
+++ b/ipaplatform/base/services.py
@@ -28,7 +28,6 @@
 import os
 import json
 import time
-import collections
 import logging
 import warnings
 
@@ -37,6 +36,12 @@
 from ipapython import ipautil
 from ipaplatform.paths import paths
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import Mapping
+else:
+    from collections import Mapping
+# pylint: enable=no-name-in-module, import-error
 
 logger = logging.getLogger(__name__)
 
@@ -62,7 +67,7 @@
 SERVICE_POLL_INTERVAL = 0.1 # seconds
 
 
-class KnownServices(collections.Mapping):
+class KnownServices(Mapping):
     """
     KnownServices is an abstract class factory that should give out instances
     of well-known platform services. Actual implementation must create these
diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py
index 58a6437d85..66d73846a4 100644
--- a/ipapython/ipaldap.py
+++ b/ipapython/ipaldap.py
@@ -27,7 +27,6 @@
 from decimal import Decimal
 from copy import deepcopy
 import contextlib
-import collections
 import os
 import pwd
 import warnings
@@ -53,6 +52,13 @@
 from ipapython.dnsutil import DNSName
 from ipapython.kerberos import Principal
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import MutableMapping
+else:
+    from collections import MutableMapping
+# pylint: enable=no-name-in-module, import-error
+
 if six.PY3:
     unicode = str
 
@@ -213,7 +219,7 @@ def _retrieve_schema_from_server(self, url, conn):
 schema_cache = SchemaCache()
 
 
-class LDAPEntry(collections.MutableMapping):
+class LDAPEntry(MutableMapping):
     __slots__ = ('_conn', '_dn', '_names', '_nice', '_raw', '_sync',
                  '_not_list', '_orig_raw', '_raw_view',
                  '_single_value_view')
@@ -577,7 +583,7 @@ def __iter__(self):
         return iter(self._nice)
 
 
-class LDAPEntryView(collections.MutableMapping):
+class LDAPEntryView(MutableMapping):
     __slots__ = ('_entry',)
 
     def __init__(self, entry):
diff --git a/ipaserver/dnssec/ldapkeydb.py b/ipaserver/dnssec/ldapkeydb.py
index 43d7fc4684..d47b03732f 100644
--- a/ipaserver/dnssec/ldapkeydb.py
+++ b/ipaserver/dnssec/ldapkeydb.py
@@ -5,10 +5,11 @@
 from __future__ import print_function, absolute_import
 
 from binascii import hexlify
-import collections
 import logging
 from pprint import pprint
 
+import six
+
 import ipalib
 from ipaplatform.paths import paths
 from ipapython.dn import DN
@@ -23,6 +24,13 @@
 from ipaserver import p11helper as _ipap11helper
 import uuid
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import MutableMapping
+else:
+    from collections import MutableMapping
+# pylint: enable=no-name-in-module, import-error
+
 logger = logging.getLogger(__name__)
 
 
@@ -122,7 +130,7 @@ def str_hexlify(data):
     return out
 
 
-class Key(collections.MutableMapping):
+class Key(MutableMapping):
     """abstraction to hide LDAP entry weirdnesses:
         - non-normalized attribute names
         - boolean attributes returned as strings
diff --git a/ipaserver/dnssec/localhsm.py b/ipaserver/dnssec/localhsm.py
index db8fd10bb3..6a85ce3a3c 100755
--- a/ipaserver/dnssec/localhsm.py
+++ b/ipaserver/dnssec/localhsm.py
@@ -5,10 +5,11 @@
 
 from __future__ import print_function, absolute_import
 
-import collections
 import os
 from pprint import pprint
 
+import six
+
 from ipalib.constants import SOFTHSM_DNSSEC_TOKEN_LABEL
 from ipaplatform.paths import paths
 from ipaserver import p11helper as _ipap11helper
@@ -17,6 +18,13 @@
                                      ldap2p11helper_api_params)
 from ipaserver.dnssec.ldapkeydb import str_hexlify
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import MutableMapping
+else:
+    from collections import MutableMapping
+# pylint: enable=no-name-in-module, import-error
+
 
 private_key_api_params = set(["label", "id", "data", "unwrapping_key",
     "wrapping_mech", "key_type", "cka_always_authenticate", "cka_copyable",
@@ -28,7 +36,8 @@
     "cka_derive", "cka_encrypt", "cka_modifiable", "cka_private",
     "cka_trusted", "cka_verify", "cka_verify_recover", "cka_wrap"])
 
-class Key(collections.MutableMapping):
+
+class Key(MutableMapping):
     def __init__(self, p11, handle):
         self.p11 = p11
         self.handle = handle
diff --git a/ipatests/test_xmlrpc/xmlrpc_test.py b/ipatests/test_xmlrpc/xmlrpc_test.py
index 12e61268e6..66459bda2b 100644
--- a/ipatests/test_xmlrpc/xmlrpc_test.py
+++ b/ipatests/test_xmlrpc/xmlrpc_test.py
@@ -22,7 +22,6 @@
 """
 from __future__ import print_function
 
-import collections
 import datetime
 import inspect
 import unittest
@@ -34,6 +33,12 @@
 from ipalib import api, request, errors
 from ipapython.version import API_VERSION
 
+# pylint: disable=no-name-in-module, import-error
+if six.PY3:
+    from collections.abc import Sequence
+else:
+    from collections import Sequence
+# pylint: enable=no-name-in-module, import-error
 
 # Matches a gidnumber like '1391016742'
 # FIXME: Does it make more sense to return gidnumber, uidnumber, etc. as `int`
@@ -57,7 +62,7 @@
 def fuzzy_sequence_of(fuzzy):
     """Construct a Fuzzy for a Sequence of values matching the given Fuzzy."""
     def test(xs):
-        if not isinstance(xs, collections.Sequence):
+        if not isinstance(xs, Sequence):
             return False
         else:
             return all(fuzzy == x for x in xs)
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/freeipa-devel@lists.fedorahosted.org/message/S3HZQA7EUG4FFUIWCLGI2IHY7J73LPHL/

Reply via email to