
    Vh                    T   U d Z ddlmZ ddlZddlmZ ddlZddlZddlZ	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z( dd	l)m*Z*m+Z+ dd
l,m-Z-m.Z. ddl/m0Z0  ejb                  d      Z2 ejb                  d      Z3 ejb                  d      Z4 ejb                  d      Z5i Z6de7d<   dZ8ejr                  ju                  ejr                  ju                  ejr                  jw                  e<                  Z=ejr                  ju                  e=      Z>ejr                  j                  e>d      Z@dZAejr                  j                  e@      slejr                  ju                  ejr                  ju                  ejr                  ju                  e=                  Z>ejr                  j                  e>dd      Z@e>ZAejr                  j                  e=d      ZCejr                  j                  e=d      ZDejr                  j                  e=d      ZEejr                  j                  eDd      ZFejr                  j                  eDd      ZGejr                  j                  eFd      ZHejr                  j                  eGd      ZIej                  ej                  z  ej                  z  ZMeMZNeNej                  z  ej                  z  ej                  z  ZReNej                  z  ej                  z  ej                  z  ZVeMej                  z  ej                  z  ej                  z  ej                  z  ZWeWej                  z  ej                  z  ZX G d dej                        ZZ G d d      Z[ e\d e[j                  j                         D              Z_ e`d d!d"#       e`d$d%d&d"'       e`d(d)d*+       e`d(d)d"+       e`d d!d,d"-       e`d$d%d&d".      d/Zad0e7d1<   	  e\ea      Zbdsd2Zcdtd3Zde-dud4       Zedvd5Zfdwdxd6Zgdyd7Zhdzd{d8Zid|d}d9Zjedd~d:       Zkdd;Zleddd<       Zm	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd=Zn	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd>Zo G d? d@e.      Zp G dA dBe.ej                  C      Zr G dD dEer      Zs G dF dGer      ZtddHZuddIZvddJZwddKZxddLZyddMZzdddNZ{d~dOZ| G dP dQ      Z} G dR dSe~      Z G dT dUe~      Z G dV dWe~      Z G dX dYe      Z G dZ d[e      Z G d\ d]e      Z G d^ d_e      Zdd`Zedadad"fddbZddcZdddZddeZddfZddgZddhZddiZdddjZddkZddlZddmZddnZddoZddpZddqZddrZ e}       Z el        y)z,Miscellaneous utility functions and classes.    )annotationsN)unpackpack)
TIOCGWINSZ   )LOCALE_WARNINGCONFIGURED_LOCALE)to_bytesto_optional_bytesto_optional_text)open_binary_fileread_text_file)mutexWrappedThread)SUPPORTED_PYTHON_VERSIONSCTBaseTKeyTValuedict[str, str]PYTHON_PATHS
coveragercansiblelib_data_utilconfig
controllertargettoolsc                  \    e Zd ZdZ ej
                         Z ej
                         ZddZy)OutputStreamz^The output stream to use when running a subprocess and redirecting/capturing stdout or stderr.c                    | t         j                  k(  r|S | t         j                  k(  rt        j                  j
                  S t        t        |             )zWReturn the correct output buffer to use, taking into account the given original buffer.)r"   ORIGINALAUTOdisplayfdbufferNotImplementedErrorstr)selforiginals     K/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/util.py
get_bufferzOutputStream.get_bufferp   sD     <(((O<$$$::$$$!#d),,    N)r,   
t.BinaryIOreturnr0   )	__name__
__module____qualname____doc__enumautor$   r%   r.    r/   r-   r"   r"   j   s$    htyy{H499;D	-r/   r"   c                      e Zd ZdZdZdZy)Architecturez
    Normalized architecture names.
    These are the architectures supported by ansible-test, such as when provisioning remote instances.
    x86_64aarch64N)r2   r3   r4   r5   X86_64AARCH64r8   r/   r-   r:   r:   |   s    
 FGr/   r:   c              #  J   K   | ]  \  }}|j                  d       r|  yw)__N)
startswith.0keyvalues      r-   	<genexpr>rF      s#     njc5Y\YgYghlYmEns   ##ia  httpT)ansible_portansible_psrp_protocoluse_passwordib  httpsignore)rH   rI   ansible_psrp_cert_validationrJ      
powershellF)rH   ansible_shell_typerJ   ntlm)rH   ansible_winrm_schemeansible_winrm_transportrJ   )rH   rR   $ansible_winrm_server_cert_validationrJ   )z	psrp+httpz
psrp+httpszssh+keyzssh+passwordz
winrm+httpzwinrm+httpszdict[str, t.Any]WINDOWS_CONNECTION_VARIABLESc                R    | j                         xr t        j                  |        S )z`Return True if the given value is a valid non-keyword Python identifier, otherwise return False.)isidentifierkeyword	iskeyword)rE   s    r-   is_valid_identifierrZ      s$    @(9(9%(@$@@r/   c                x     i t               t        j                          fd       }t        |      }|S )zFEnforce exclusive access on a decorated function and cache the result.c                 L    j                  d      x} u r        x} d<   | S )z!Cache the return value from func.N)get)rE   funcsentinelstorages    r-   
cache_funczcache.<locals>.cache_func   s2     [[x00EX=$(F*EGDMr/   )object	functoolswrapsr   )r^   ra   wrapperr_   r`   s   `  @@r-   cacherf      s;    "$GxH__T  JGNr/   c                B   	 t         j                  }| |v r||    S | t        j                  k(  sMt
        j                  j                  |       t
        j                  j                  t        j                        k(  rt        j                         }n(t        | ddgd      d   }t        j                  |      }t        j                  t        j                  t        j                  t        j                  d}g }t!        |      dk\  r|j#                  |d          t!        |      d	k\  r|j#                  |d          t%        t'        |            }t%        t'        d
 |D cg c]  }|j)                  |       c}D                    }d}|st*        j-                  d|  d|        nOt!        |      dk(  r#|d   }t*        j/                  d| d|  d       nt*        j-                  d| d|  d|        ||| <   |S # t        $ r i x}t         _        Y w xY wc c}w )ztDetect the architecture of the specified Python and return a normalized version, or None if it cannot be determined.-cz;import json, platform; print(json.dumps(platform.uname()));Tcapturer   )r;   amd64r<   arm64         c              3  &   K   | ]	  }|s|  y wNr8   )rC   archs     r-   rF   z&detect_architecture.<locals>.<genexpr>   s     qlptqs   Nz9Unable to determine architecture for Python interpreter "z" from: r   zDetected architecture z for Python interpreter: 	verbosityz$Conflicting architectures detected (z) for Python interpreter ")detect_architectureresultsAttributeErrorsys
executableospathrealpathplatformunameraw_commandjsonloadsr:   r=   r>   lenappendsortedsetr]   r&   warninginfo)	pythonrv   r~   datatranslation
candidates	candidatearchitecturesarchitectures	            r-   ru   ru      s   
3%-- v277#3#3F#;rww?O?OPSP^P^?_#_ FD*ghrvwxyz

4  %%$$''%%	K J
5zQ%(#
5zQ%(#J(J3q]g0hPY1K0hqqrM$(LSTZS[[cdncopq	]	q	 $Q'-l^;TU[T\]ijk>}oMghngoow  yC  xD  E  	F"GFOU  3022%-38 1is   G? !H?HHc                    d}g }| D ]^  }|j                  d      s|r|dz  }d}|j                  dd      }|d   }||v r||   t        |      z
  dz   }N|j                  |       ` |S )z>Return a filtered version of the given command line arguments.r   -r   =)rA   splitr   r   )argsfilters	remainingresultargpartsrD   s          r-   filter_argsr      s    IF ~~c"yNI			#q!Ah'>s5z1A5Ic  Mr/   c                   |r!t         j                  j                  |       sg S t        |       j	                         }|D cg c]  }t        j                  dd|       }}|r|D cg c]  }|s|	 }}|S c c}w c c}w )z
    Returns lines from the specified text file with comments removed.
    Comments are any content from a hash symbol to the end of a line.
    Any spaces immediately before a comment are also removed.
    z *#.*$ )rz   r{   existsr   
splitlinesresub)r{   remove_blank_linesoptionallineslines        r-   read_lines_without_commentsr     su     t,	4 ++-E5:;TRVVIr4(;E;"'0$400L < 1s   A7'A</A<c                B    t        d | j                         D              S )z=Return the provided dictionary with any None values excluded.c              3  0   K   | ]  \  }}|	||f  y wrq   r8   rB   s      r-   rF   z&exclude_none_values.<locals>.<genexpr>)  s     Qeu?PeQ   
	)dictitems)r   s    r-   exclude_none_valuesr   '  s    Qtzz|QQQr/   c                   d}t        j                         }|s|}t         j                  j                  |       rzt         j                  j	                  ||       }t         j                  j                  |      rct        j                  |t         j                  t         j                  z        r-| }n)|8t         j                  j                  dt         j                  j                        }|r|j                  t         j                  j                        }t               }|D ]  }	|	|v r|j                  |	       t         j                  j!                  |	      |k(  r|}	t         j                  j	                  |	|       }
t         j                  j                  |
      s}t        j                  |
t         j                  t         j                  z        s|
} n |s,|r*d| z  }|dk7  rt#        |      t$        j'                  |       |S )a  
    Find the specified executable and return the full path, or None if it could not be found.
    If required is True an exception will be raised if the executable is not found.
    If required is set to 'warning' then a warning will be shown if the executable is not found.
    NPATH Required program "%s" not found.r   )rz   getcwdr{   dirnamejoinr   accessF_OKX_OKenvironr]   defpathr   pathsepr   addabspathApplicationErrorr&   r   )ry   cwdr{   requiredmatchreal_cwdr   	path_dirs	seen_dirspath_dirr   messages               r-   find_executabler   ,  sn    Eyy{H	wwz"c:.77>>&!bii"''8I&JE<::>>&"''//:D

277??3II% y(h'77??8,8"HGGLL:>	77>>),9bggPRPWPWFW1X%E X4zAy "7++ Lr/   c                    t        |       }|s1|t        j                  dt        |       k(  rt        j                  }|S t        d| z  ||      }|S )z
    Find and return the full path to the specified Python version.
    If required, an exception will be raised not found.
    If not required, None will be returned if not found.
    Nzpython%s)r{   r   )str_to_versionrx   version_infor   ry   r   )versionr{   r   r   
python_bins        r-   find_pythonr   ^  sW     "'*LLC$4$45Gc,6G$HH^^
  %Z'%9xX
r/   c                 n    t        t        j                  j                  t        d      d       ddlm}  | S )zReturn the Ansible version.z
release.pyansible_releaser   )__version__)load_modulerz   r{   r   ANSIBLE_LIB_ROOTr   r   )ansible_versions    r-   get_ansible_versionr   n  s*    
 -|<>OP ?r/   c                     t        j                         5  t        j                  d       t        t        j
                  j                  t        dd      d       ddd       y# 1 sw Y   yxY w)zDEnable support for loading Python packages vendored by ansible-core.error_vendorz__init__.pyansible_vendorN)warningscatch_warningsfilterwarningsr   rz   r{   r   r   r8   r/   r-   _enable_vendoringr   {  sT    
 
	 	 	" `(BGGLL!19mLN^_` ` `s   AA##A,c                 <    t        d d t        D        D              S )zMReturn a dictionary indicating which supported Python versions are available.c              3  0   K   | ]  \  }}|s	||f  y wrq   r8   )rC   r   r{   s      r-   rF   z0get_available_python_versions.<locals>.<genexpr>  s%       YMGT  TX$  Yr   c              3  :   K   | ]  }|t        |d       f  yw)F)r   N)r   rC   r   s     r-   rF   z0get_available_python_versions.<locals>.<genexpr>  s$       6PjqwG^c@d6e  6Ps   )r   r   r8   r/   r-   get_available_python_versionsr     s2       Y  6P  vO  6P  Y  Y  Yr/   c                	   |	xs t         j                  }	|r|rt        d      |r|rt        d      |r|rt        d      |r|rt        d      |r|rt        d      |r|st        d      |	t         j                  k7  r|rt        d|	d      |	t         j                  k7  r|rt        d|	d	      |st        j                         }|s
t               }t        |       } t        j                  |       }|rd
}n|rd}nd}|dz  }g }|r|j                  d       |r|j                  d       |r|j                  d       |r|ddj                  |       z  }t        j                  | d| |
d       t        j                  d|z  d       t        | d   ||d   d      }|rt        j                  d|z  d       t        |j                               D ]!  }t        j                  |d||   d       # |ryd}|d }n(|t        j                   }d}n|rnt        j"                  }|sL|xs t        j                   }|s|	t         j$                  k(  rt        j                   nt        j&                  }d}nd }t)        j(                         }d }	 	 | D cg c]  }t+        |       }}t-        d! |j/                         D              }t        j0                  ||||||"      }|rbt7        |      }t9        |||t        j                   k(  |t        j                   k(  ||	$      \  }}t;        ||      xs d%}t;        ||      xs d%}n|j=                          d\  }}|rG|j>                  ;|jA                          t        j                  d%       t        jC                  d&       	 |j>                  }t)        j(                         |z
  } t        j                  d'|d(| d)d*       |dk(  r||fS tE        | |||| |      c c}w # t2        $ r}t5        d#| d   z        |d }~ww xY w# |rH|j>                  ;|jA                          t        j                  d%       t        jC                  d&       w w w xY w)+zBRun the specified command and return stdout and stderr as a tuple.z2Cannot combine capture=True with interactive=True.z*Cannot combine data with interactive=True.z+Cannot combine stdin with interactive=True.z,Cannot combine stdout with interactive=True.zCannot combine stdin with data.zURedirection of stdout requires capture=True to avoid redirection of stderr to stdout.zCannot combine output_stream=z with capture=True.z with interactive=True.RunInteractiveStreamz commandr   stdinstdoutz with /z: T)rt   truncatezWorking directory: %s   rs   r   r   F)r   r{   r   zProgram found: %sr   )NNNc              3  N   K   | ]  \  }}t        |      t        |      f  y wrq   )r
   )rC   kvs      r-   rF   zraw_command.<locals>.<genexpr>  s!     PDAqhqk8A;7Ps   #%)envr   r   stderrr   r   )rj   output_streamr   z]Killed command to avoid an orphaned child process during handling of an unexpected exception.zCommand exited with status z after z	 seconds.rn   )#r"   r%   InternalErrorrz   r   common_environmentlistshlexr   r   r&   r   r   r   keys
subprocessPIPEDEVNULLr$   STDOUTtimer
   r   r   PopenFileNotFoundErrorr   r   communicate_with_processr   wait
returncodekillnoticeSubprocessError)!cmdrj   r   r   r   explainr   r   interactiver   cmd_verbosity
str_errorserror_callbackescaped_cmddescription
with_typesprogramrD   communicater   startprocessr   	cmd_bytes	env_bytesex
data_bytesstdout_bytesstderr_bytesstdout_textstderr_textstatusruntimes!                                    r-   r   r     sh     "6\%6%6M;PQQHIIIJJ+JKK=>>gstt)))g<m-==PQRR)))k<m-==TUVViik "
s)C**S/K	#:KJ&!'"(# 4566LLK=;-0MTXLYLL(3.!L<c!f#CK%PG(72a@chhj! =SX.!<= K			"" *:??$+}@U@U/U[e[l[lIIKEG|	X2563#6I6PCIIKPPI &&yiuU[djpstG *40J)A':W]akapapWprx  }G  }L  }L  sL  V]P]*_&L,*<DJK*<DJKLLN'1$Kw))1LLNLLNNz{FiikE!GLLfgVbcLd{K''
#v{K.
YY; 7 ! 	X"#EA#NOUWW	X w))1LLNLLNNz{ 27s>   P !P3=P 0A9P4 P 	P1P,,P11P4 4AR c                X   g }|rt         }nt        }|%|j                  t        | j                  |             |rL || j
                  |j                  t        j
                  j                              }|j                  |       nd}|rL || j                  |j                  t        j                  j                              }	|j                  |	       nd}	|D ]  }
|
j                           |D ]  }
	 |
j                           t!        |t"              rdj%                  |j&                        }nd}t!        |	t"              rdj%                  |	j&                        }nd}| j)                          ||fS # t        $ r(}t        j                  t        |             Y d}~d}~ww xY w)zRCommunicate with the specified process, handling stdin/stdout/stderr as requested.Nr/   )CaptureThreadOutputThreadr   WriterThreadr   r   r.   rx   r(   r   r	  wait_for_result	Exceptionr&   r   r*   
isinstanceReaderThreadr   r   r   )r
  r   r   r   rj   r   threadsreaderstdout_readerstderr_readerthreadr  r  r  s                 r-   r   r   #  sb    $&G |GMM59:w~~}/G/G

HYHY/Z[}%w~~}/G/G

HYHY/Z[}%   #	#""$# -.xx 3 34-.xx 3 34LLN%%  	#MM#b'""	#s   6E88	F)F$$F)c                  ,     e Zd ZdZd fdZddZ xZS )r  z.Thread to write data to stdin of a subprocess.c                T    t         |   | j                         || _        || _        y rq   )super__init___runhandler   )r+   r'  r   	__class__s      r-   r%  zWriterThread.__init__^  s"    #	r/   c                    	 | j                   j                  | j                         | j                   j                          | j                   j	                          y# | j                   j	                          w xY wzWorkload to run on a thread.N)r'  writer   flushcloser+   s    r-   r&  zWriterThread._rund  sN    	 KKdii(KKKKDKKs   ?A A8)r'  t.IO[bytes]r   bytesr1   Noner1   r1  )r2   r3   r4   r5   r%  r&  __classcell__r(  s   @r-   r  r  [  s    8 r/   r  c                  J     e Zd ZdZd fdZej                  dd       Z xZS )r  z(Thread to read stdout from a subprocess.c                b    t         |   | j                         || _        || _        g | _        y rq   )r$  r%  r&  r'  r(   r   )r+   r'  r(   r(  s      r-   r%  zReaderThread.__init__p  s)    #"$
r/   c                     yr*  r8   r.  s    r-   r&  zReaderThread._runw  s    r/   )r'  r/  r(   r0   r1   r1  r2  )	r2   r3   r4   r5   r%  abcabstractmethodr&  r3  r4  s   @r-   r  r  m  s%    2% 	+ +r/   r  )	metaclassc                      e Zd ZdZddZy)r  z9Thread to capture stdout from a subprocess into a buffer.c                    | j                   }| j                  }	 |D ]  }|j                  |        	 |j                          y# |j                          w xY wr*  )r'  r   r   r-  r+   srcdstr   s       r-   r&  zCaptureThread._run  sI    kkjj	 !

4 ! IIKCIIKs   A ANr2  r2   r3   r4   r5   r&  r8   r/   r-   r  r  |  s
    C	r/   r  c                      e Zd ZdZddZy)r  z2Thread to pass stdout from a subprocess to stdout.c                    | j                   }| j                  }	 |D ]#  }|j                  |       |j                          % 	 |j	                          y# |j	                          w xY wr*  )r'  r(   r+  r,  r-  r=  s       r-   r&  zOutputThread._run  sQ    kkkk	 		$		 IIKCIIKs   (A A&Nr2  r@  r8   r/   r-   r  r    s
    <
r/   r  c                 6   t        t        t        j                  j	                  dt        j
                  j                              } d}d}t        j
                  j                  d      r| j                  d       | j                  t        ||             | S )	z3Common environment used for executing all programs.r   )LC_ALLr   )HOME)LD_LIBRARY_PATHSSH_AUTH_SOCK#OBJC_DISABLE_INITIALIZE_FORK_SAFETYANSIBLE_KEEP_REMOTE_FILESLDFLAGSCFLAGSz/etc/freebsd-update.confz-I/usr/local/include/)rK  )r   r   )
r   r	   rz   r   r]   r{   r   r   update	pass_vars)r   r   r   s      r-   r   r     sq    
 ZZ^^FBGGOO4C
HH0 
ww~~01

1
2JJy(X>?Jr/   c                    t         j                  dt         d       t        r| rt         j	                  t               yyy)zCReport the configured locale and the locale warning, if applicable.zConfigured locale: r   rs   N)r&   r   r	   r   r   )show_warnings    r-   report_localerP    s6     LL&'8&9:aLH,' '~r/   c                    i }| D ]5  }|t         j                  vrt        |      t         j                  |   ||<   7 |D ]+  }|t         j                  vrt         j                  |   ||<   - |S )zWReturn a filtered dictionary of environment variables based on the current environment.)rz   r   MissingEnvironmentVariable)r   r   r   names       r-   rM  rM    sx    
C %rzz!,T22JJt$D	%
  %rzz!JJt$D	%
 Jr/   c                    t        j                  |        t        fdt        j                  t        j
                  t        j                  fD              }|r4t        j                  | t         j                        st        d|  d      yy)zQPerform chmod on the specified path and then verify the permissions were applied.c              3  (   K   | ]	  }|z    y wrq   r8   )rC   permmodes     r-   rF   z!verified_chmod.<locals>.<genexpr>  s     XTTD[Xs   zPath "zT" should executable, but is not. Is the filesystem mounted with the "noexec" option?N)
rz   chmodanystatS_IXUSRS_IXGRPS_IXOTHr   r   r   )r{   rW  ry   s    ` r-   verified_chmodr^    sp    HHT4XdllDLL$,,-WXXJ"))D"''2v  .B   C  D  	D 3zr/   c                `    	 t        j                  t        |              y# t        $ r Y yw xY w)zTRemove the specified directory, silently continuing if the directory does not exist.N)shutilrmtreer
   r   )r{   s    r-   remove_treerb    s)    htn% s   ! 	--c                    h d}h d}t         j                  j                  |       d   }||v ry||v ryt        |       5 }d|j	                  d      v cddd       S # 1 sw Y   yxY w)	zKReturn True if the specified file is a binary file, otherwise return False.>   .cs.j2.js.md.sh.cfg.crt.css.ini.pem.ps1.rst.txt.xml.yml.conf.html.json.psm1.yaml.py>   .gz.bin.eot.ico.iso.jpg.otf.p12.png.pyc.rpm.ttf.zip.woff.woff2r   FT    i   N)rz   r{   splitextr   read)r{   assume_textassume_binaryextpath_fds        r-   is_binary_filer    sq    K0M$ ''

4
 
#C
k
m	$	 +7T**+ + +s    AA&c                D    dj                  d t        |       D              S )z"Generate and return a random name.r   c              3     K   | ]8  }t        j                  t        j                  t        j                  z          : y wrq   )randomchoicestringascii_lettersdigits)rC   _idxs     r-   rF   z generate_name.<locals>.<genexpr>,  s(     a46==!5!5!EFas   >A )r   range)lengths    r-   generate_namer  *  s    77aSXY_S`aaar/   c                 <   t         j                  t         j                  t         j                  t         j                  dgdz  } dj                  | dd D cg c]  }t	        j
                  |       c}      }t        j                  j                  |       |S c c}w )z$Generate and return random password.r   rn   r   N)	r  r  r  r   r  r  r&   	sensitiver   )charscharpasswords      r-   generate_passwordr  /  s     	 	

E wwcr
Cd+CDH(#O	 Ds   Bc                      e Zd ZdZdZdZdZdZdZdZ	dZ
d	eee
d
ZddZddZddZdddZddZddZddZdddZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZy	)DisplayzManages color console output.z[0mz[31mz[32mz[33mz[34mz[35mz[36mN)r   r   r      c                   d| _         t        j                  j                         | _        g | _        t               | _        t        j                  | _	        d| _
        d| _        d| _        d| _        t               | _        t        j                  d      rCt!        dt#        j$                  dt&        t)        ddddd                  d d \  | _
        | _        y y )Nr   THHHHr   )rt   rx   r   isattycolorr   r   warnings_uniquer   r'   rowscolumnsr   redactr  rz   r   fcntlioctlr   r   r.  s    r-   r%  zDisplay.__init__R  s    ZZ&&(
#%),**	#&599Q<&,VU[[JPTU[]^`acdfgPh5i&jkmlm&n#DIt| r/   c                D    | j                  d|z  | j                         y)z9Internal implementation for displaying a warning message.zWARNING: %sr  Nprint_messagepurpler+   r   s     r-   	__warningzDisplay.__warninga  s    =72$++Fr/   c                    | j                   sy| j                  dt        | j                         z         | j                   D ]  }| j                  |        y)z.Review all warnings which previously occurred.Nz!Reviewing previous %d warning(s):)r   _Display__warningr   )r+   r   s     r-   review_warningszDisplay.review_warningse  sF    }}:S=OOP}} 	$GNN7#	$r/   c                    || j                   kD  ry|r*|| j                  v ry| j                  j                  |       | j                  |       | j                  j                  |       y)z Display a warning level message.N)rt   r  r   r  r   r   )r+   r   uniquert   s       r-   r   zDisplay.warningo  sW    t~~%$...  $$W-wW%r/   c                D    | j                  d|z  | j                         y)zDisplay a notice level message.z
NOTICE: %sr  Nr  r  s     r-   r   zDisplay.notice}  s    <'1Er/   c                D    | j                  d|z  | j                         y)zDisplay an error level message.z	ERROR: %sr  Nr  redr  s     r-   r   zDisplay.error  s    ;0Ar/   c                F    | j                  d|z  | j                  d       y)zDisplay a fatal level message.z	FATAL: %sT)r  r   Nr  r  s     r-   fatalzDisplay.fatal  s     ;0Nr/   c                    | j                   |k\  r;| j                  j                  || j                        }| j	                  |||       yy)zDisplay an info level message.)r  r   N)rt   verbosity_colorsr]   yellowr  )r+   r   rt   r   r  s        r-   r   zDisplay.info  sD    >>Y&))--iEEwehG 'r/   c                   | j                   r>| j                  r2| j                  D ]#  }|s|j                  |dt        |      z        }% |r6t        |      | j                  cxkD  rdkD  rn n|d| j                  dz
   dz   }|r:| j
                  r.|j                  | j                  |      }||| j                  }|rt        j                  n| j                  }t        ||       |j                          y)zDisplay a message.*rm   Nz ...)file)r  r  replacer   r   r  clearrx   r   r'   printr,  )r+   r   r  r   r   itemr'   s          r-   r  zDisplay.print_message  s     ;;4>> A!//$c$i@	A 7|dmm/a/!"44==1#45>TZZoodjj%8G"'$**=G!SZZtwwgB

r/   r2  r   r*   r1   r1  )Fr   )r   r*   r  boolrt   intr1   r1  )r   F)r   r*   rt   r  r   r  r1   r1  )NFF)
r   r*   r  t.Optional[str]r   r  r   r  r1   r1  )r2   r3   r4   r5   r  r  greenr  bluer  cyanr  r%  r  r  r   r   r   r  r   r  r8   r/   r-   r  r  @  s    'E
CEFDFD 	oG$&FBOH "&  	
  
r/   r  c                  $     e Zd ZdZd fdZ xZS )r   z9An unhandled internal error indicating a bug in the code.c                *    t         |   d|        y )Nz0An internal error has occurred in ansible-test: )r$  r%  )r+   r   r(  s     r-   r%  zInternalError.__init__  s    KG9UVr/   r  r2   r3   r4   r5   r%  r3  r4  s   @r-   r   r     s    CW Wr/   r   c                      e Zd ZdZy)r   zGeneral application error.Nr2   r3   r4   r5   r8   r/   r-   r   r     s    $r/   r   c                      e Zd ZdZy)ApplicationWarningzAGeneral application warning which interrupts normal program flow.Nr  r8   r/   r-   r  r    s    Kr/   r  c                      e Zd ZdZy)TimeoutExpiredErrorz@Error raised when the test timeout has been reached or exceeded.Nr  r8   r/   r-   r  r    s    Jr/   r  c                  J     e Zd ZdZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   z1Error resulting from failed subprocess execution.c                4   dt        j                  |      d|d}|t        ||      z  }|| _        || _        || _        || _        || _        || _        |r ||        | j                  j                         | _        t        | -  | j                         y )Nz	Command "z" returned exit status z.
)r   r   format_command_outputr   r   r  r   r   r  stripr$  r%  )	r+   r   r  r   r   r  r  r   r(  s	           r-   r%  zSubprocessError.__init__  s     @Ezz#PVW(884 ||))+&r/   )r   NNNN)r   	list[str]r  r  r   r  r   r  r  zt.Optional[float]r  /t.Optional[c.Callable[[SubprocessError], None]]r1   r1  r  r4  s   @r-   r   r     sf    ;
 "&"&%)JN'' '  	'
  ' #' H' 
' 'r/   r   c                  $     e Zd ZdZd fdZ xZS )rR  z-Error caused by missing environment variable.c                8    t         |   d|z         || _        y )Nz Missing environment variable: %s)r$  r%  rS  )r+   rS  r(  s     r-   r%  z#MissingEnvironmentVariable.__init__  s    ;dBC	r/   )rS  r*   r1   r1  r  r4  s   @r-   rR  rR    s    7 r/   rR  c                  .     e Zd ZdZdd fdZddZ xZS )HostConnectionErrora  
    Raised when the initial connection during host profile setup has failed and all retries have been exhausted.
    Raised by provisioning code when one or more provisioning threads raise this exception.
    Also raised when an SSH connection fails for the shell command.
    c                2    t         |   |       || _        y rq   )r$  r%  	_callback)r+   r   callbackr(  s      r-   r%  zHostConnectionError.__init__  s    !!r/   c                >    | j                   r| j                          yy)zRun the error callback, if any.N)r  r.  s    r-   run_callbackz HostConnectionError.run_callback  s    >>NN r/   rq   )r   r*   r  zt.Callable[[], None]r1   r1  r2  )r2   r3   r4   r5   r%  r  r3  r4  s   @r-   r  r    s    "
r/   r  c                    d}|r/|j                         x}r|dz  }|| t        j                   dz  }| r/| j                         x} r|dz  }||  t        j                   dz  }|S )zJReturn a formatted string containing the given stdout and stderr (if any).r   z>>> Standard Error

z>>> Standard Output
)r  r  r  )r   r   r   s      r-   r  r    sz    GV\\^+6+))fXgmm_B//V\\^+6+**fXgmm_B//Nr/   
   c                    t        d|      D ]  }	  |        c S   |        S # |$ r?}|rt        j                  t        |             t	        j
                  |       Y d}~Td}~ww xY w)z(Retry the specified function on failure.r   N)r  r&   r   r*   r   sleep)r^   ex_typer  attemptswarndummyr  s          r-   retryr    sa    q(# 	6M 6M  	B(JJu		s   "A&5A!!A&c                   g }g }|j                         D ]K  }t        j                  | |      }|r |j                  |j	                                ;|j                  |       M |r t        d| ddj                  |            |S )zzParse lines from the given value using the specified pattern and return the extracted list of key/value pair dictionaries.z	Pattern "z" did not match values:
r  )r   r   searchr   	groupdictr  r   )patternrE   matched	unmatchedr   r   s         r-   parse_to_list_of_dictr    s|    GI  " #		'4(NN5??,-T"# GTYYW`MabccNr/   c                   t               }| g}|rd|j                         }|j                         D ]>  }||vst        j                  |      s|j                  |       |j                  |       @ |rdt        |d       S )zGReturns a list of types that are concrete subclasses of the given type.c                    | j                   S rq   )r2   )scs    r-   <lambda>z get_subclasses.<locals>.<lambda>7  s
    R[[ r/   )rD   )r   pop__subclasses__inspect
isabstractr   r   r   )
class_type
subclassesqueueparentchilds        r-   get_subclassesr  )  sy    !$J(\E
**, 	$EJ&))%0NN5)U#		$  *"899r/   c                <   |j                  t        j                  j                        s|t        j                  j                  z  }| j                  t        j                  j                        s| t        j                  j                  z  } | j	                  |      S )zAReturns true if candidate_path is path or a subdirectory of path.)endswithrz   r{   seprA   )candidate_pathr{   s     r-   	is_subdirr  :  sa    ==%""277;;/"''++%$$T**r/   c                   t               }| D ]n  }	 t        j                  j                  |      }|r|t        j                  j                  k(  rC|j                  |t        j                  j                  z          l t        |      S )zEReturns a list of directories extracted from the given list of paths.)r   rz   r{   r   r  r   r   )paths	dir_namesr{   s      r-   paths_to_dirsr  E  sm    I .77??4(D4277;;.MM$,- . )r/   c                D    t        d | j                  d      D              S )z-Return a version tuple from a version string.c              3  2   K   | ]  }t        |        y wrq   )r  rC   ns     r-   rF   z!str_to_version.<locals>.<genexpr>W  s     4AQ4   .)tupler   r   s    r-   r   r   U  s    4s!3444r/   c                2    dj                  d | D              S )z-Return a version string from a version tuple.r  c              3  2   K   | ]  }t        |        y wrq   r*   r  s     r-   rF   z!version_to_str.<locals>.<genexpr>\  s     ,qCF,r  )r   r  s    r-   version_to_strr  Z  s    88,G,,,r/   c                ^    t        d | D              D cg c]  }t        |       c}S c c}w )z3Return a sorted copy of the given list of versions.c              3  2   K   | ]  }t        |        y wrq   )r   r   s     r-   rF   z"sorted_versions.<locals>.<genexpr>a  s     9jV].:Q9jr  )r   r  )versionsr   s     r-   sorted_versionsr!  _  s'    399jai9j3jkN7#kkks   *c                .   |#t         j                  j                  t              }t         j                  j	                  ||       }t
        j                  dd      d   }|d| j                  t         j                  j                  d      d}t        j                  |g|      D ]l  \  }}}t         j                  j	                  ||t        |      dz   d j                  dt         j                  j                        dz         }t        ||       n y)z
    Import plugins from the given directory relative to the given root.
    If the root is not provided, the 'lib' directory for the test runner will be used.
    Nr  r   r   )prefixrx  )rz   r{   r   __file__r   r2   rsplitr  r  pkgutiliter_modulesr   r   )		directoryrootr{   packager#  _module_loaderrS  _ispkgmodule_paths	            r-   import_pluginsr.  d  s    
 |wwx(77<<i(Dooc1%a(G )"3"3BGGKK"EFF*1*>*>vf*U '&vggll4c'lQ.>.?)@)H)Hbggkk)Z]b)bcK&'r/   c                X    t        d t        |       D              }|D ]
  }||   ||<    y)z
    Load plugins of the specified type and track them in the specified database.
    Only plugins which have already been imported will be loaded.
    c              3  ^   K   | ]%  }|j                   j                  d d      d   |f ' yw)r  r   N)r3   r%  )rC   r  s     r-   rF   zload_plugins.<locals>.<genexpr>z  s,     (sSU"--*>*>sA*Fq*I2)N(ss   +-N)r   r  )	base_typedatabasepluginsplugins       r-   load_pluginsr5  u  s8    
 %)(sYghqYr(s$sG +"6?+r/   c                   |t         j                  v ryt        j                  j	                  ||       }t        j                  j                  |      }|t         j                  |<   |j                  j                  |       y)z3Load a Python module using the given name and path.N)rx   modules	importlibutilspec_from_file_locationmodule_from_specloaderexec_module)r{   rS  specmodules       r-   r   r     s[    s{{>>11$=D^^,,T2FCKKKKF#r/   c                T    t        j                  dd|       dd j                  d      S )zMReturn a sanitized version of the given name, suitable for use as a hostname.z[^A-Za-z0-9]+r   N?   )r   r   r  )rS  s    r-   sanitize_host_namerB    s'    66/3-cr288==r/   c                l    t        j                  | j                  d         d   }t        ||      rdS |S )zReturn the generic type arg derived from the generic_base_type type that is associated with the base_type type, if any, otherwise return None.r   N)tget_args__orig_bases__r  )r1  generic_base_typetype_args      r-   get_generic_typerI    s7     zz)22156q9Hh(9:4HHr/   c                    t        |       D cg c]  }t        ||      |f c}D cg c]
  }|d   s	| c}S c c}w c c}w )z{Create and return a list of tuples associating generic_base_type derived types with a corresponding base_type derived type.r   )r  rI  )r1  rG  sc_typer  s       r-   get_type_associationsrL    sZ    est}e~Za/9JKWU  LT  DH  IJ  DKD  L  L  Ls   :
??c                N    t        | |      D ci c]  }|d   |d    c}S c c}w )zZCreate and return a mapping of generic_base_type derived types to base_type derived types.r   r   )rL  )r1  rG  r  s      r-   get_type_maprN    s+    )>yJ[)\]DGT!W]]]s   "c                   | t         j                  k(  ryt        j                  j	                  |       t        j                  j	                  t         j                        k(  ryt        | ddgd      d   }|t         j                  k(  ry|S )z~Verify that the given path references the current Python interpreter. If not, return the expected path, otherwise return None.Nrh   z!import sys; print(sys.executable)Tri   r   )rx   ry   rz   r{   r|   r   )r{   expected_executables     r-   verify_sys_executablerQ    so    s~~	ww!1!1#..!AA%tT3V&Waefghicnn,r/   c                    t        fd| D              }|syt        d |D              }t        d ddj                  |             )z
    Raises an exception if any item in the given sequence does not match the specified guard type.
    Use with assert so that type checkers are aware of the type guard.
    c              3  N   K   | ]  }t        |      rt        |        y wrq   )r  type)rC   r  
guard_types     r-   rF   ztype_guard.<locals>.<genexpr>  s     \tz$PZ?[T
\s   %%Tc              3  2   K   | ]  }t        |        y wrq   r  )rC   r  s     r-   rF   ztype_guard.<locals>.<genexpr>  s     DdD	Dr  z"Sequence required to contain only z includes: z, )r   r   r  r   )sequencerU  invalid_typesinvalid_type_namess    `  r-   
type_guardrZ    sS    
 \x\\MDmDD
8KPTPYPYZlPmOno
ppr/   )rE   r*   r1   r  )r^   c.Callable[[], TValue]r1   r[  )r   r*   r1   r  )r   r  r   zdict[str, int]r1   r  )FF)r{   r*   r   r  r   r  r1   r  )r   zdict[TKey, t.Optional[TValue]]r1   zdict[TKey, TValue])NNT)
ry   r*   r   r  r{   r  r   zt.Union[bool, str]r1   r  )NT)r   r*   r{   r  r   r  r1   r  )r1   r*   r2  )r1   r   )NNNFNNFNr   strictN)r   zc.Iterable[str]rj   r  r   zt.Optional[dict[str, str]]r   r  r   r  r   r  r   %t.Optional[t.Union[t.IO[bytes], int]]r   r]  r   r  r   zt.Optional[OutputStream]r  r  r  r*   r  r  r1   z'tuple[t.Optional[str], t.Optional[str]])r
  zsubprocess.Popenr   zt.Optional[bytes]r   r  r   r  rj   r  r   r"   r1   ztuple[bytes, bytes])rO  r  r1   r1  )r   c.Collection[str]r   r^  r1   r   )r{   r*   rW  r  r1   r1  )r{   r*   r1   r1  )r{   r*   r1   r  )   )r  r  r1   r*   )r   
str | Noner   r`  r1   r*   )r^   zt.Callable[..., TValue]r  zt.Type[BaseException]r  r  r  r  r  r  r1   r   )r  r*   rE   r*   r1   zlist[dict[str, str]])r  	t.Type[C]r1   zlist[t.Type[C]])r  r*   r{   r*   r1   r  )r  r  r1   r  )r   r*   r1   tuple[int, ...])r   rb  r1   r*   )r   r  r1   r  rq   )r(  r*   r)  r  r1   r1  )r1  ra  r2  zdict[str, t.Type[C]]r1   r1  )r{   r*   rS  r*   r1   r1  )rS  r*   r1   r*   )r1  zt.TyperG  t.Type[TValue]r1   zt.Optional[t.Type[TValue]])r1  t.Type[TBase]rG  rc  r1   z*list[tuple[t.Type[TValue], t.Type[TBase]]])r1  rd  rG  rc  r1   z#dict[t.Type[TValue], t.Type[TBase]])r{   r*   r1   r  )rW  zc.Sequence[t.Any]rU  ra  r1   zt.TypeGuard[c.Sequence[C]])r5   
__future__r   r8  collections.abccr6   r  importlib.utilr8  r  r   rX   rz   r}   r&  r  r   r`  rZ  r  r   rx   r   rc   r   typingrD  r   structr   r   termiosr   locale_utilr   r	   encodingr
   r   r   ior   r   r!  r   r   	constantsr   TypeVarr   r   r   r   r   __annotations__COVERAGE_CONFIG_NAMEr{   r   r   r$  ANSIBLE_TEST_ROOTANSIBLE_ROOTr   r   ANSIBLE_SOURCE_ROOTr   ANSIBLE_TEST_DATA_ROOTANSIBLE_TEST_UTIL_ROOTANSIBLE_TEST_CONFIG_ROOTANSIBLE_TEST_CONTROLLER_ROOTANSIBLE_TEST_TARGET_ROOTANSIBLE_TEST_TOOLS_ROOTANSIBLE_TEST_TARGET_TOOLS_ROOTS_IRUSRS_IRGRPS_IROTH	MODE_READ	MODE_FILEr[  r\  r]  MODE_FILE_EXECUTES_IWUSRS_IWGRPS_IWOTHMODE_FILE_WRITEMODE_DIRECTORYMODE_DIRECTORY_WRITEEnumr"   r:   r   __dict__r   REMOTE_ARCHITECTURESr   rU   WINDOWS_CONNECTIONSrZ   rf   ru   r   r   r   r   r   r   r   r   r   r   r  ABCMetar  r  r  r   rP  rM  r^  rb  r  r  r  r  r  r   r   r  
SystemExitr  r   rR  r  r  r  r  r  r  r  r   r  r!  r.  r5  r   rB  rI  rL  rN  rQ  rZ  r&   r8   r/   r-   <module>r     sf   2 " 
        	    	     
       

 

 AIIcN		'qyy	8	!n !# GGOOBGGOOBGGOOH4M$NO  ww0177<<i8  	ww~~&'77??277??277??CT3U#VWLww||L%C&&7A &7A 77<<(98D !ww||,BLQ 77<<(>I '',,'CWM !#.F!P  LL4<<'$,,6		,t||;dllJ dll*T\\9DLLHT\\)DLL84<<G$,,V%4t||C -499 -$  nL4I4I4O4O4Qnn  $
 %%-	 '
 '
 # &	 $-5	9"2 . "F Q78 A
$ 0 0f0&R
/d  	 	` Y Y '+ 3748.2FJTZ	TZTZ 
$TZ 	TZ
 
TZ TZ 1TZ 2TZ TZ ,TZ TZ TZ DTZ -TZn5&5&5& 5& 	5&
 5&  5& 5&p =  $+=CKK +L <  (V("D5+pb
"j jZWI W%y %L LK* K'& '<!1 * $ KZhj|~  NR &:"+ 5
-
l
'"+$>
IL
^
 q )  r/   