o
    û›h(  ã                   @   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&   úHc:\Users\shubh\Videos\agent\nova\Lib\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 )ÚAliasz€Callable object storing the details of one alias.

    Instances are registered as magic functions to allow use of aliases.
    >   ZpushdÚcdZpopdÚaliasZunaliasZdhistc                 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 )zˆDefine 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