Move collections abc shim to _collections_compat

pull/40748/merge
Sviatoslav Sydorenko 7 years ago committed by Sviatoslav Sydorenko
parent 912bd25a4e
commit eb209e92c9

@ -81,8 +81,6 @@ import pwd
import platform
import errno
import datetime
from collections import deque
from collections import Mapping, MutableMapping, Sequence, MutableSequence, Set, MutableSet
from itertools import chain, repeat
try:
@ -107,14 +105,6 @@ except ImportError:
# Python2 & 3 way to get NoneType
NoneType = type(None)
# Note: When getting Sequence from collections, it matches with strings. If
# this matters, make sure to check for strings before checking for sequencetype
try:
from collections.abc import KeysView
SEQUENCETYPE = (Sequence, frozenset, KeysView)
except ImportError:
SEQUENCETYPE = (Sequence, frozenset)
try:
import json
# Detect the python-json library which is incompatible
@ -162,6 +152,13 @@ except ImportError:
except ImportError:
pass
from ansible.module_utils.common._collections_compat import (
deque,
KeysView,
Mapping, MutableMapping,
Sequence, MutableSequence,
Set, MutableSet,
)
from ansible.module_utils.pycompat24 import get_exception, literal_eval
from ansible.module_utils.six import (
PY2,
@ -178,6 +175,10 @@ from ansible.module_utils._text import to_native, to_bytes, to_text
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE, boolean
# Note: When getting Sequence from collections, it matches with strings. If
# this matters, make sure to check for strings before checking for sequencetype
SEQUENCETYPE = frozenset, KeysView, Sequence
PASSWORD_MATCH = re.compile(r'^(?:.+[-_\s])?pass(?:[-_\s]?(?:word|phrase|wrd|wd)?)(?:[-_\s].+)?$', re.I)
_NUMBERTYPES = tuple(list(integer_types) + [float])

@ -0,0 +1,29 @@
# Copyright (c), Sviatoslav Sydorenko <ssydoren@redhat.com> 2018
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
"""Collections ABC import shim.
This module is intended only for internal use.
It will go away once the bundled copy of six includes equivalent functionality.
Third parties should not use this.
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
try:
"""Python 3.3+ branch."""
from collections.abc import (
deque, KeysView,
Mapping, MutableMapping,
Sequence, MutableSequence,
Set, MutableSet,
)
except ImportError:
"""Use old lib location under 2.6-3.2."""
from collections import (
deque, KeysView,
Mapping, MutableMapping,
Sequence, MutableSequence,
Set, MutableSet,
)
Loading…
Cancel
Save