a )g@sdddlmZmZmZeZddlZddlZddlZddl m Z m Z ddZ ddZ dd Zd d ZdS) )absolute_importdivisionprint_functionN)to_bytes to_nativecCsttjddS)N__main__Z _respawned)hasattrsysmodulesr r G/usr/lib/python3.9/site-packages/ansible/module_utils/common/respawn.py has_respawnedsr cCsZtrtdt}t\}}t|t|t|tj |dg|d}t |dS)a Respawn the currently-running Ansible Python module under the specified Python interpreter. Ansible modules that require libraries that are typically available only under well-known interpreters (eg, ``yum``, ``apt``, ``dnf``) can use bespoke logic to determine the libraries they need are not available, then call `respawn_module` to re-execute the current module under a different interpreter and exit the current process when the new subprocess has completed. The respawned process inherits only stdout/stderr from the current process. Only a single respawn is allowed. ``respawn_module`` will fail on nested respawns. Modules are encouraged to call `has_respawned()` to defensively guide behavior before calling ``respawn_module``, and to ensure that the target interpreter exists, as ``respawn_module`` will not fail gracefully. :arg interpreter_path: path to a Python interpreter to respawn the current module z!module has already been respawnedz--)stdinN) r Exception_create_payloadospipewriterclose subprocesscallr exit)interpreter_pathZpayloadZ stdin_readZ stdin_writercr r r respawn_modules  rc Cs`|D]V}tj|sqz,t|dd|g}|dkr@|WSWqtyXYqYq0qdS)aG Probes a supplied list of Python interpreters, returning the first one capable of importing the named module. This is useful when attempting to locate a "system Python" where OS-packaged utility modules are located. :arg interpreter_paths: iterable of paths to Python interpreters. The paths will be probed in order, and the first path that exists and can successfully import the named module will be returned (or ``None`` if probing fails for all supplied paths). :arg module_name: fully-qualified Python module name to probe for (eg, ``selinux``) z-cz import {0}rN)rpathexistsrrformatr)Zinterpreter_pathsZ module_namerrr r r probe_interpreters_for_module/s    rcCsVddlm}t|d}|s"tdtjdj}tjdj}d}|j||t |d}|S)Nr)basicZ _ANSIBLE_ARGSzVunable to access ansible.module_utils.basic._ANSIBLE_ARGS (not launched by AnsiballZ?)ra import runpy import sys module_fqn = '{module_fqn}' modlib_path = '{modlib_path}' smuggled_args = b"""{smuggled_args}""".strip() if __name__ == '__main__': sys.path.insert(0, modlib_path) from ansible.module_utils import basic basic._ANSIBLE_ARGS = smuggled_args runpy.run_module(module_fqn, init_globals=dict(_respawned=True), run_name='__main__', alter_sys=True) ) module_fqn modlib_path smuggled_args) Zansible.module_utilsrgetattrrr r Z _module_fqnZ _modlib_pathrr)rr"r r!Zrespawn_code_templateZ respawn_coder r r rGs    r)Z __future__rrrtypeZ __metaclass__rrr Z+ansible.module_utils.common.text.convertersrrr rrrr r r r s