o nnh$@sFddlmZddlZddlZddlmZmZddlm Z m Z ddl m Z ddl mZmZddlmZddlmZdd lmZz dd lmZd ZWn eySd ZYnweZd dZddZddZddZddZ ddZ!ddZ"ddZ#d/dd Z$d!d"Z%d0d#d$Z&d0d%dZ'd1d'd(Z(d2d)d*Z)d2d+d,Z*Gd-d.d.e+Z,dS)3) annotationsN)MutableMappingMutableSequence) LooseVersion StrictVersionerrors) to_nativeto_text)boolean)Display)SemanticVersion)VersionTFcC t|ts td|ddS)z# Test if task result yields failed z&The 'failed' test expects a dictionaryfailedF isinstancerrAnsibleFilterErrorgetresultrD/usr/local/lib/python3.10/dist-packages/ansible/plugins/test/core.pyr*   rcC t| S)z$ Test if task result yields success )rrrrrsuccess1 rcCr)z( Test if task result yields unreachable z+The 'unreachable' test expects a dictionary unreachableFrrrrrr6rrcCr)z& Test if task result yields reachable )rrrrr reachable=rrcCst|ts tdd|vr8d}d|vr6t|dtr6t|ddtr6|dD] }|ddr5d}|Sq(|S|dd}|S)z$ Test if task result yields changed z'The 'changed' test expects a dictionarychangedFresultsrT)rrrrrr)rrresrrrrBs$      rcCr)z$ Test if task result yields skipped z'The 'skipped' test expects a dictionaryskippedFrrrrrr"Vrr"cC:t|ts tdd|vr|dddkStddS)z Test if async task has started z'The 'started' test expects a dictionarystartedrzIThe 'started' test expects an async task, but a non-async task was testedTrrrrrdisplaywarningrrrrr$]   r$cCr#)z! Test if async task has finished z(The 'finished' test expects a dictionaryfinishedrr%zJThe 'finished' test expects an async task, but a non-async task was testedTr&rrrrr*kr)r*searchcCsNt|dd}d}|r|tjO}|r|tjO}tj||d}tt||d|S)z Expose `re` as a boolean filter using the `search` method by default. This is likely only useful for `search` and `match` which already have their own filters. surrogate_or_strictrr)flagsr,)r reIMcompileboolgetattr)valuepattern ignorecase multiline match_typer._rerrrregexys   r;cCst|ddo |S)z^Evaluate whether a variable is a single vault encrypted value .. versionadded:: 2.10 __ENCRYPTED__F)r4 is_encrypted)r5rrrvault_encryptedsr>cCt||||dS)z* Perform a `re.match` returning a boolean matchr;r5r6r7r8rrrr@r@cCr?)z+ Perform a `re.search` returning a boolean r,rArBrrrr,rCeqc CsLddddddddddddddd}tttttd}|d ur&|d ur&td |s-td |s4td |d kr?ts?tdt}|rFt}n|rez||}Wntydtd|dt t |fw||vrn||}ntd|dt t |fzt t |}||t ||t |WSty} z tdt| d } ~ ww)z) Perform a version comparison on a value rDltlegtgene)z===rDrGz>=rHz!=z<>rI)loosestrictsemversemanticpep440Nz/Cannot specify both 'strict' and 'version_type'z#Input version value cannot be emptyz4Version parameter to compare against cannot be emptyrQz?The pep440 version_type requires the Python 'packaging' libraryz,Invalid version type (%s). Must be one of %sz, z-Invalid operator type (%s). Must be one of %szVersion comparison failed: %s)rrr PEP440Versionrr HAS_PACKAGINGKeyErrorjoinmapreprr4 py_operatorr Exceptionr ) r5versionoperatorrN version_typeop_maptype_maprmethoderrrversion_comparesX          racCs8|rz t|}Wt|StyYt|Swt|S)zEvaluate as value for truthiness using python ``bool`` Optionally, attempt to do a conversion to bool from boolean like values such as ``"false"``, ``"true"``, ``"yes"``, ``"no"``, ``"on"``, ``"off"``, etc. .. versionadded:: 2.10 )r TypeErrorr3r5 convert_boolrrrtruthys  recCst||d S)zEvaluate as value for falsiness using python ``bool`` Optionally, attempt to do a conversion to bool from boolean like values such as ``"false"``, ``"true"``, ``"yes"``, ``"no"``, ``"on"``, ``"off"``, etc. .. versionadded:: 2.10 )rd)rercrrrfalsysrfc@seZdZdZddZdS) TestModulez Ansible core jinja2 tests cCs|idtdtdtdtdtdtdtdtd td td td td tdtdt dt dt t t t tttdS)Nrfailure succeededr successfulrrrchanger"skipr*r$r@r,r;ra)rZanyallrerfr>)rrrrrr"r*r$r@r,r;rarmrnrerfr>)selfrrrtestssT  zTestModule.testsN)__name__ __module__ __qualname____doc__rprrrrrgs rg)r+r+FFr,)r+FF)rDNN)F)- __future__rr/r[rXcollections.abcrr#ansible.module_utils.compat.versionrransibler+ansible.module_utils.common.text.convertersr r )ansible.module_utils.parsing.convert_boolr ansible.utils.displayr ansible.utils.versionr packaging.versionrrRrS ImportErrorr'rrrrrr"r$r*r;r>r@r,rarerfobjectrgrrrrsB            8