o nnh +@sddlmZddlZddlZddlmZddlmZddlm Z dZ e d e de d e d ej ejBZd d ZdddZddZddZddZddZdS)) annotationsN)AnsibleParserError)to_text)unquotez [a-fA-F0-9]z ( \\U{0} # 8-digit hex escapes | \\u{1} # 4-digit hex escapes | \\x{2} # 2-digit hex escapes | \\N\{{[^}}]+\}} # Unicode characters by name | \\[\\'"abfnrtv] # Single-character escapes )cCsdd}t||S)NcSst|ddS)Nrzunicode-escape)codecsdecodegroup)matchr C/usr/local/lib/python3.10/dist-packages/ansible/parsing/splitter.py decode_match)sz%_decode_escapes..decode_match)_ESCAPE_SEQUENCE_REsub)srr r r_decode_escapes(s rFc Cs t|dd}i}|durt|}g}|D]b}t|}d|vrqd}z |d|d}|dkr7||ddkr7nq"WntyK||d dYqw|d|}||dd} |rf|d vrf||qt| ||<q||qt |dkrt ||d <|S) a Convert a string of key/value items to a dict. If any free-form params are found and the check_raw option is set to True, they will be added to a new parameter called '_raw_params'. If check_raw is not enabled, they will simply be ignored. passthru) nonstringN=rT\z\=)createsremoveschdir executablewarnstdinstdin_add_newlinestrip_empty_ends _raw_params) r split_argsrindex ValueErrorappendreplacerstriplen join_args) args check_rawoptionsvargs raw_paramsorig_xxposkvr r rparse_kv/s:        r4cCsTd}t|D]!\}}|dkr||d}|dvr'|dkr'|r%||kr$d}q|}q|S)z the goal of this block is to determine if the quoted string is unterminated in which case it needs to be put back together Nrrz"'r) enumerate)token quote_char prev_charidxcur_charr r r_get_quote_state`s r;cCs8||}||}||kr|||7}|dkrd}|S)z this function counts the number of opening/closing blocks for a given opening/closing type and adjusts the current depth for that block based on the difference r)count)r6 cur_depth open_token close_tokennum_open num_closer r r_count_jinja2_blocksts   rBcCs>d}|D]}t|dks|dr||7}q|d|7}q|S)z Join the original cmd based on manipulations by split_args(). This retains the original newlines and whitespaces. r  )r(endswith)rresultpr r rr)s  r)cCsZ|sgSg}|d}d}d}d}d}d}t|D]\}} | d} d} t| D]\} } t| dkrF| dkrF|s=|d|dd7<q(| dkrO|sOd } q(|}t| |}|du}d}|rn|sn|sn|sn|sn|| d }n0|sx|sx|sx|sx|r| dkr|rd |d| f|d<nd}| dkrd}d |d|| f|d<d }|}t| |d d }||kr|s|| d }|}t| |dd}||kr|s|| d }|}t| |dd}||kr|s|| d }|s|s|s|s|s| dkr|| q(t|dkr|t|dkr| s|s|d|dd7<q|s$|s$|s$|r+td||S)a Splits args on whitespace, but intelligently reassembles those that may have been split over a jinja2 block or quotes. When used in a remote module, we won't ever have to be concerned about jinja2 blocks, however this function is/will be used in the core portions as well before the args are templated. example input: a=b c="foo bar" example output: ['a=b', 'c="foo bar"'] Basically this is a variation shlex that has some more intelligence for how Ansible needs to use it. rDNFrrErCrTz%s%sz%s%s%sz{{z}}z{%z%}z{#z#}rzOfailed at splitting arguments, either an unbalanced jinja2 block or quotes: {0})splitr5r(r%r;rBrformat)r*paramsitemsr7 inside_quotes print_depth block_depth comment_depthitemidxitemtokensline_continuationr9r6was_inside_quotesappendedspacerprev_print_depthprev_block_depthprev_comment_depthr r rr"s|               & r")F) __future__rr reansible.errorsr+ansible.module_utils.common.text.convertersransible.parsing.quotingr_HEXCHARcompilerKUNICODEVERBOSErrr4r;rBr)r"r r r rs      1