
    Vh+                        d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 dZ
 ej                  dj                  e
dz  e
d	z  e
d
z        ej                  ej                  z        Zd ZddZd Zd Zd Zd Zy)    )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
    )         c                4    d }t         j                  ||       S )Nc                L    t        j                  | j                  d      d      S )Nr   zunicode-escape)codecsdecodegroup)matchs    H/home/dcms/DCMS/lib/python3.12/site-packages/ansible/parsing/splitter.pydecode_matchz%_decode_escapes.<locals>.decode_match)   s    }}U[[^-=>>    )_ESCAPE_SEQUENCE_REsub)sr   s     r   _decode_escapesr   (   s    ? ""<33r   c                    t        | d      } i }| t        |       }g }|D ]  }t        |      }d|v r|d}	 	 |j                  d|dz         }|dkD  r||dz
     dk7  rn'	 |d| }||dz   d }	|r|d	vr|j                  |       ct        |	j                               ||j                         <   |j                  |        t        |      dkD  rt        |      |d
<   |S # t        $ r$ |j                  |j                  dd             Y w xY w)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=r      \z\=)createsremoveschdir
executablewarnstdinstdin_add_newlinestrip_empty_ends_raw_params)r   
split_argsr   index
ValueErrorappendreplacer   striplen	join_args)
args	check_rawoptionsvargs
raw_paramsorig_xxposkvs
             r   parse_kvr8   /   sE    4:.DG4 
 	*F'Aax	ggc3737qqzT'9!  " dsGcAghK   +R  "R%%f-)0);GAGGI&!!&)1	*8 z?Q&/
&;GN#N- "  %%aiis&;<	s   (C  *DDc                z    d}t        |       D ]*  \  }}|dkD  r| |dz
     }|dv s|dk7  s|r	||k(  s&d})|}, |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
    Nr   r   z"'r   )	enumerate)token
quote_char	prev_charidxcur_chars        r   _get_quote_stater@   `   sa     I"5) &X7cAgIud!2z)!%J%
& r   c                r    | j                  |      }| j                  |      }||k7  r|||z
  z  }|dk  rd}|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)r;   	cur_depth
open_tokenclose_tokennum_open	num_closes         r   _count_jinja2_blocksrH   t   sI     {{:&HK(I9h*+	q=Ir   c                r    d}| D ]/  }t        |      dk(  s|j                  d      r||z  }(|d|z   z  }1 |S )z
    Join the original cmd based on manipulations by split_args().
    This retains the original newlines and whitespaces.
     r   
 )r,   endswith)r   resultps      r   r-   r-      sM    
 F v;!vt4aKFcAgF	
 Mr   c                6   | sg S g }| j                  d      }d}d}d}d}d}t        |      D ]  \  }}	|	j                  d      }
d}t        |
      D ]W  \  }}t        |      dk(  r&|dk7  r!|s|j                  d       |dxx   dz  cc<   ;|dk(  r|sd	}E|}t	        ||      }|du}d}|r|s|s|s|s|j                  |       d	}n7|s|s|s|s|r-|dk(  r|r|d   ||d<   nd}|dkD  rd}|d   |||d<   d	}|}t        ||d
d      }||k7  r|s|j                  |       d	}|}t        ||dd      }||k7  r|s|j                  |       d	}|}t        ||dd      }||k7  r|s|j                  |       d	}|r0|r4|r8|r<|r@|dk7  sG|j                  |       Z t        |      dkD  s|t        |      dz
  k7  s|r|s|j                  d       |dxx   dz  cc<    |s|s|s|rt        dj                  |             |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.
    rK   NFr   rL   rJ   r   Tz{{z}}z{%z%}z{#z#}r   zOfailed at splitting arguments, either an unbalanced jinja2 block or quotes: {0})splitr:   r,   r)   r@   rH   r   format)r.   paramsitemsr<   inside_quotesprint_depthblock_depthcomment_depthitemidxitemtokensline_continuationr>   r;   was_inside_quotesappendedspacerprev_print_depthprev_block_depthprev_comment_depths                       r   r&   r&      s     	 F JJtE JMKKM %U+ X$
 C!%f- F	%LS% 5zQ3!8MM"%r
c!

 }]$(! !.)%<J&d2M H %6{^ke$}Qb!8 1+1":u!=F2JFQw!$-3BZ!GF2J  +.uk4NK..xe$*.uk4NK..xe$!.0tTRM 228e$  ;-_glquwlwe$MF	%V u:>gUa7@Qb!2J$JqXx k]m !s!z!z{  "A  B  	BMr   )F)
__future__r   r   reansible.errorsr   +ansible.module_utils.common.text.convertersr   ansible.parsing.quotingr   _HEXCHARcompilerS   UNICODEVERBOSEr   r   r8   r@   rH   r-   r&    r   r   <module>rn      s   $ #  	 - ? +
  bjj "	 
1hlHqL	92::

;RT 4.b(Ir   