
    Xh'                        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y)zE
System command aliases.

Authors:

* Fernando Perez
* Brian Granger
    N)Configurable   )
UsageError)ListInstance)errorz^(\s*)()(\S+)(.*$)returnc                  L   t         j                  dk(  rvg d} t        j                  j	                  d      rg d}nGt        j                  j	                  d      st        j                  j	                  d      rg d}ng d}| |z   } | S t         j                  d	v rg d
} | S 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     F/var/www/html/myenv/lib/python3.12/site-packages/IPython/core/alias.pyr)   r)   +   s     
ww' <<""7+J \\$$Y/3<<3J3J83TJJ *J6  
M	!      c                       e Zd Zy)
AliasErrorN__name__
__module____qualname__ r,   r+   r.   r.   t       r,   r.   c                       e Zd Zy)InvalidAliasErrorNr/   r3   r,   r+   r6   r6   x   r4   r,   r6   c                   2    e Zd ZdZh dZd Zd Zd ZddZy)	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j                  |      | _        | j                         | _        y )NzAlias for `!{}`)shellr%   cmdformat__doc__validatenargs)selfr@   r%   rA   s       r+   __init__zAlias.__init__   s6    
	(//4]]_
r,   c                 d   | j                   | j                  v rt        d| j                   z        	 | j                  j                  j
                  d   | j                      }t        |t              st        d| j                   z        t        | j                  t              st        d| j                  z        | j                  j                  d      | j                  j                  d      z
  }|dkD  r)| j                  j                  d      dk\  rt        d	      |S # t        $ r Y w xY w)
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,   99&# %JLPII%V W W	\ZZ..55f=diiHF fe,' )OQUQZQZ)[ \ \ 488S)# %.04%9 : : t$txx~~e'<<AIDHHMM$/14# %F G G #  		s   0D# #	D/.D/c                 N    dj                  | j                  | j                        S )Nz<alias {} for {!r}>)rB   r%   rA   )rF   s    r+   __repr__zAlias.__repr__   s    $++DIItxx@@r,   c           
          | j                   }| j                  }|j                  d      dk\  r|j                  d|      }d}|dk(  r.|j                  d      dk\  r|j                  dd      }|d|}np|j	                  d |      }t        |      |k  r(t        d| j                  d	|d
t        |      d      |t        |d |       z  ddj                  ||d        }| j                  j                  |       y )NrL   r    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__   s    hh

88D>Q++dD)CD!8xx!#kk%. $'C ::dE*D4y5  yy%T"4 5 5 5fu#66sxxUV7MNC

#r,   N)rY   )	r0   r1   r2   rC   rM   rG   rD   rW   rc   r3   r,   r+   r8   r8   |   s$     @I%4Ar,   r8   c                        e Zd ZU  e e             j                  d      Zeed<    eg       j                  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_nonec                     t        t        | 
  dd|i| | j                  9| j                  j                  j
                  d   | _        | j                          y y )Nr@   rI   r3   )superre   rG   r@   rN   rO   
linemagicsinit_aliases)rF   r@   kwargs	__class__s      r+   rG   zAliasManager.__init__   sQ    lD*AA&A::!"jj77>>vFDO "r,   c                     | j                   | j                  z   D ]_  \  }}|j                  d      r7| j                  +| j                  j                  dk(  r|j                  dd      }| j                  ||       a y )Nzls nocolorz --colorrY   )r)   rh   r(   r@   colorsr[   soft_define_alias)rF   r%   rA   s      r+   rm   zAliasManager.init_aliases   sn    --0A0AA 	.ID#u%JJ*JJ%%2kk*b1""4-	.r,   c                     | j                   j                         D cg c]#  \  }}t        |t              r||j                  f% c}}S c c}}w N)rl   itemsrP   r8   rA   )rF   nfuncs      r+   aliaseszAliasManager.aliases   sD    /3/D/D/F 8)1d)$6 DHH 8 	8 8s   (A
c                 r    	 | j                  ||       y# t        $ r}t        d|z         Y d}~y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+   rs   zAliasManager.soft_define_alias   s8    	+dC( 	+%)**	+s    	616c                     t        | j                  ||      }| j                  j                  j                  |d|       y)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   s;     TZZd<

!!33Fv?C 	4 	Er,   c                 b    | j                   j                  |d      }t        |t              r|S dS )z9Return an alias, or None if no alias by that name exists.N)rl   getrP   r8   )rF   r%   anames      r+   	get_aliaszAliasManager.get_alias   s,    ##D$/"5%0u:d:r,   c                 (    | j                  |      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                 \    | j                  |      r| j                  |= y t        d|z        )N%s is not an alias)r   rl   
ValueErrorr   s     r+   undefine_aliaszAliasManager.undefine_alias   s+    ==%1D899r,   c                 N    | j                   D ]  \  }}| j                  |        y ru   )ry   r   )rF   r%   _s      r+   clear_aliaseszAliasManager.clear_aliases  s'    || 	&GD!%	&r,   c                 \    | j                  |      }|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  s.    %::1D899r,   ru   )r0   r1   r2   r   r)   tag__annotations__rh   r   r@   rG   rm   propertyry   rs   r{   r   r   r   r   r   __classcell__)ro   s   @r+   re   re      s     !2377t7DOTDB/3343@L$@;E 	. 8 8+E;
0:&:r,   re   )rC   r$   rer&   traitlets.config.configurabler   r   r   	traitletsr   r   loggingtypingtcompileshell_line_splitTuplerR   r)   	Exceptionr.   r6   r8   re   r3   r,   r+   <module>r      s   * 
 	 
 6  $   2::34 FS 12 FR	 		
 	B BPH:< H:r,   