U
    -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|ddddddg} tjdr8d	d
ddddg}n:tjdsPtjdrbddddddg}nddddddg}| | } n$t jdkrddd ddd!d"d#g} 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   )echor   )renr   )copyr   )osnamesysplatform
startswith)default_aliasesZ
ls_aliases r%   S/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/IPython/core/alias.pyr$   (   sV    

  

    r$   c                   @   s   e Zd ZdS )
AliasErrorN__name__
__module____qualname__r%   r%   r%   r&   r'   q   s   r'   c                   @   s   e Zd ZdS )InvalidAliasErrorNr(   r%   r%   r%   r&   r,   u   s   r,   c                   @   sB   e Zd ZdZddddddh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.
    cdZpopdZpushdZdhistaliasZunaliasc                 C   s,   || _ || _|| _d|| _|  | _d S )NzAlias for `!{}`)shellr    cmdformat__doc__validatenargs)selfr0   r    r1   r%   r%   r&   __init__   s
    zAlias.__init__c                 C   s   | j | jkrtd| j  z| jjjd | j  }W n tk
rF   Y nX t|ts`td| j  t| j	t
sztd| j	 | j	d| j	d }|dkr| j	ddkrt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,   r0   magics_managermagicsKeyError
isinstancer-   r1   strcountfind)r6   callerr5   r%   r%   r&   r4      s(    
zAlias.validatec                 C   s   d | j| jS )Nz<alias {} for {!r}>)r2   r    r1   r6   r%   r%   r&   __repr__   s    zAlias.__repr__ c                 C   s   | j }| j}|ddkr*|d|}d}|dkrZ|ddkrL|dd}d||f }nZ|d |}t||k rtd| j|t|f d|t|d |  d		||d  f }| j
| d S )
Nr;   r   rG   r:   r   r9   z%s %sz+Alias <%s> requires %s arguments, %s given. )r1   r5   rC   replacesplitlenr   r    tuplejoinr0   system)r6   restr1   r5   argsr%   r%   r&   __call__   s     *zAlias.__call__N)rG   )	r)   r*   r+   r3   r<   r7   r4   rF   rQ   r%   r%   r%   r&   r-   x   s   r-   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f d|i| | jjjd | _|   d S )Nr0   r8   )superrR   r7   r0   r=   r>   
linemagicsinit_aliases)r6   r0   kwargs	__class__r%   r&   r7      s    zAliasManager.__init__c                 C   sH   | j | j D ]6\}}|dr6| jjdkr6|dd}| || qd S )Nzls ZNoColorz --colorrG   )r$   user_aliasesr#   r0   colorsrI   soft_define_aliasr6   r    r1   r%   r%   r&   rX      s    zAliasManager.init_aliasesc                 C   s   dd | j  D S )Nc                 S   s$   g | ]\}}t |tr||jfqS r%   )r@   r-   r1   ).0nfuncr%   r%   r&   
<listcomp>   s    
z(AliasManager.aliases.<locals>.<listcomp>)rW   itemsrE   r%   r%   r&   aliases   s    zAliasManager.aliasesc              
   C   sD   z|  || W n. tk
r> } ztd|  W 5 d}~X Y nX dS )z2Define an alias, but don't raise on an AliasError.zInvalid alias: %sN)define_aliasr'   r   )r6   r    r1   er%   r%   r&   r^      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.
        )r0   r    r1   r8   )Z
magic_kindZ
magic_nameN)r-   r0   r=   Zregister_function)r6   r    r1   rD   r%   r%   r&   rf      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)rW   getr@   r-   )r6   r    Zanamer%   r%   r&   	get_alias   s    zAliasManager.get_aliasc                 C   s   |  |dk	S )z?Return whether or not a given name has been defined as an aliasN)ri   r6   r    r%   r%   r&   is_alias   s    zAliasManager.is_aliasc                 C   s$   |  |r| j|= ntd| d S )N%s is not an alias)rk   rW   
ValueErrorrj   r%   r%   r&   undefine_alias   s    

zAliasManager.undefine_aliasc                 C   s   | j D ]\}}| | qd S )N)re   rn   r_   r%   r%   r&   clear_aliases   s    zAliasManager.clear_aliasesc                 C   s$   |  |}|r|jS td| dS )z/Retrieve the command to which an alias expands.rl   N)ri   r1   rm   )r6   r    rD   r%   r%   r&   retrieve_alias   s    
zAliasManager.retrieve_alias)N)r)   r*   r+   r   r$   tagr\   r   r0   r7   rX   propertyre   r^   rf   ri   rk   rn   ro   rp   __classcell__r%   r%   rZ   r&   rR      s   

rR   )r3   r   rer!   Ztraitlets.config.configurabler   r   r   Z	traitletsr   r   loggingcompileZshell_line_splitr$   	Exceptionr'   r,   objectr-   rR   r%   r%   r%   r&   <module>   s   
IH