o
    Zh(                     @   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 ddlZedZd	ej	ejeef  f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+)(.*$)returnc                  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 ^-..xZopenbsdZ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_aliasesZ
ls_aliases r&   I/var/www/html/lang_env/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)   t       r)   c                   @   r(   )InvalidAliasErrorNr*   r&   r&   r&   r'   r/   x   r.   r/   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.
    >   ZpushdZdhistcdaliasZpopdZunaliasc                 C   s,   || _ || _|| _d|| _|  | _d S )NzAlias for `!{}`)shellr!   cmdformat__doc__validatenargs)selfr3   r!   r4   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!   	blacklistr/   r3   magics_managermagicsKeyError
isinstancer0   r4   strcountfind)r9   callerr8   r&   r&   r'   r7      s*   
zAlias.validatec                 C   s   d | j| jS )Nz<alias {} for {!r}>)r5   r!   r4   r9   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 )
Nr>   r   rJ   r=   r   r<   z%s %sz+Alias <%s> requires %s arguments, %s given. )r4   r8   rF   replacesplitlenr   r!   tuplejoinr3   system)r9   restr4   r8   argsr&   r&   r'   __call__   s    *zAlias.__call__N)rJ   )	r+   r,   r-   r6   r?   r:   r7   rI   rT   r&   r&   r&   r'   r0   {   s    r0   c                       s   e Zd ZU ee jddZeed< eg djddZeed< 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)configr%   )default_valueuser_aliasesz1IPython.core.interactiveshell.InteractiveShellABC)
allow_noneNc                    sD   t t| jdd|i| | jd ur | jjjd | _|   d S d S )Nr3   r;   r&   )superrU   r:   r3   r@   rA   
linemagicsinit_aliases)r9   r3   kwargs	__class__r&   r'   r:      s
   
zAliasManager.__init__c                 C   sR   | j | j D ] \}}|dr | jd ur | jjdkr |dd}| || qd S )Nzls ZNoColorz --colorrJ   )r%   rX   r$   r3   colorsrL   soft_define_alias)r9   r!   r4   r&   r&   r'   r\      s   
zAliasManager.init_aliasesc                 C   s   dd | j  D S )Nc                 S   s$   g | ]\}}t |tr||jfqS r&   )rC   r0   r4   ).0nfuncr&   r&   r'   
<listcomp>   s    z(AliasManager.aliases.<locals>.<listcomp>)r[   itemsrH   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   )r9   r!   r4   er&   r&   r'   ra      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.
        )r3   r!   r4   r;   )Z
magic_kindZ
magic_nameN)r0   r3   r@   Zregister_function)r9   r!   r4   rG   r&   r&   r'   rh      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[   getrC   r0   )r9   r!   Z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)rk   r9   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)rm   r[   
ValueErrorrl   r&   r&   r'   undefine_alias   s   
zAliasManager.undefine_aliasc                 C   s   | j D ]	\}}| | qd S N)rg   rp   )r9   r!   _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.rn   )rk   r4   ro   )r9   r!   rG   r&   r&   r'   retrieve_alias  s   
zAliasManager.retrieve_aliasrq   )r+   r,   r-   r   r%   tag__annotations__rX   r   r3   r:   r\   propertyrg   ra   rh   rk   rm   rp   rs   rt   __classcell__r&   r&   r^   r'   rU      s"   
 

rU   )r6   r    rer"   Ztraitlets.config.configurabler   r   r   Z	traitletsr   r   loggingtypingtcompileZshell_line_splitTuplerD   r%   	Exceptionr)   r/   objectr0   rU   r&   r&   r&   r'   <module>   s   
IH