diff options
Diffstat (limited to 'lib/ansible/parsing/splitter.py')
-rw-r--r-- | lib/ansible/parsing/splitter.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/ansible/parsing/splitter.py b/lib/ansible/parsing/splitter.py index b68444fe..bed10c18 100644 --- a/lib/ansible/parsing/splitter.py +++ b/lib/ansible/parsing/splitter.py @@ -23,7 +23,7 @@ import codecs import re from ansible.errors import AnsibleParserError -from ansible.module_utils._text import to_text +from ansible.module_utils.common.text.converters import to_text from ansible.parsing.quoting import unquote @@ -58,15 +58,7 @@ def parse_kv(args, check_raw=False): options = {} if args is not None: - try: - vargs = split_args(args) - except IndexError as e: - raise AnsibleParserError("Unable to parse argument string", orig_exc=e) - except ValueError as ve: - if 'no closing quotation' in str(ve).lower(): - raise AnsibleParserError("error parsing argument string, try quoting the entire line.", orig_exc=ve) - else: - raise + vargs = split_args(args) raw_params = [] for orig_x in vargs: @@ -168,6 +160,9 @@ def split_args(args): how Ansible needs to use it. ''' + if not args: + return [] + # the list of params parsed out of the arg string # this is going to be the result value when we are done params = [] @@ -204,6 +199,10 @@ def split_args(args): # Empty entries means we have subsequent spaces # We want to hold onto them so we can reconstruct them later if len(token) == 0 and idx != 0: + # Make sure there is a params item to store result in. + if not params: + params.append('') + params[-1] += ' ' continue @@ -235,13 +234,11 @@ def split_args(args): elif print_depth or block_depth or comment_depth or inside_quotes or was_inside_quotes: if idx == 0 and was_inside_quotes: params[-1] = "%s%s" % (params[-1], token) - elif len(tokens) > 1: + else: spacer = '' if idx > 0: spacer = ' ' params[-1] = "%s%s%s" % (params[-1], spacer, token) - else: - params[-1] = "%s\n%s" % (params[-1], token) appended = True # if the number of paired block tags is not the same, the depth has changed, so we calculate that here @@ -273,10 +270,11 @@ def split_args(args): # one item (meaning we split on newlines), add a newline back here # to preserve the original structure if len(items) > 1 and itemidx != len(items) - 1 and not line_continuation: - params[-1] += '\n' + # Make sure there is a params item to store result in. + if not params: + params.append('') - # always clear the line continuation flag - line_continuation = False + params[-1] += '\n' # If we're done and things are not at zero depth or we're still inside quotes, # raise an error to indicate that the args were unbalanced |