|
|
|
@ -32,8 +32,6 @@ from ansible.module_utils.common.text.converters import to_native, to_text
|
|
|
|
|
from ansible.parsing.splitter import parse_kv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ADDITIONAL_PY2_KEYWORDS = frozenset(("True", "False", "None"))
|
|
|
|
|
|
|
|
|
|
_MAXSIZE = 2 ** 32
|
|
|
|
|
cur_id = 0
|
|
|
|
|
node_mac = ("%012x" % uuid.getnode())[:12]
|
|
|
|
@ -237,26 +235,8 @@ def load_options_vars(version):
|
|
|
|
|
return load_options_vars.options_vars
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _isidentifier_PY3(ident):
|
|
|
|
|
if not isinstance(ident, string_types):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not ident.isascii():
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not ident.isidentifier():
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if keyword.iskeyword(ident):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isidentifier = _isidentifier_PY3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isidentifier.__doc__ = """Determine if string is valid identifier.
|
|
|
|
|
def isidentifier(ident):
|
|
|
|
|
"""Determine if string is valid identifier.
|
|
|
|
|
|
|
|
|
|
The purpose of this function is to be used to validate any variables created in
|
|
|
|
|
a play to be valid Python identifiers and to not conflict with Python keywords
|
|
|
|
@ -265,11 +245,22 @@ a valid identifier is, this function unifies the validation so playbooks are
|
|
|
|
|
portable between the two. The following changes were made:
|
|
|
|
|
|
|
|
|
|
* disallow non-ascii characters (Python 3 allows for them as opposed to Python 2)
|
|
|
|
|
* True, False and None are reserved keywords (these are reserved keywords
|
|
|
|
|
on Python 3 as opposed to Python 2)
|
|
|
|
|
|
|
|
|
|
:arg ident: A text string of identifier to check. Note: It is callers
|
|
|
|
|
responsibility to convert ident to text if it is not already.
|
|
|
|
|
|
|
|
|
|
Originally posted at http://stackoverflow.com/a/29586366
|
|
|
|
|
Originally posted at https://stackoverflow.com/a/29586366
|
|
|
|
|
"""
|
|
|
|
|
if not isinstance(ident, string_types):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not ident.isascii():
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not ident.isidentifier():
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if keyword.iskeyword(ident):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|