
    &e2'                         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dS )zE
System command aliases.

Authors:

* Fernando Perez
* Brian Granger
    N)Configurable   )
UsageError)ListInstance)errorz^(\s*)()(\S+)(.*$)c                  :   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     2lib/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-   q           Dr+   r-   c                       e Zd ZdS )InvalidAliasErrorNr.   r2   r+   r*   r5   r5   u   r3   r+   r5   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$   r@   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$   	blacklistr5   r?   magics_managermagics
isinstancer7   KeyErrorr@   strcountfind)rE   callerrD   s      r*   rC   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}>)rA   r$   r@   rE   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 )NrK   r   rX   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__   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)rX   )	r/   r0   r1   rB   rL   rF   rC   rW   rc   r2   r+   r*   r7   r7   x   sp          @??I% % %  4A A A     r+   r7   c                       e Zd Z e e                                          d          Z eg                               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_noneNc                      t          t          |           j        dd|i| | j        j        j        d         | _        |                                  d S )Nr?   rH   r2   )superre   rF   r?   rM   rN   
linemagicsinit_aliases)rE   r?   kwargs	__class__s      r*   rF   zAliasManager.__init__   sW    *lD!!*AAA&AAA*3:6Br+   c                     | j         | j        z   D ]V\  }}|                    d          r&| j        j        dk    r|                    dd          }|                     ||           Wd S )Nzls NoColorz --colorrX   )r(   user_aliasesr'   r?   colorsr[   soft_define_aliasrE   r$   r@   s      r*   rl   zAliasManager.init_aliases   sy    -0AA 	. 	.ID#~~e$$ 2):i)G)Gkk*b11""4----	. 	.r+   c                 H    d | j                                         D             S )Nc                 P    g | ]#\  }}t          |t                    ||j        f$S r2   )rO   r7   r@   ).0nfuncs      r*   
<listcomp>z(AliasManager.aliases.<locals>.<listcomp>   s@     8 8 8)1d)$668DH 8 8 8r+   )rk   itemsrV   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   )rE   r$   r@   es       r*   rs   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$   r@   rH   )
magic_kind
magic_nameN)r7   r?   rM   register_function)rE   r$   r@   rT   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)rk   getrO   r7   )rE   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   rE   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   rk   
ValueErrorr   s     r*   undefine_aliaszAliasManager.undefine_alias   s:    == 	:%%%1D8999r+   c                 J    | j         D ]\  }}|                     |           d S N)r|   r   rt   s      r*   clear_aliaseszAliasManager.clear_aliases   s8     	& 	&ID#%%%%	& 	&r+   c                 b    |                      |          }|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   s7    %% 	::1D8999r+   r   )r/   r0   r1   r   r(   tagrq   r   r?   rF   rl   propertyr|   rs   r~   r   r   r   r   r   __classcell__)rn   s   @r*   re   re      s4       d??,,--111>>O4b)))--T-::LHHUYZZZE     . . . 8 8 X8+ + +E E E; ; ;
0 0 0: : :& & &: : : : : : :r+   re   )rB   r#   rer%   traitlets.config.configurabler   r   r   	traitletsr   r   loggingcompileshell_line_splitr(   	Exceptionr-   r5   objectr7   re   r2   r+   r*   <module>r      sg   * 
			 				 



 6 6 6 6 6 6       $ $ $ $ $ $ $ $       2:344 F F FR	 	 	 	 	 	 	 		 	 	 	 	
 	 	 	B B B B BF B B BPB: B: B: B: B:< B: B: B: B: B:r+   