
    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	m
Z
 ddlmZ ddlZ ej        d          Zd	ej	        ej        eef                  fd
Z G d de          Z G d de          Z G d d          Z G d de          ZdS )zE
System command aliases.

Authors:

* Fernando Perez
* Brian Granger
    N)Configurable   )
UsageError)ListInstance)errorz^(\s*)()(\S+)(.*$)returnc                  :   t           j        dk    rug d} t          j                            d          rg d}nGt          j                            d          st          j                            d          rg d}ng d}| |z   } nt           j        d	v rg d
} ng } | S )z1Return list of shell aliases to auto-define.
    posix)mkdirr   rmdirr   )mvr   )rmr   )cpr   )catr   linux))lszls -F --color)llzls -F -o --color)lfzls -F -o --color %l | grep ^-)lkzls -F -o --color %l | grep ^l)ldirzls -F -o --color %l | grep /$)lxz ls -F -o --color %l | grep ^-..xopenbsdnetbsd))r   zls -F)r   zls -F -l)r   zls -F -l %l | grep ^-)r   zls -F -l %l | grep ^l)r   zls -F -l %l | grep /$)r   zls -F -l %l | grep ^-..x))r   zls -F -G)r   zls -F -l -G)r   zls -F -l -G %l | grep ^-)r   zls -F -l -G %l | grep ^l)r   zls -F -G -l %l | grep /$)r   zls -F -l -G %l | grep ^-..x)ntdos))r   zdir /on)ddirdir /ad /on)r   r    r   r   )echor!   )renr"   )copyr#   )osnamesysplatform
startswith)default_aliases
ls_aliasess     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/alias.pyr)   r)   +   s     
w'   <""7++ )	  JJ \$$Y// 	3<3J3J83T3T 	  JJ  J *J6	M	!	!       c                       e Zd ZdS )
AliasErrorN__name__
__module____qualname__ r,   r+   r.   r.   t           Dr,   r.   c                       e Zd ZdS )InvalidAliasErrorNr/   r3   r,   r+   r6   r6   x   r4   r,   r6   c                   4    e Zd ZdZh dZd Zd Zd Zd	dZdS )
AliaszCallable object storing the details of one alias.

    Instances are registered as magic functions to allow use of aliases.
    >   cdpopdaliasdhistpushdunaliasc                     || _         || _        || _        d                    |          | _        |                                 | _        d S )NzAlias for `!{}`)shellr%   cmdformat__doc__validatenargs)selfr@   r%   rA   s       r+   __init__zAlias.__init__   s?    
	(//44]]__


r,   c                 B   | j         | j        v rt          d| j         z            	 | j        j        j        d         | j                  }t          |t                    st          d| j         z            n# t          $ r Y nw xY wt          | j	        t                    st          d| j	        z            | j	                            d          | j	                            d          z
  }|dk    r-| j	                            d          dk    rt          d	          |S )
z7Validate the alias, and return the number of arguments.z@The name %s can't be aliased because it is a keyword or builtin.linezAThe name %s can't be aliased because it is another magic command.z*An alias command must be a string, got: %r%s%%sr   %lzEThe %s and %l specifiers are mutually exclusive in alias definitions.)r%   	blacklistr6   r@   magics_managermagics
isinstancer8   KeyErrorrA   strcountfind)rF   callerrE   s      r+   rD   zAlias.validate   s\   9&&# %JLPI%V W W W	\Z.5f=diHF fe,, \' )OQUQZ)[ \ \ \\  	 	 	D	 48S)) 	:# %.04%9 : : : t$$tx~~e'<'<<AIIDHMM$//144# %F G G G s   "A6 6
BBc                 B    d                     | j        | j                  S )Nz<alias {} for {!r}>)rB   r%   rA   rF   s    r+   __repr__zAlias.__repr__   s    $++DItx@@@r,    c           
      N   | j         }| j        }|                    d          dk    r|                    d|          }d}|dk    r7|                    d          dk    r|                    dd          }|d|}n|                    d |          }t          |          |k     r+t          d| j        d	|d
t          |          d          |t          |d |                   z  dd	                    ||d                    }| j
                            |           d S )NrL   r   rY   rK   r   rJ    zAlias <z> requires z arguments, z given.)rA   rE   rT   replacesplitlenr   r%   tuplejoinr@   system)rF   restrA   rE   argss        r+   __call__zAlias.__call__   s2   h
88D>>Q++dD))CD!88xx!##kk%.. SS$$'CC ::dE**D4yy5   jyyy%%%T"4 5 5 5 5fuf#6#6666sxxUVV7M7M7MNC
#r,   N)rY   )	r0   r1   r2   rC   rM   rG   rD   rX   rd   r3   r,   r+   r8   r8   |   sp          @??I% % %  4A A A     r,   r8   c                   $    e Zd ZU  e e                                          d          Zeed<    eg                               d          Zeed<    edd          Z	d fd		Z
d
 Zed             Zd Zd Zd Zd Zd Zd Zd Z xZS )AliasManagerT)configr)   )default_valueuser_aliasesz1IPython.core.interactiveshell.InteractiveShellABC)
allow_noneNc                      t          t          |           j        dd|i| | j        2| j        j        j        d         | _        |                                  d S d S )Nr@   rI   r3   )superrf   rG   r@   rN   rO   
linemagicsinit_aliases)rF   r@   kwargs	__class__s      r+   rG   zAliasManager.__init__   sg    *lD!!*AAA&AAA:!"j7>vFDO "!r,   c                     | j         | j        z   D ]]\  }}|                    d          r-| j        &| j        j        dk    r|                    dd          }|                     ||           ^d S )Nzls nocolorz --colorrY   )r)   ri   r(   r@   colorsr\   soft_define_alias)rF   r%   rA   s      r+   rn   zAliasManager.init_aliases   s    -0AA 	. 	.ID#u%%2J*J%22kk*b11""4----	. 	.r,   c                 H    d | j                                         D             S )Nc                 P    g | ]#\  }}t          |t                    ||j        f$S r3   )rP   r8   rA   ).0nfuncs      r+   
<listcomp>z(AliasManager.aliases.<locals>.<listcomp>   s@     8 8 8)1d)$668DH 8 8 8r,   )rm   itemsrW   s    r+   aliaseszAliasManager.aliases   s0    8 8t/D/D/F/F 8 8 8 	8r,   c                     	 |                      ||           dS # t          $ r}t          d|z             Y d}~dS d}~ww xY w)z2Define an alias, but don't raise on an AliasError.zInvalid alias: %sN)define_aliasr.   r   )rF   r%   rA   es       r+   rt   zAliasManager.soft_define_alias   sh    	+dC((((( 	+ 	+ 	+%)*********	+s    
A<Ac                 x    t          | j        ||          }| j        j                            |d|           dS )zDefine a new alias after validating it.

        This will raise an :exc:`AliasError` if there are validation
        problems.
        )r@   r%   rA   rI   )
magic_kind
magic_nameN)r8   r@   rN   register_function)rF   r%   rA   rU   s       r+   r~   zAliasManager.define_alias   sR     TZd<<<
!33Fv?C 	4 	E 	E 	E 	E 	Er,   c                 j    | j                             |d          }t          |t                    r|ndS )z9Return an alias, or None if no alias by that name exists.N)rm   getrP   r8   )rF   r%   anames      r+   	get_aliaszAliasManager.get_alias   s2    ##D$//"5%00:uud:r,   c                 0    |                      |          duS )z?Return whether or not a given name has been defined as an aliasN)r   rF   r%   s     r+   is_aliaszAliasManager.is_alias   s    ~~d##4//r,   c                 d    |                      |          r
| j        |= d S t          d|z            )N%s is not an alias)r   rm   
ValueErrorr   s     r+   undefine_aliaszAliasManager.undefine_alias   s:    == 	:%%%1D8999r,   c                 J    | j         D ]\  }}|                     |           d S N)r|   r   )rF   r%   _s      r+   clear_aliaseszAliasManager.clear_aliases  s8    | 	& 	&GD!%%%%	& 	&r,   c                 b    |                      |          }|r|j        S t          d|z            )z/Retrieve the command to which an alias expands.r   )r   rA   r   )rF   r%   rU   s      r+   retrieve_aliaszAliasManager.retrieve_alias  s7    %% 	::1D8999r,   r   )r0   r1   r2   r   r)   tag__annotations__ri   r   r@   rG   rn   propertyr|   rt   r~   r   r   r   r   r   __classcell__)rp   s   @r+   rf   rf      sQ         D!2!23377t7DDOTDDDB///3343@@L$@@@H;  E           	. 	. 	. 8 8 X8+ + +E E E; ; ;
0 0 0: : :& & &: : : : : : :r,   rf   )rC   r$   rer&   traitlets.config.configurabler   r   r   	traitletsr   r   loggingtypingtcompileshell_line_splitTuplerR   r)   	Exceptionr.   r6   r8   rf   r3   r,   r+   <module>r      s   * 
			 				 



 6 6 6 6 6 6       $ $ $ $ $ $ $ $           2:344 FS 12 F F F FR	 	 	 	 	 	 	 		 	 	 	 	
 	 	 	B B B B B B B BPH: H: H: H: H:< H: H: H: H: H:r,   