
    Vh!                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ  ej                  e	      j                  d   Zd Zd Zd Zd Zy)	    )annotationsN)to_bytes   c                 <    t        t        j                  d   d      S )N__main__
_respawned)hasattrsysmodules     S/home/dcms/DCMS/lib/python3.12/site-packages/ansible/module_utils/common/respawn.pyhas_respawnedr      s    3;;z*L99r   c                4   t               rt        d      t               }t        j                         \  }}t        j
                  |t        |             t        j                  |       t        j                  | dg|      }t        j                  |       y)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, ``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_payloadospipewriter   close
subprocesscallr
   exit)interpreter_pathpayload
stdin_readstdin_writercs        r   respawn_moduler       so    " ;<< G ggiJHH[(7+,HH[	*D1	DBHHRLr   c                F   t        j                  dd      }t         j                  dt         d| j	                  d      iz  }| D ]J  }t         j
                  j                  |      s#	 t        j                  |dd| dg|      }|d	k(  r|c S L y
# t        $ r Y Yw xY w)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``)
    
PYTHONPATH :z: z-czimport z, ansible.module_utils.basic)envr   N)
r   getenvenviron_ANSIBLE_PARENT_PATHrstrippathexistsr   r   r   )interpreter_pathsmodule_namer"   r%   r   r   s         r   probe_interpreters_for_moduler.   1   s     <,J
**)=(>a
|&L&S&STX&YZ
ZC- ww~~./	$k]*FG
 B Qw'' "   		s   *$B	B B c                     ddl m}  t        | d      }|st        d      t        j
                  d   j                  }t        j
                  d   j                  }d}|j                  |||j                               }|S )Nr   )basic_ANSIBLE_ARGSzVunable to access ansible.module_utils.basic._ANSIBLE_ARGS (not launched by AnsiballZ?)r   ay  
import runpy
import sys

module_fqn = {module_fqn!r}
modlib_path = {modlib_path!r}
smuggled_args = {smuggled_args!r}

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)
ansible.module_utilsr0   getattrr   r
   r   _module_fqn_modlib_pathformatstrip)r0   r4   r2   r3   respawn_code_templaterespawn_codes         r   r   r   R   s    *E?3MpqqZ(44J++j)66K" )//:S^n{  oB  oB  oD/  ELr   )
__future__r   r   pathlibr   r
   +ansible.module_utils.common.text.convertersr   Path__file__parentsr(   r   r    r.   r   r   r   r   <module>rC      sJ    # 	   
 @#w||H-55a8 ::Br   