
    f2'                         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  ej                  d      Zd	 Z G d
 de      Z G d de      Z G d de      Z G d de      Zy)zE
System command aliases.

Authors:

* Fernando Perez
* Brian Granger
    N)Configurable   )
UsageError)ListInstance)errorz^(\s*)()(\S+)(.*$)c                  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     M/var/www/cvtools/html/venv/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-   q       r+   r-   c                       e Zd Zy)InvalidAliasErrorNr.   r2   r+   r*   r5   r5   u   r3   r+   r5   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$   r@   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$   	blacklistr5   r?   magics_managermagics
isinstancer7   KeyErrorr@   strcountfind)rE   callerrD   s      r*   rC   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}>)rA   r$   r@   )rE   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 )NrK   r    rJ   r   rI    zAlias <z> requires z arguments, z given.)r@   rD   rS   replacesplitlenr   r$   tuplejoinr?   system)rE   restr@   rD   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)rX   )	r/   r0   r1   rB   rL   rF   rC   rV   rb   r2   r+   r*   r7   r7   x   s$     @I%4Ar+   r7   c                        e Zd Z e e             j                  d      Z eg       j                  d      Z 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)config)default_valuez1IPython.core.interactiveshell.InteractiveShellABC)
allow_nonec                     t        t        | 
  dd|i| | j                  j                  j
                  d   | _        | j                          y )Nr?   rH   r2   )superrd   rF   r?   rM   rN   
linemagicsinit_aliases)rE   r?   kwargs	__class__s      r*   rF   zAliasManager.__init__   sB    lD*AA&A**33::6Br+   c                     | j                   | j                  z   D ]S  \  }}|j                  d      r+| j                  j                  dk(  r|j                  dd      }| j                  ||       U y )Nzls NoColorz --colorrX   )r(   user_aliasesr'   r?   colorsrZ   soft_define_aliasrE   r$   r@   s      r*   rk   zAliasManager.init_aliases   sc    --0A0AA 	.ID#~~e$):):i)Gkk*b1""4-	.r+   c                     | j                   j                         D cg c]#  \  }}t        |t              r||j                  f% c}}S c c}}w N)rj   itemsrO   r7   r@   )rE   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   )rE   r$   r@   es       r*   rr   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$   r@   rH   )
magic_kind
magic_nameN)r7   r?   rM   register_function)rE   r$   r@   rT   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)rj   getrO   r7   )rE   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   rE   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   rj   
ValueErrorr   s     r*   undefine_aliaszAliasManager.undefine_alias   s+    ==%1D899r+   c                 N    | j                   D ]  \  }}| j                  |        y ru   )ry   r   rs   s      r*   clear_aliaseszAliasManager.clear_aliases   s'     	&ID#%	&r+   c                 \    | j                  |      }|r|j                  S t        d|z        )z/Retrieve the command to which an alias expands.r   )r   r@   r   )rE   r$   rT   s      r*   retrieve_aliaszAliasManager.retrieve_alias   s.    %::1D899r+   ru   )r/   r0   r1   r   r(   tagrp   r   r?   rF   rk   propertyry   rr   r{   r   r   r   r   r   __classcell__)rm   s   @r*   rd   rd      s    ?,-111>Ob)--T-:LHUYZE. 8 8+E;
0:&:r+   rd   )rB   r#   rer%   traitlets.config.configurabler   r   r   	traitletsr   r   loggingcompileshell_line_splitr(   	Exceptionr-   r5   objectr7   rd   r2   r+   r*   <module>r      sq   * 
 	 
 6  $  2::34 FR	 		
 	BF BPB:< B:r+   