a )gC$@sRddlmZmZmZeZddlZddlZddl m Z m Z ddl m Z mZddlmZddlmZmZddlmZddlmZdd lmZzdd lmZd ZWneyd ZYn0eZd dZ ddZ!ddZ"ddZ#ddZ$ddZ%ddZ&ddZ'd/dd Z(d!d"Z)d0d#d$Z*d1d%dZ+d2d'd(Z,d3d)d*Z-d4d+d,Z.Gd-d.d.e/Z0dS)5)absolute_importdivisionprint_functionN)MutableMappingMutableSequence) LooseVersion StrictVersionerrors) to_nativeto_text)boolean)Display)SemanticVersion)VersionTFcCs t|tstd|ddS)z# Test if task result yields failed z&The 'failed' test expects a dictionaryfailedF isinstancerr AnsibleFilterErrorgetresultr=/usr/lib/python3.9/site-packages/ansible/plugins/test/core.pyr,s  rcCs t| S)z$ Test if task result yields success )rrrrrsuccess3srcCs t|tstd|ddS)z( Test if task result yields unreachable z+The 'unreachable' test expects a dictionary unreachableFrrrrrr8s  rcCs t| S)z& Test if task result yields reachable )rrrrr reachable?srcCs|t|tstdd|vrld}d|vrxt|dtrxt|ddtrx|dD]}|ddrPd}qxqPn |dd}|S)z$ Test if task result yields changed z'The 'changed' test expects a dictionarychangedFresultsrT)rrr rrr)rrresrrrrDs       rcCs t|tstd|ddS)z$ Test if task result yields skipped z'The 'skipped' test expects a dictionaryskippedFrrrrrr Xs  r cCs>t|tstdd|vr,|dddkStddSdS)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 testedTNrrr rrdisplayZwarningrrrrr!_s    r!cCs>t|tstdd|vr,|dddkStddSdS)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 testedTNr#rrrrr%ms    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. Zsurrogate_or_strictr r)flagsr')r reIMcompileboolgetattr)valuepattern ignorecase multilineZ match_typer(_rerrrregex{s   r4cCst|ddo|S)z^Evaulate whether a variable is a single vault encrypted value .. versionadded:: 2.10 Z __ENCRYPTED__F)r.Z is_encrypted)r/rrrvault_encryptedsr5cCst||||dS)z* Perform a `re.match` returning a boolean matchr4r/r0r1r2rrrr6sr6cCst||||dS)z+ Perform a `re.search` returning a boolean r'r7r8rrrr'seqc Csbddddddddddddddd}tttttd}|d urL|d urLtd |sZtd |shtd |d kr~ts~tdt}|rt}nB|rz ||}Wn0tytd|dt t |fYn0||vr||}ntd|dt t |fz&t t |}||t ||t |WSty\} ztdt| WYd } ~ n d } ~ 00d S)z) Perform a version comparison on a value r9ltlegtgene)z===r9r<z>=r=z!=z<>r>)ZloosestrictZsemverZsemanticpep440Nz/Cannot specify both 'strict' and 'version_type'z#Input version value cannot be emptyz4Version parameter to compare against cannot be emptyrCz?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 PEP440Versionr r HAS_PACKAGINGKeyErrorjoinmapreprr. py_operatorr Exceptionr ) r/versionoperatorrBZ version_typeZop_mapZtype_maprmethoderrrversion_comparesR           rPcCs,|r$z t|}Wnty"Yn0t|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 TypeErrorr-r/ convert_boolrrrtruthys   rTcCst||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 )rS)rTrRrrrfalsysrUc@seZdZdZddZdS) TestModulez Ansible core jinja2 tests cCs4ttttttttttttttt t t t t t tttdS)N)rZfailureZ succeededrZ successfulrrrZchanger skipr%r!r6r'r4rPrLanyallrTrUr5)rrrrrr r%r!r6r'r4rPrXrYrTrUr5)selfrrrtestss0zTestModule.testsN)__name__ __module__ __qualname____doc__r[rrrrrVsrV)r&r&FFr')r&FF)r&FF)r9NN)F)F)1Z __future__rrrtypeZ __metaclass__r)rMrJcollections.abcrrZ#ansible.module_utils.compat.versionrrZansibler Zansible.module_utils._textr r Z)ansible.module_utils.parsing.convert_boolr Zansible.utils.displayrZansible.utils.versionrZpackaging.versionrrDrE ImportErrorr$rrrrrr r!r%r4r5r6r'rPrTrUobjectrVrrrrs@           8