o
    ˷e2'                     @   s   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dZd	d
 ZG dd deZG dd deZG dd deZG dd deZdS )zE
System command aliases.

Authors:

* Fernando Perez
* Brian Granger
    N)Configurable   )
UsageError)ListInstance)errorz^(\s*)()(\S+)(.*$)c                  C   s|   t jdkr/g d} tjdrg d}ntjds tjdr%g d}ng d}| | } | 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_aliases r(   I/var/www/ideatree/venv/lib/python3.10/site-packages/IPython/core/alias.pyr&   (   s   





r&   c                   @      e Zd ZdS )
AliasErrorN__name__
__module____qualname__r(   r(   r(   r)   r+   q       r+   c                   @   r*   )InvalidAliasErrorNr,   r(   r(   r(   r)   r1   u   r0   r1   c                   @   s:   e Zd ZdZh dZdd Zdd Zdd Zd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                 C   s,   || _ || _|| _d|| _|  | _d S )NzAlias for `!{}`)shellr"   cmdformat__doc__validatenargs)selfr9   r"   r:   r(   r(   r)   __init__   s
   zAlias.__init__c                 C   s   | j | jv rtd| j  z| jjjd | j  }W n	 ty"   Y nw t|ts/td| j  t| j	t
s<td| j	 | j	d| j	d }|dkrX| j	ddkrXt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"   	blacklistr1   r9   magics_managermagicsKeyError
isinstancer2   r:   strcountfind)r?   callerr>   r(   r(   r)   r=      s*   
zAlias.validatec                 C   s   d | j| jS )Nz<alias {} for {!r}>)r;   r"   r:   r?   r(   r(   r)   __repr__   s   zAlias.__repr__ c                 C   s   | j }| j}|ddkr|d|}d}|dkr-|ddkr&|dd}d||f }n-|d |}t||k rEtd| j|t|f d|t|d |  d		||d  f }| j
| d S )
NrD   r   rP   rC   r   rB   z%s %sz+Alias <%s> requires %s arguments, %s given. )r:   r>   rL   replacesplitlenr   r"   tuplejoinr9   system)r?   restr:   r>   argsr(   r(   r)   __call__   s    *zAlias.__call__N)rP   )	r-   r.   r/   r<   rE   r@   r=   rO   rZ   r(   r(   r(   r)   r2   x   s    r2   c                       s   e Zd Zee jddZeg djddZedddZd fdd	Z	d	d
 Z
edd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z  ZS )AliasManagerT)config)default_valuez1IPython.core.interactiveshell.InteractiveShellABC)
allow_noneNc                    s6   t t| jdd|i| | jjjd | _|   d S )Nr9   rA   r(   )superr[   r@   r9   rF   rG   
linemagicsinit_aliases)r?   r9   kwargs	__class__r(   r)   r@      s   zAliasManager.__init__c                 C   sH   | j | j D ]\}}|dr| jjdkr|dd}| || qd S )Nzls NoColorz --colorrP   )r&   user_aliasesr%   r9   colorsrR   soft_define_aliasr?   r"   r:   r(   r(   r)   ra      s
   zAliasManager.init_aliasesc                 C   s   dd | j  D S )Nc                 S   s$   g | ]\}}t |tr||jfqS r(   )rI   r2   r:   ).0nfuncr(   r(   r)   
<listcomp>   s    z(AliasManager.aliases.<locals>.<listcomp>)r`   itemsrN   r(   r(   r)   aliases   s   zAliasManager.aliasesc              
   C   sF   z	|  || W dS  ty" } ztd|  W Y d}~dS d}~ww )z2Define an alias, but don't raise on an AliasError.zInvalid alias: %sN)define_aliasr+   r   )r?   r"   r:   er(   r(   r)   rh      s   zAliasManager.soft_define_aliasc                 C   s(   t | j||d}| jjj|d|d dS )zDefine a new alias after validating it.

        This will raise an :exc:`AliasError` if there are validation
        problems.
        )r9   r"   r:   rA   )
magic_kind
magic_nameN)r2   r9   rF   register_function)r?   r"   r:   rM   r(   r(   r)   rp      s   
zAliasManager.define_aliasc                 C   s    | j |d}t|tr|S dS )z9Return an alias, or None if no alias by that name exists.N)r`   getrI   r2   )r?   r"   anamer(   r(   r)   	get_alias   s   zAliasManager.get_aliasc                 C   s   |  |duS )z?Return whether or not a given name has been defined as an aliasN)rw   r?   r"   r(   r(   r)   is_alias   s   zAliasManager.is_aliasc                 C   s"   |  |r| j|= d S td| )N%s is not an alias)ry   r`   
ValueErrorrx   r(   r(   r)   undefine_alias   s   
zAliasManager.undefine_aliasc                 C   s   | j D ]	\}}| | qd S N)ro   r|   ri   r(   r(   r)   clear_aliases   s   zAliasManager.clear_aliasesc                 C   s    |  |}|r
|jS td| )z/Retrieve the command to which an alias expands.rz   )rw   r:   r{   )r?   r"   rM   r(   r(   r)   retrieve_alias   s   
zAliasManager.retrieve_aliasr}   )r-   r.   r/   r   r&   tagrf   r   r9   r@   ra   propertyro   rh   rp   rw   ry   r|   r~   r   __classcell__r(   r(   rc   r)   r[      s    

r[   )r<   r!   rer#   traitlets.config.configurabler   r   r   	traitletsr   r   loggingcompileshell_line_splitr&   	Exceptionr+   r1   objectr2   r[   r(   r(   r(   r)   <module>   s   
IH