mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-14 21:19:12 -07:00
Move collections abc shim to _collections_compat
This commit is contained in:
parent
912bd25a4e
commit
eb209e92c9
2 changed files with 40 additions and 10 deletions
|
@ -81,8 +81,6 @@ import pwd
|
||||||
import platform
|
import platform
|
||||||
import errno
|
import errno
|
||||||
import datetime
|
import datetime
|
||||||
from collections import deque
|
|
||||||
from collections import Mapping, MutableMapping, Sequence, MutableSequence, Set, MutableSet
|
|
||||||
from itertools import chain, repeat
|
from itertools import chain, repeat
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -107,14 +105,6 @@ except ImportError:
|
||||||
# Python2 & 3 way to get NoneType
|
# Python2 & 3 way to get NoneType
|
||||||
NoneType = type(None)
|
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:
|
try:
|
||||||
import json
|
import json
|
||||||
# Detect the python-json library which is incompatible
|
# Detect the python-json library which is incompatible
|
||||||
|
@ -162,6 +152,13 @@ except ImportError:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
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.pycompat24 import get_exception, literal_eval
|
||||||
from ansible.module_utils.six import (
|
from ansible.module_utils.six import (
|
||||||
PY2,
|
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
|
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)
|
PASSWORD_MATCH = re.compile(r'^(?:.+[-_\s])?pass(?:[-_\s]?(?:word|phrase|wrd|wd)?)(?:[-_\s].+)?$', re.I)
|
||||||
|
|
||||||
_NUMBERTYPES = tuple(list(integer_types) + [float])
|
_NUMBERTYPES = tuple(list(integer_types) + [float])
|
||||||
|
|
29
lib/ansible/module_utils/common/_collections_compat.py
Normal file
29
lib/ansible/module_utils/common/_collections_compat.py
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue