a ì)gV,ã@s°ddlmZmZmZeZddlZddlZddlm Z ddl m Z ddl m Z dZe d eded ed ¡ejejB¡Zd d „Zddd„Zdd„Zdd„Zdd„Zdd„ZdS)é)Úabsolute_importÚdivisionÚprint_functionN)Ú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 | d¡d¡S)Nrzunicode-escape)ÚcodecsÚdecodeÚgroup)Úmatch©rú.decode_match)Ú_ESCAPE_SEQUENCE_REÚsub)ÚsrrrrÚ_decode_escapes*srFc Cst|dd}i}|durŒz t|ƒ}WnrtyV}ztd|d‚WYd}~nLd}~0ty˜}z,dt|ƒ ¡vr‚td|d‚n‚WYd}~n d}~00g}|D]Î}t|ƒ}d|vrfd } z0| d| d ¡} | d kr¾|| d d kr¾qêq¾Wn*ty|  |  d d¡¡Yq¢Yn0|d| …} || d d…} |rP| d vrP|  |¡nt |   ¡ƒ||   ¡<q¢|  |¡q¢t |ƒd krŒt|ƒ|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. Zpassthru)Z nonstringNzUnable to parse argument string)Zorig_exczno closing quotationz;error parsing argument string, try quoting the entire line.ú=réú\z\=)ZcreatesZremovesÚchdirÚ executableÚwarnÚstdinZstdin_add_newlineZstrip_empty_endsZ _raw_params)rÚ split_argsÚ IndexErrorrÚ ValueErrorÚstrÚlowerrÚindexÚappendÚreplacerÚstripÚlenÚ join_args) ÚargsZ check_rawÚoptionsZvargsÚeÚveZ raw_paramsZorig_xÚxÚposÚkÚvrrrÚparse_kv1s@          r0cCsTd}t|ƒD]B\}}|dkr(||d}|dvr |dkr |rJ||krNd}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_charZ prev_charÚidxZcur_charrrrÚ_get_quote_statejs r5cCs8| |¡}| |¡}||kr4|||7}|dkr4d}|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)r2Z cur_depthZ open_tokenZ close_tokenZnum_openZ num_closerrrÚ_count_jinja2_blocks~s   r7cCs>d}|D]0}t|ƒdks"| d¡r,||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)rÚresultÚprrrr's  r'cCstg}| d¡}d}d}d}d}d}t|ƒD]\}} |  d¡} d} t| ƒD]À\} } t| ƒdkrz| dkrz|dd7<qJ| dkrŒ|sŒd} qJ|}t| |ƒ}|du}d}|rÊ|sÊ|sÊ|sÊ|sÊ| | ¡d}nŒ|sà|sà|sà|sà|rV| dkr|rd |d| f|d<nLt| ƒd kr>d }| dkr&d}d |d|| f|d<nd |d| f|d<d}|}t| |ddƒ}||kr†|s†| | ¡d}|}t| |ddƒ}||kr¶|s¶| | ¡d}|}t| |ddƒ}||kræ|sæ| | ¡d}|sJ|sJ|sJ|sJ|sJ| d krJ| | ¡qJt|ƒd krD|t|ƒd krD| sD|dd7<d} q*|sb|sb|sb|rptd |¡ƒ‚|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. r9NFrr:éÿÿÿÿrTz%s%srr8z%s%s%sz%s %sz{{z}}z{%z%}z{#z#}zOfailed at splitting arguments, either an unbalanced jinja2 block or quotes: {0})Úsplitr1r&r5r#r7rÚformat)r(ÚparamsÚitemsr3Z inside_quotesZ print_depthZ block_depthZ comment_depthZitemidxÚitemÚtokensZline_continuationr4r2Zwas_inside_quotesZappendedZspacerZprev_print_depthZprev_block_depthZprev_comment_depthrrrr›sr          &r)F)Z __future__rrrÚtypeZ __metaclass__r ÚreZansible.errorsrZansible.module_utils._textrZansible.parsing.quotingrZ_HEXCHARÚcompiler@ÚUNICODEÚVERBOSErrr0r5r7r'rrrrrÚs$   ú ú  9