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 <cheimes@redhat.com>
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
This commit is contained in:
Christian Heimes
2018-07-04 10:07:49 +02:00
parent 53c5496647
commit 198a2c6112
8 changed files with 71 additions and 17 deletions

View File

@@ -22,7 +22,6 @@ Base class for all XML-RPC tests
"""
from __future__ import print_function
import collections
import datetime
import inspect
import unittest
@@ -34,6 +33,12 @@ from ipatests.util import assert_deepequal, Fuzzy
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 @@ fuzzy_base64 = Fuzzy('^[0-9A-Za-z/+]+={0,2}$')
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)