
    .h.                         d Z ddlZddlZddlZddlmZ ddlmZ ddlZddl	m
Z
 dedefdZdej        dfded	ee         d
eeef         dz  dedeez  dz  f
dZde
fdZdS )z=
Windows-specific functionality for stdio client operations.
    N)Path)TextIO)Processcommandreturnc                     	 t          j        |           x}r|S dD ]"}|  | }t          j        |          x}r|c S #| S # t          $ r | cY S w xY w)aB  
    Get the correct executable command normalized for Windows.

    On Windows, commands might exist with specific extensions (.exe, .cmd, etc.)
    that need to be located for proper execution.

    Args:
        command: Base command (e.g., 'uvx', 'npx')

    Returns:
        str: Windows-appropriate command path
    )z.cmdz.batz.exez.ps1)shutilwhichOSError)r   command_pathextext_versionext_paths        S/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/mcp/client/stdio/win32.pyget_windows_executable_commandr      s    !<000< 	  4 	  	 C$+c++K!<444x        s   A #A A AAargsenverrlogcwdc                    K   	 t          j        | g||t          t          d          rt          j        nd||           d{V }|S # t
          $ r& t          j        | g||||           d{V }|cY S w xY w)a  
    Creates a subprocess in a Windows-compatible way.

    Windows processes need special handling for console windows and
    process creation flags.

    Args:
        command: The command to execute
        args: Command line arguments
        env: Environment variables
        errlog: Where to send stderr output
        cwd: Working directory for the process

    Returns:
        A process handle
    CREATE_NO_WINDOWr   )r   creationflagsstderrr   N)r   r   r   )anyioopen_processhasattr
subprocessr   	Exception)r   r   r   r   r   processs         r   create_windows_processr    /   s      .*t z#566*55	
 	
 	
 	
 	
 	
 	
 	
 	
    *t#f#
 
 
 
 
 
 
 
 
 s   AA	 	-A98A9r   c                   K   	 |                                   t          j        d          5  |                                  d{V  ddd           dS # 1 swxY w Y   dS # t          $ r |                                  Y dS w xY w)aB  
    Terminate a Windows process.

    Note: On Windows, terminating a process with process.terminate() doesn't
    always guarantee immediate process termination.
    So we give it 2s to exit, or we call process.kill()
    which sends a SIGKILL equivalent signal.

    Args:
        process: The process to terminate
    g       @N)	terminater   
fail_afterwaitTimeoutErrorkill)r   s    r   terminate_windows_processr'   [   s      c"" 	! 	!,,..       	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!   s4   (A! AA! AA! AA! !BB)__doc__r	   r   syspathlibr   typingr   r   	anyio.abcr   strr   r   listdictr    r'        r   <module>r2      s%         



                   C C    F "&Z!) ))
s)) 
c3h$	) 	)
 
d	) ) ) )XW      r1   