
    Mh                        d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
 ddlZddlmZ e	rddlmZ dddZd Z	 dddZ	 dddZg dZdS ) z1Connection file-related utilities for the kernel
    )annotationsN)PIPEPopen)TYPE_CHECKINGAny)write_connection_fileIPKernelAppappIPKernelApp | Nonereturnstrc                    ddl m} | 5ddlm}  |j                    sd}t          |           |j                    }  || j        d| j        g          S )zReturn the path to the connection file of an app

    Parameters
    ----------
    app : IPKernelApp instance [optional]
        If unspecified, the currently running app will be used
    r   )filefindNr	   z.app not specified, and not in a running Kernel.)	traitlets.utilsr   ipykernel.kernelappr
   initializedRuntimeErrorinstanceconnection_fileconnection_dir)r   r   r
   msgs       Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ipykernel/connect.pyget_connection_filer      s     )(((((
{333333&{&(( 	$BCs###"k"$$8C'#s/A)BCCC    c                J    | t                      S t          j        |           S )zReturn the absolute path for a connection file

    - If nothing specified, return current Kernel's connection file
    - Otherwise, call jupyter_client.find_connection_file
    )r   jupyter_clientfind_connection_file)r   s    r   _find_connection_filer    (   s'     "$$$.???r   Fr   
str | Noneunpackboolstr | dict[str, Any]c                    t          |           }t          |          5 }|                                }ddd           n# 1 swxY w Y   |rAt          j        |          }|                    dd                                          |d<   |S |S )a  Return the connection information for the current Kernel.

    Parameters
    ----------
    connection_file : str [optional]
        The connection file to be used. Can be given by absolute path, or
        IPython will search in the security directory.
        If run from IPython,

        If unspecified, the connection file for the currently running
        IPython Kernel will be used, which is only allowed from inside a kernel.

    unpack : bool [default: False]
        if True, return the unpacked dict, otherwise just the string contents
        of the file.

    Returns
    -------
    The connection dictionary of the current kernel, as string or dict,
    depending on `unpack`.
    Nkey )r    openreadjsonloadsgetencode)r   r"   cffinfo_strinfos         r   get_connection_infor2   4   s    0 
	/	/B	b Q6688                z(##hhub))0022UOs   A  AAargvlist[str] | None
Popen[Any]c                    |g n|}t          |           }d                    ddg          }i }d|d<   t          t          j        d|d|g|ft
          t
          t          j        d	k    d
|S )a  Connect a qtconsole to the current kernel.

    This is useful for connecting a second qtconsole to a kernel, or to a
    local notebook.

    Parameters
    ----------
    connection_file : str [optional]
        The connection file to be used. Can be given by absolute path, or
        IPython will search in the security directory.
        If run from IPython,

        If unspecified, the connection file for the currently running
        IPython Kernel will be used, which is only allowed from inside a kernel.

    argv : list [optional]
        Any extra args to be passed to the console.

    Returns
    -------
    :class:`subprocess.Popen` instance running the qtconsole frontend
    N;z"from qtconsole import qtconsoleappzqtconsoleapp.main()Tstart_new_sessionz-cz
--existingwin32)stdoutstderr	close_fds)r    joinr   sys
executabler   platform)r   r3   r.   cmdkwargss        r   connect_qtconsolerC   Z   s    2 224D		/	/B
((8:OP
Q
QCF #'F	sL"<t<<7*	 
   r   )r   r   r2   rC   )N)r   r   r   r   )NF)r   r!   r"   r#   r   r$   )NN)r   r!   r3   r4   r   r5   )__doc__
__future__r   r*   r>   
subprocessr   r   typingr   r   r   r   r   r
   r   r    r2   rC   __all__ r   r   <module>rJ      s"    # " " " " "  



 " " " " " " " " % % % % % % % %     0 0 0 0 0 0 0//////D D D D D*	@ 	@ 	@ 8=# # # # #N BF* * * * *Z  r   