
    Mh!                         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m	Z	 ddl
mZmZ ddlmZmZmZ dd	lmZ  G d
 de          Z G d de          ZdS )z3An object for managing IPython profile directories.    N)Path)LoggingConfigurable   )get_ipython_package_dir)expand_pathensure_dir_exists)UnicodeBoolobserve)Optionalc                       e Zd ZdS )ProfileDirErrorN)__name__
__module____qualname__     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/profiledir.pyr   r      s        Dr   r   c                      e Zd ZdZ ed          Z ed          Z ed          Z ed          Z ed          Z	 ed          Z
 ed          Z ed          Z ed          Z ed          Z edd	                              d
          Z ed          Z ed          d             Zd$dedee         defdZ ed          d$d            Z ed          d$d            Z ed          d$d            Z ed          d$d            Zd Zd%dededefdZ e!d$d            Z"e!d&d!            Z#e!d&d"            Z$e!d$d#            Z%dS )'
ProfileDira@  An object to manage the profile directory and its resources.

    The profile directory is used by all IPython applications, to manage
    configuration, logging and security.

    This object knows how to find, create and manage these directories. This
    should be used by any code that wants to handle profiles.
    securitylogstartuppidstatic zaSet the profile location directly. This overrides the logic used by the
        `profile` option.)helpT)configFlocationc                 :   | j         rt          d          d| _         |d         }t          |           t          j                            || j                  | _        t          j                            || j                  | _	        t          j                            || j
                  | _        t          j                            || j                  | _        t          j                            || j                  | _        |                                  d S )Nz+Cannot set profile location more than once.Tnew)_location_issetRuntimeErrorr   ospathjoinsecurity_dir_namesecurity_dirlog_dir_namelog_dirstartup_dir_namestartup_dirpid_dir_namepid_dirstatic_dir_name
static_dir
check_dirs)selfchanger!   s      r   _location_changedzProfileDir._location_changed:   s     	NLMMM#Um# GLLd.DEEw||C):;;7<<T-BCCw||C):;;',,sD,@AAr   Nr%   modereturnc                    t           j                            |          rc|r_t          j        |          j        |k    rB	 t          j        ||           n+# t          $ r | j                            d|           Y nw xY wdS 	 |rt          j	        ||           nt          j	        |           n.# t          $ r!}|j
        t          j        k    rY d}~dS  d}~ww xY wdS )a  ensure a directory exists at a given path

        This is a version of os.mkdir, with the following differences:

        - returns whether the directory has been created or not.
        - ignores EEXIST, protecting against race conditions where
          the dir may have been created in between the check and
          the creation
        - sets permissions if requested and the dir already exists

        Parameters
        ----------
        path: str
            path of the dir to create
        mode: int
            see `mode` of `os.mkdir`

        Returns
        -------
        bool:
            returns True if it created the directory, False otherwise
        zCould not set permissions on %sFNT)r$   r%   existsstatst_modechmodOSErrorr   warningmkdirerrnoEEXIST)r2   r%   r5   es       r   _mkdirzProfileDir._mkdirJ   s   0 7>>$ 		 -55HT4((((   H$$9    
 5		 t$$$$ 	 	 	w%,&&uuuuu		 ts0    A %A>=A>,B1 1
C;CCCr*   c                 :    |                      | j                   d S N)rB   r*   r2   r3   s     r   check_log_dirzProfileDir.check_log_diry   s    DL!!!!!r   r,   c                    |                      | j                  rt          j                            | j        d          }t          j                            t                      ddd          }t          j                            |          r8t          j                            |          st          j        ||           d S d S | j	        
                    d|           d S d S )NREADMEcoreprofileREADME_STARTUPzLCould not copy README_STARTUP to startup dir. Source file %s does not exist.)rB   r,   r$   r%   r&   r   r8   shutilcopyr   r=   )r2   r3   readmesrcs       r   check_startup_dirzProfileDir.check_startup_dir}   s    ;;t'(( 	W\\$"2H==F',,'))69>N C w~~c"" w~~f-- -KV,,,,,- -   b    	 	r   r(   c                 <    |                      | j        d           d S NiA  )rB   r(   rE   s     r   check_security_dirzProfileDir.check_security_dir   s    D%w/////r   r.   c                 <    |                      | j        d           d S rR   )rB   r.   rE   s     r   check_pid_dirzProfileDir.check_pid_dir   s    DL'*****r   c                     |                                   |                                  |                                  |                                  d S rD   )rS   rF   rU   rP   )r2   s    r   r1   zProfileDir.check_dirs   sP    !!!     r   config_filec                 \   t          t          j                            | j        |                    }|                                r|sdS |.t          j                            t                      ddd          }t          |t                     sJ ||z  }t          j	        ||           dS )zCopy a default config file into the active profile directory.

        Default configuration files are kept in :mod:`IPython.core.profile`.
        This function moves these from that location to the working profile
        directory.
        FNrI   rJ   defaultT)
r   r$   r%   r&   r   r8   r   
isinstancerL   rM   )r2   rW   r%   	overwritedstrO   s         r   copy_config_filezProfileDir.copy_config_file   s     27<<{;;<<::<< 		 	5<7<< 7 9 97JPZ[[D$%%%%%[ Ctr   c                      | ||          S )zCreate a new profile directory given a full path.

        Parameters
        ----------
        profile_dir : str
            The full path to the profile directory.  If it does exist, it will
            be used.  If not, it will be created.
        r   r   r   clsprofile_dirr   s      r   create_profile_dirzProfileDir.create_profile_dir   s     sK7777r   rY   c                     t           j                            |          st          d|z            t           j                            |d|z             } | ||          S )a?  Create a profile dir by profile name and path.

        Parameters
        ----------
        path : unicode
            The path (directory) to put the profile directory in.
        name : unicode
            The name of the profile.  The name of the profile directory will
            be "profile_<profile>".
        zDirectory not found: %sprofile_r_   )r$   r%   isdirr   r&   )ra   r%   namer   rb   s        r   create_profile_dir_by_namez%ProfileDir.create_profile_dir_by_name   s^     w}}T"" 	D!";d"BCCCgll4t);<<sK7777r   c                     d|z   }|g}|D ]P}t           j                            ||          }t           j                            |          r | ||          c S Qt	          d|z            )af  Find an existing profile dir by profile name, return its ProfileDir.

        This searches through a sequence of paths for a profile dir.  If it
        is not found, a :class:`ProfileDirError` exception will be raised.

        The search path algorithm is:
        1. ``os.getcwd()`` # removed for security reason.
        2. ``ipython_dir``

        Parameters
        ----------
        ipython_dir : unicode or str
            The IPython directory to use.
        name : unicode or str
            The name of the profile.  The name of the profile directory
            will be "profile_<profile>".
        re   r_   z(Profile directory not found in paths: %s)r$   r%   r&   rf   r   )ra   ipython_dirrg   r   dirnamepathsprb   s           r   find_profile_dir_by_namez#ProfileDir.find_profile_dir_by_name   s    & $ 	X 	XA',,q'22Kw}}[)) @sK??????@ ""Lw"VWWWr   c                     t          |          }t          j                            |          st	          d|z             | ||          S )zFind/create a profile dir and return its ProfileDir.

        This will create the profile directory if it doesn't exist.

        Parameters
        ----------
        profile_dir : unicode or str
            The path of the profile directory.
        zProfile directory not found: %sr_   )r   r$   r%   rf   r   r`   s      r   find_profile_dirzProfileDir.find_profile_dir   sQ     "+..w}}[)) 	S!"Ck"QRRRsK7777r   rD   )F)rY   N)&r   r   r   __doc__r	   r'   r)   r+   r-   r/   r(   r*   r,   r.   r0   tagr   r
   r"   r   r4   strr   intboolrB   rF   rP   rS   rU   r1   r   r]   classmethodrc   rh   rn   rp   r   r   r   r   r      s          
++75>>Lwy))75>>Lgh''O73<<LgcllG'#,,KgcllGJws
 
 
 #T#

 
 d5kkOWZ  - -3 -hsm -t - - - -^ WY" " " " W]     W^0 0 0 0 WY+ + + +! ! ! C t QU    " 	8 	8 	8 [	8 8 8 8 [8  X X X [X6 8 8 8 [8 8 8r   r   )rq   r$   rL   r?   pathlibr   traitlets.config.configurabler   rl   r   
utils.pathr   r   	traitletsr	   r
   r   typingr   	Exceptionr   r   r   r   r   <module>r}      s   9 9
 
			         = = = = = = + + + + + + 7 7 7 7 7 7 7 7 , , , , , , , , , ,      	 	 	 	 	i 	 	 	U8 U8 U8 U8 U8$ U8 U8 U8 U8 U8r   