o nnhȓ@sUdZddlmZddlZddlmZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddl m!Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(dd l)m*Z*m+Z+dd l,m-Z-m.Z.dd l/m0Z0e1d Z2e1d Z3e1dZ4e1dZ5iZ6de7d<dZ8e j9:e j9:e j9;e<Z=e j9:e=Z>e j9?e>dZ@dZAe j9Be@se j9:e j9:e j9:e=Z>e j9?e>ddZ@e>ZAe j9?e=dZCe j9?e=dZDe j9?e=dZEe j9?eDdZFe j9?eDdZGe j9?eFdZHe j9?eGdZIejJejKBejLBZMeMZNeNejOBejPBejQBZReNejSBejTBejUBZVeMejSBejOBejPBejQBZWeWejTBejUBZXGdddejYZZGdddZ[e\dd e[j]^DZ_dd%d&Z`dd)d*Zae-dd-d.Zbdd3d4Zcddd9d:Zddd>d?ZedddEdFZfdddHdIZgeaddJdKZhddMdNZieaddOdPZj    5   5   Q dddddeZkddkdlZlGdmdndne.ZmGdodpdpe.ejndqZoGdrdsdseoZpGdtdudueoZqddvdwZrddydzZsdd|d}ZtdddZudddZvdddZwddddZxdddZyGdddZzGddde{Z|Gddde{Z}Gddde{Z~GdddeZGddde}ZGddde}ZGddde}ZdddZeddd@fdddZdddZdddZdddZdddZdddZdddZdddZddddZdddƄZdddɄZddd˄ZdddфZdddՄZd dd؄Zd ddڄZd ddZezZeidS( z,Miscellaneous utility functions and classes.) annotationsN)unpackpack) TIOCGWINSZ)LOCALE_WARNINGCONFIGURED_LOCALE)to_bytesto_optional_bytesto_optional_text)open_binary_fileread_text_file)mutex WrappedThread)SUPPORTED_PYTHON_VERSIONSCTBaseTKeyTValuedict[str, str] PYTHON_PATHS coveragercansiblelib_data_utilconfig controllertargettoolsc@s*eZdZdZeZeZdddZdS) OutputStreamz^The output stream to use when running a subprocess and redirecting/capturing stdout or stderr.original t.BinaryIOreturncCs,|tjkr|S|tjkrtjjStt|)zWReturn the correct output buffer to use, taking into account the given original buffer.)r ORIGINALAUTOdisplayfdbufferNotImplementedErrorstr)selfr!r,F/usr/local/lib/python3.10/dist-packages/ansible_test/_internal/util.py get_bufferps   zOutputStream.get_bufferN)r!r"r#r") __name__ __module__ __qualname____doc__enumautor$r%r.r,r,r,r-r js r c@seZdZdZdZdZdS) Architecturez Normalized architecture names. These are the architectures supported by ansible-test, such as when provisioning remote instances. x86_64aarch64N)r/r0r1r2X86_64AARCH64r,r,r,r-r5|sr5ccs"|] \}}|ds|VqdS)__N) startswith.0keyvaluer,r,r-  r@r?r*r#boolcCs|o t| S)z`Return True if the given value is a valid non-keyword Python identifier, otherwise return False.) isidentifierkeyword iskeywordr?r,r,r-is_valid_identifierrGfuncc.Callable[[], TValue]cs0ittfdd}t|}|S)zFEnforce exclusive access on a decorated function and cache the result.cs&d}ur}d<|S)z!Cache the return value from func.NgetrFrIsentinelstorager,r- cache_funcszcache..cache_func)object functoolswrapsr)rIrPwrapperr,rMr-caches rUpythont.Optional[str]cs|ztj}Wntyi}t_Ynw||vr||S|tjks.tj|tjtjkr3t }nt |ddgddd}t |}t jt jt jt jdg}t|dkr]||dt|d krj||dtt|}ttd d fd d |DD}d}|std|d|n&t|dkr|d}tjd|d|ddntd|d|d||||<|S)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()));Tcapturer)r6amd64r7arm64css|]}|r|VqdSNr,)r=archr,r,r-r@z&detect_architecture..csg|]}|qSr,rK)r= candidate translationr,r- z'detect_architecture..Nz9Unable to determine architecture for Python interpreter "z" from: rzDetected architecture z for Python interpreter:  verbosityz$Conflicting architectures detected (z) for Python interpreter ")detect_architectureresultsAttributeErrorsys executableospathrealpathplatformuname raw_commandjsonloadsr5r8r9lenappendsortedsetr&warninginfo)rVrkrsdata candidates architectures architecturer,rdr-rjs@  $     $ rjargs list[str]filtersdict[str, int]cCsnd}g}|D].}|ds|r|d8}qd}|dd}|d}||vr/||t|d}q||q|S)z>Return a filtered version of the given command line arguments.r-r=)r;splitrwrx)rr remainingresultargpartsr>r,r,r- filter_argss  rFrpremove_blank_linesoptionalcCsD|r tj|s gSt|}dd|D}|r dd|D}|S)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. cSsg|] }tdd|qS)z *#.*$)resubr=liner,r,r-rfz/read_lines_without_comments..cSsg|]}|r|qSr,r,rr,r,r-rf)rorpexistsr splitlines)rprrlinesr,r,r-read_lines_without_commentss rr}dict[TKey, t.Optional[TValue]]dict[TKey, TValue]cCstdd|DS)z=Return the provided dictionary with any None values excluded.css$|] \}}|dur||fVqdSr`r,r<r,r,r-r@"z&exclude_none_values..)dictitems)r}r,r,r-exclude_none_valuessrTrncwdrequiredt.Union[bool, str]c Csd}t}|s |}tj|r*tj||}tj|r)t|tjtjBr)|}nM|dur7tj dtjj }|rw| tjj }t}|D]1} | |vrLqE|| tj| |kr[|} tj| |} tj| rvt| tjtjBrv| }nqE|s|rd|} |dkrt| t| |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. NPATH Required program "%s" not found.r{)rogetcwdrpdirnamejoinraccessF_OKX_OKenvironrLdefpathrpathseprzaddabspathApplicationErrorr&r{) rnrrprmatchreal_cwdr path_dirs seen_dirspath_dirrcmessager,r,r-find_executables>     rversioncCsBt|}|s|tjdt|krtj}|Std|||d}|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. Nzpython%s)rpr)str_to_versionrm version_inforwrnr)rrprr python_binr,r,r- find_python6s rcCs$ttjtddddlm}|S)zReturn the Ansible version.z release.pyansible_releaser) __version__) load_modulerorprANSIBLE_LIB_ROOTrr)ansible_versionr,r,r-get_ansible_versionFs rNonecCsNttdttjtdddWddS1s wYdS)zDEnable support for loading Python packages vendored by ansible-core.error_vendorz __init__.pyansible_vendorN)warningscatch_warningsfilterwarningsrrorprrr,r,r,r-_enable_vendoringSs  "rcCstddddtDDS)zMReturn a dictionary indicating which supported Python versions are available.css |] \}}|r||fVqdSr`r,)r=rrpr,r,r-r@az0get_available_python_versions..css |] }|t|ddfVqdS)F)rN)rr=rr,r,r-r@ar)rrr,r,r,r-get_available_python_versions^srstrictcmdc.Iterable[str]rZenvt.Optional[dict[str, str]]explainstdin%t.Optional[t.Union[t.IO[bytes], int]]stdout interactive output_streamt.Optional[OutputStream] cmd_verbosityint str_errorserror_callback/t.Optional[c.Callable[[SubprocessError], None]]'tuple[t.Optional[str], t.Optional[str]]c Cs| ptj} |r |r td|r|rtd|r|rtd|r%|r%td|r-|r-td|r5|s5td| tjkrD|rDtd| d| tjkrS|rStd| d |sYt}|s^t}t|}t|} |rld }n|rqd }nd }|d 7}g}|r| d|r| d|r| d|r|dd|7}t j |d| | ddt j d|ddt |d||ddd}|rt j d|ddt |D]}t j d|||fddq|rdSd}|d urd }n|d urtj}d}n|rntj}|s|ptj}|s | tjkrtjntj}d}nd }t}d }zzd!d"|D}td#d$|D}tj||||||d%}WntyS}z td&|d|d }~ww|r~t|}t|||tjk|tjk|| d'\}}t|| ptd(}t|| p|d(}n|d\}}W|r|jd ur|t d(t d)n|r|jd ur|t d(t d)www|j}t|}t j d*||fd+d|dkr||fSt!|||||| ),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.zCannot combine stdin with data.zURedirection of stdout requires capture=True to avoid redirection of stderr to stdout.zCannot combine output_stream=z with capture=True.z with interactive=True.Run InteractiveStreamz commandr}rrz with /z: T)ritruncatezWorking directory: %srhrrF)rrprzProgram found: %sz%s=%s)NNNcSg|]}t|qSr,r )r=rr,r,r-rfrzraw_command..css$|] \}}t|t|fVqdSr`r)r=kvr,r,r-r@rzraw_command..)rrrstderrrr)rZrrz]Killed command to avoid an orphaned child process during handling of an unexpected exception.z/Command exited with status %s after %s seconds.r^)"r r% InternalErrorrorcommon_environmentlistshlexrrxr&r|rrykeys subprocessPIPEDEVNULLr$STDOUTtimerrPopenFileNotFoundErrorrr communicate_with_processr wait returncodekillnoticeSubprocessError) rrZrr}rrrrrrrrr escaped_cmd description with_typesprogramr> communicaterstartprocess cmd_bytes env_bytesex data_bytes stdout_bytes stderr_bytes stdout_text stderr_textstatusruntimer,r,r-rtds             rtrsubprocess.Popent.Optional[bytes]rtuple[bytes, bytes]c Cs"g}|rt}nt}|dur|t|j||r)||j|tjj}||nd}|r>||j |tj j} || nd} |D]} | qB|D]!} z| WqKt yl} z t t| WYd} ~ qKd} ~ wwt|tryd|j} nd} t| trd| j} nd} || | fS)zRCommunicate with the specified process, handling stdin/stdout/stderr as requested.N) CaptureThread OutputThreadrx WriterThreadrrr.rmr(rrwait_for_result Exceptionr&rr* isinstance ReaderThreadrrr)rrrrrZrthreadsreader stdout_reader stderr_readerthreadrrr r,r,r-rs>       rcs,eZdZdZd fdd Zd d d ZZS)rz.Thread to write data to stdin of a subprocess.handle t.IO[bytes]r}bytesr#rcst|j||_||_dSr`)super__init___runrr})r+rr} __class__r,r-r"6s zWriterThread.__init__cCs6z|j|j|jW|jdS|jwzWorkload to run on a thread.N)rwriter}flushcloser+r,r,r-r#<s zWriterThread._run)rrr}r r#rr#r)r/r0r1r2r"r# __classcell__r,r,r$r-r3srcs2eZdZdZd fdd Zejd d d ZZS)rz(Thread to read stdout from a subprocess.rrr(r"r#rcs$t|j||_||_g|_dSr`)r!r"r#rr(r)r+rr(r$r,r-r"Hs zReaderThread.__init__cCsdSr&r,r*r,r,r-r#OszReaderThread._run)rrr(r"r#rr+) r/r0r1r2r"abcabstractmethodr#r,r,r,r$r-rEs r) metaclassc@eZdZdZdddZdS)rz9Thread to capture stdout from a subprocess into a buffer.r#rcCs:|j}|j}z|D]}||q W|dS|wr&)rrrxr)r+srcdstrr,r,r-r#Ws zCaptureThread._runNr+r/r0r1r2r#r,r,r,r-rTrc@r0)rz2Thread to pass stdout from a subprocess to stdout.r#rcCsB|j}|j}z|D] }|||q W|dS|wr&)rr(r'r(r)r1r,r,r-r#fs  zOutputThread._runNr+r4r,r,r,r-rcr5rcCsPtttjdtjjd}d}d}tjdr|jdd|t ||d|S) z3Common environment used for executing all programs.r)LC_ALLr)HOME)LD_LIBRARY_PATH SSH_AUTH_SOCK#OBJC_DISABLE_INITIALIZE_FORK_SAFETYANSIBLE_KEEP_REMOTE_FILESLDFLAGSCFLAGSz/etc/freebsd-update.confz-I/usr/local/include/)r=)rr) rrrorrLrprrupdate pass_vars)rrrr,r,r-rss  r show_warningcCs2tjdtddtr|rttdSdSdS)zCReport the configured locale and the locale warning, if applicable.zConfigured locale: rrhN)r&r|rrr{)r@r,r,r- report_localesrAc.Collection[str]cCsVi}|D]}|tjvrt|tj|||<q|D]}|tjvr!qtj|||<q|S)zWReturn a filtered dictionary of environment variables based on the current environment.)rorMissingEnvironmentVariable)rrrnamer,r,r-r?s  r?modecsXt|tfddtjtjtjfD}|r(t|tjs*t d|ddSdS)zQPerform chmod on the specified path and then verify the permissions were applied.c3s|]}|@VqdSr`r,)r=permrEr,r-r@rbz!verified_chmod..zPath "zT" should executable, but is not. Is the filesystem mounted with the "noexec" option?N) rochmodanystatS_IXUSRS_IXGRPS_IXOTHrrr)rprErnr,rGr-verified_chmods "rNcCs*z tt|WdStyYdSw)zTRemove the specified directory, silently continuing if the directory does not exist.N)shutilrmtreer r)rpr,r,r- remove_trees  rQcCsrhd}hd}tj|d}||vrdS||vrdSt|}d|dvWdS1s2wYdS) 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.woff2rFTiN)rorpsplitextr read)rp assume_text assume_binaryextpath_fdr,r,r-is_binary_files  $r}lengthcCsdddt|DS)z"Generate and return a random name.rcss"|] }ttjtjVqdSr`)randomchoicestring ascii_lettersdigits)r=_idxr,r,r-r@rAz generate_name..)rrange)rr,r,r- generate_namercCsFtjtjtjtjdgd}ddd|ddD}tj||S)z$Generate and return random password.rr^rcSsg|]}t|qSr,)rr)r=charr,r,r-rfrgz%generate_password..N)rrrrr& sensitiver)charspasswordr,r,r-generate_passwords rc@seZdZdZdZdZdZdZdZdZ dZ d eee d Z d+d dZ d,ddZ d+ddZd-d.ddZd,ddZd,dd Zd,d!d"Zd/d0d$d%Z  d1d2d)d*Zd S)3DisplayzManages color console output.zzzzzzzN)rrrr#rc Csd|_tj|_g|_t|_tj|_ d|_ d|_ d|_ d|_ t|_tdrCtdtdttddddddd\|_ |_ dSdS)NrTHHHHr)rirmrisattycolorrrzwarnings_uniquerr'rowscolumnsrredactrrorfcntlioctlrrr*r,r,r-r"*s  4zDisplay.__init__rr*cC|jd||jddS)z9Internal implementation for displaying a warning message.z WARNING: %srN print_messagepurpler+rr,r,r- __warning9rzDisplay.__warningcCs8|jsdS|dt|j|jD]}||qdS)z.Review all warnings which previously occurred.Nz!Reviewing previous %d warning(s):)r_Display__warningrw)r+r{r,r,r-review_warnings=s   zDisplay.review_warningsFruniquerBrircCsF||jkrdS|r||jvrdS|j||||j|dS)z Display a warning level message.N)rirrrrrx)r+rrrir,r,r-r{Gs    zDisplay.warningcCr)zDisplay a notice level message.z NOTICE: %srNrrr,r,r-rUrzDisplay.noticecCr)zDisplay an error level message.z ERROR: %srNrredrr,r,r-rYrz Display.errorcCs|jd||jdddS)zDisplay a fatal level message.z FATAL: %sT)rrNrrr,r,r-fatal]sz Display.fatalrcCs2|j|kr|j||j}|j|||ddSdS)zDisplay an info level message.)rrN)riverbosity_colorsrLyellowr)r+rrirrr,r,r-r|as z Display.inforrWrcCs|jr|jr|jD]}|sq ||dt|}q |r5t||jkr(dkr5nn |d|jdd}|rI|jrI||j|}d|||jf}|rNtjn|j }t ||d| dS)zDisplay a message.*r]Nz ...z%s%s%s)file) rrreplacerwrrclearrmrr'printr()r+rrrritemr'r,r,r-rgs     zDisplay.print_messager+rr*r#r)Fr)rr*rrBrirr#r)rF)rr*rirrrBr#r)NFF) rr*rrWrrBrrBr#r)r/r0r1r2rrgreenrbluercyanrr"rrr{rrrr|rr,r,r,r-rs4        rc"eZdZdZdfdd ZZS) rz9An unhandled internal error indicating a bug in the code.rr*r#rcstd|dS)Nz0An internal error has occurred in ansible-test: )r!r"rr$r,r-r"szInternalError.__init__rr/r0r1r2r"r,r,r,r$r-rrc@eZdZdZdS)rzGeneral application error.Nr/r0r1r2r,r,r,r-rrc@r)ApplicationWarningzAGeneral application warning which interrupts normal program flow.Nrr,r,r,r-rrrc@r)TimeoutExpiredErrorz@Error raised when the test timeout has been reached or exceeded.Nrr,r,r,r-rrrcs.eZdZdZ     ddfdd ZZS)rz1Error resulting from failed subprocess execution.rNrrr rrrWrr t.Optional[float]rrr#rcsndt||f}|t||7}||_||_||_||_||_||_|r(|||j |_t |jdS)Nz&Command "%s" returned exit status %s. ) rrformat_command_outputrrr rrr stripr!r")r+rr rrr rrr$r,r-r"s  zSubprocessError.__init__)rNNNN)rrr rrrWrrWr rrrr#rrr,r,r$r-rsrcr) rCz-Error caused by missing environment variable.rDr*r#rcstd|||_dS)Nz Missing environment variable: %s)r!r"rD)r+rDr$r,r-r"s z#MissingEnvironmentVariable.__init__)rDr*r#rrr,r,r$r-rCrrCcs.eZdZdZd dfd d Zdd d ZZS)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. Nrr*callbackt.Callable[[], None]r#rcst|||_dSr`)r!r" _callback)r+rrr$r,r-r"s  zHostConnectionError.__init__cCs|jr |dSdS)zRun the error callback, if any.N)rr*r,r,r- run_callbacks z HostConnectionError.run_callbackr`)rr*rrr#rr+)r/r0r1r2r"rr,r,r,r$r-rsr str | NonecCs`d}|r|}r|d7}||tjd7}|r.|}r.|d7}||tjd7}|S)zJReturn a formatted string containing the given stdout and stderr (if any).rz>>> Standard Error  z>>> Standard Output )rrr)rrrr,r,r-rsr t.Callable[..., TValue]ex_typet.Type[BaseException]sleepattemptswarnc Csbtd|D](}z|WS|y-}z|rtt|t|WYd}~qd}~ww|S)z(Retry the specified function on failure.rN)rr&r{r*rr)rIrrrrdummyrr,r,r-retrys rpatternlist[dict[str, str]]cCs^g}g}|D]}t||}|r||q||q|r-td|d|f|S)zzParse lines from the given value using the specified pattern and return the extracted list of key/value pair dictionaries.z%Pattern "%s" did not match values: %sr)rrsearchrx groupdictrr)rr?matched unmatchedrrr,r,r-parse_to_list_of_dicts   r class_type t.Type[C]list[t.Type[C]]cCs`t}|g}|r(|}|D]}||vr%t|s ||||q|st|dddS)zGReturns a list of types that are concrete subclasses of the given type.cSs|jSr`)r/)scr,r,r-sz get_subclasses..)r>)rzpop__subclasses__inspect isabstractrrxry)r subclassesqueueparentchildr,r,r-get_subclassess     rcandidate_pathcCs>|tjjs |tjj7}|tjjs|tjj7}||S)zAReturns true if candidate_path is path or a subdirectory of path.)endswithrorpsepr;)rrpr,r,r- is_subdirs    rpathscCsLt}|D]} tj|}|r|tjjkrn ||tjjqqt|S)zEReturns a list of directories extracted from the given list of paths.)rzrorprrrry)r dir_namesrpr,r,r- paths_to_dirss rtuple[int, ...]cCstdd|dDS)z-Return a version tuple from a version string.cs|]}t|VqdSr`)rr=nr,r,r-r@/rbz!str_to_version...)tuplerrr,r,r-r-rrcCsddd|DS)z-Return a version string from a version tuple.rcsrr`r*rr,r,r-r@4rbz!version_to_str..)rrr,r,r-version_to_str2rHrversionscCsddtdd|DDS)z3Return a sorted copy of the given list of versions.cSrr,)rrr,r,r-rf9rz#sorted_versions..csrr`)rrr,r,r-r@9rbz"sorted_versions..)ry)rr,r,r-sorted_versions7r directoryrootc Cs|dur tjt}tj||}tddd}d||tjjdf}t j |g|dD]!\}}}tj||t |dddtjjd}t ||q-dS)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. Nrrrz%s.%s.)prefixrf) rorpr__file__rr/rsplitrrpkgutil iter_modulesrwr) rrrppackager_module_loaderrD_ispkg module_pathr,r,r-import_plugins<s . r base_typedatabasedict[str, t.Type[C]]cCs0tddt|D}|D]}||||<q dS)z Load plugins of the specified type and track them in the specified database. Only plugins which have already been imported will be loaded. css&|]}|jddd|fVqdS)rrN)r0r)r=rr,r,r-r@Rs$zload_plugins..N)rr)rrpluginspluginr,r,r- load_pluginsMsrrDcCsB|tjvrdStj||}tj|}|tj|<|j|dS)z3Load a Python module using the given name and path.N)rmmodules importlibutilspec_from_file_locationmodule_from_specloader exec_module)rprDspecmoduler,r,r-rXs   rcCstdd|dddS)zMReturn a sanitized version of the given name, suitable for use as a hostname.z [^A-Za-z0-9]+rN?)rrr)rDr,r,r-sanitize_host_namecrrt.Typegeneric_base_typet.Type[TValue]t.Optional[t.Type[TValue]]cCs&t|jdd}t||rdS|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.rN)tget_args__orig_bases__r)rrtype_argr,r,r-get_generic_typehsr t.Type[TBase]*list[tuple[t.Type[TValue], t.Type[TBase]]]cs ddfddt|DDS)z{Create and return a list of tuples associating generic_base_type derived types with a corresponding base_type derived type.cSsg|]}|dr|qS)rr,r=rr,r,r-rfqsz)get_type_associations..csg|] }t||fqSr,)r)r=sc_typerr,r-rfqr)rrrr,r r-get_type_associationsos r"#dict[t.Type[TValue], t.Type[TBase]]cCsddt||DS)zZCreate and return a mapping of generic_base_type derived types to base_type derived types.cSsi|] }|d|dqS)rrr,rr,r,r- vrz get_type_map..)r"r!r,r,r- get_type_maptrHr%cCsT|tjkrdStj|tjtjkrdSt|ddgddd}|tjkr(dS|S)z~Verify that the given path references the current Python interpreter. If not, return the expected path, otherwise return None.NrXz!import sys; print(sys.executable)TrYr)rmrnrorprqrt)rpexpected_executabler,r,r-verify_sys_executableys  r'sequencec.Sequence[t.Any] guard_typet.TypeGuard[c.Sequence[C]]csJtfdd|D}|sdStdd|D}tddd|)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. c3s"|] }t|st|VqdSr`)rtyperr*r,r-r@rAztype_guard..Tcsrr`rrr,r,r-r@rbz"Sequence required to contain only z includes: z, )rzryrr)r(r* invalid_typesinvalid_type_namesr,r-r- type_guards r0)r?r*r#rB)rIrJr#rJ)rVr*r#rW)rrrrr#r)FF)rpr*rrBrrBr#r)r}rr#r)NNT) rnr*rrWrprWrrr#rW)NT)rr*rprWrrBr#rW)r#r*r+)r#r) NNNFNNFNrrN)rrrZrBrrr}rWrrWrrBrrrrrrBrrrrrr*rrr#r)rrrrrrBrrBrZrBrr r#r)r@rBr#r)rrBrrBr#r)rpr*rErr#r)rpr*r#r)rpr*r#rB)r~)rrr#r*)rrrrr#r*) rIrrrrrrrrrBr#r)rr*r?r*r#r)rrr#r)rr*rpr*r#rB)rrr#r)rr*r#r)rrr#r*)rrr#rr`)rr*rrWr#r)rrrrr#r)rpr*rDr*r#r)rDr*r#r*)rrrrr#r)rrrrr#r)rrrrr#r#)rpr*r#rW)r(r)r*rr#r+)r2 __future__rr-collections.abccr3rimportlib.utilr rrurDrorrrrrrOrJrrrmrrRrtypingrrstructrrtermiosr locale_utilrrencodingr r r ior r rrr constantsrTypeVarrrrrr__annotations__COVERAGE_CONFIG_NAMErprrrANSIBLE_TEST_ROOT ANSIBLE_ROOTrrANSIBLE_SOURCE_ROOTrANSIBLE_TEST_DATA_ROOTANSIBLE_TEST_UTIL_ROOTANSIBLE_TEST_CONFIG_ROOTANSIBLE_TEST_CONTROLLER_ROOTANSIBLE_TEST_TARGET_ROOTANSIBLE_TEST_TOOLS_ROOTANSIBLE_TEST_TARGET_TOOLS_ROOTS_IRUSRS_IRGRPS_IROTH MODE_READ MODE_FILErKrLrMMODE_FILE_EXECUTES_IWUSRS_IWGRPS_IWOTHMODE_FILE_WRITEMODE_DIRECTORYMODE_DIRECTORY_WRITEEnumr r5r__dict__rREMOTE_ARCHITECTURESrGrUrjrrrrrrrrrtrrABCMetarrrrrAr?rNrQr}rrrrrrr SystemExitrrrCrrrrrrrrrrrrrrrr"r%r'r0r&r,r,r,r-s               3    2     8  +   8 m