a �DOg :�@s<ddlZddlZdgZdZejejdZGdd�d�ZdS)�N�Cmdz(Cmd) �_c@s�eZdZeZeZdZdZdZ dZ dZ dZ dZ dZdZd/d d �Zd0d d �Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Z d1d-d.�Z!dS)2r�=�Nz(Documented commands (type help ):zMiscellaneous help topics:zUndocumented commands:z*** No help on %s��tabcCs@|dur||_ntj|_|dur(||_ntj|_g|_||_dS�N)�stdin�sys�stdout�cmdqueue� completekey)�selfr r r �r�/usr/lib64/python3.9/cmd.py�__init__Ls z Cmd.__init__cCs�|��|jrZ|jrZz2ddl}|��|_|�|j�|�|jd�Wnt yXYn0�z|durl||_ |j r�|j � t |j �d�d}|�s2|jr�|j�d�}nj|jr�zt|j�}Wnty�d}Yn0n<|j � |j�|j ��|j��}t|��sd}n |�d�}|�|�}|�|�}|�||�}q�|��W|j�r�|j�r�zddl}|�|j�Wnt �yxYn0n@|j�r�|j�r�zddl}|�|j�Wnt �y�Yn00dS)Nrz : complete� �EOFz )�preloop� use_rawinputr �readlineZ get_completerZ old_completerZ set_completer�complete�parse_and_bind� ImportError�intror �write�strr �pop�input�prompt�EOFError�flushr �len�rstrip�precmd�onecmd�postcmd�postloop)rrr�stop�linerrr�cmdloopbsZ             �z Cmd.cmdloopcCs|Srr�rr)rrrr$�sz Cmd.precmdcCs|Srr)rr(r)rrrr&�sz Cmd.postcmdcCsdSrr�rrrrr�sz Cmd.preloopcCsdSrrr,rrrr'�sz Cmd.postloopcCs�|��}|sdd|fS|ddkr4d|dd�}n2|ddkrft|d�r\d|dd�}n dd|fSdt|�}}||kr�|||jvr�|d}qt|d|�||d���}}|||fS)Nr�?zhelp r�!Zdo_shellzshell )�strip�hasattrr"� identchars)rr)�i�n�cmd�argrrr� parseline�s      z Cmd.parselinecCs�|�|�\}}}|s|��S|dur.|�|�S||_|dkrBd|_|dkrT|�|�Szt|d|�}Wnty�|�|�YS0||�SdS)Nrr�do_)r6� emptyline�default�lastcmd�getattr�AttributeError)rr)r4r5�funcrrrr%�s    z Cmd.onecmdcCs|jr|�|j�SdSr)r:r%r,rrrr8�sz Cmd.emptylinecCs|j�d|�dS)Nz*** Unknown syntax: %s )r rr+rrrr9�sz Cmd.defaultcGsgSrr)r�ignoredrrr�completedefault�szCmd.completedefaultcsd|��fdd�|��D�S)Nr7cs"g|]}|���r|dd��qS)�N�� startswith��.0�a�Zdotextrr� ��z%Cmd.completenames..)� get_names)r�textr>rrFr� completenames�szCmd.completenamesc Cs�|dkr�ddl}|��}|��}t|�t|�}|��|}|��|}|dkr�|�|�\} } } | dkrp|j} q�zt|d| �} Wq�t y�|j} Yq�0n|j } | ||||�|_ z |j |WSt y�YdS0dS)NrrZ complete_) rZget_line_buffer�lstripr"Z get_begidxZ get_endidxr6r?r;r<rKZcompletion_matches� IndexError) rrJ�staterZorigliner)�strippedZbegidxZendidxr4�argsZfooZcompfuncrrrr�s*     z Cmd.completecCs t|j�Sr)�dir� __class__r,rrrrIsz Cmd.get_namescs4t|j���}t�fdd�|��D��}t||B�S)Nc3s,|]$}|�d�d�r|dd�VqdS)�help_r�NrArC�rPrr� s�z$Cmd.complete_help..)�setrKrI�list)rrP�commandsZtopicsrrUr� complete_helpszCmd.complete_helpc Cs�|r�zt|d|�}Wnxty�z4t|d|�j}|rV|j�dt|��WYdSWntyjYn0|j�dt|j|f��YdS0|��n|��}g}g}i}|D]$}|dd�dkr�d||dd�<q�|��d} |D]p}|dd�dkr�|| k�rq�|} |dd�} | |v�r4|� | �|| =q�t||�j�rN|� | �q�|� | �q�|j�dt|j ��|� |j |dd �|� |j t|���dd �|� |j|dd �dS) NrSr7�%s rTrrr@��P)r;r<�__doc__r rr�nohelprI�sort�append� doc_leader� print_topics� doc_header� misc_headerrX�keys� undoc_header) rr5r=�doc�namesZcmds_docZ cmds_undoc�help�nameZprevnamer4rrr�do_help$sN          z Cmd.do_helpcCs\|rX|j�dt|��|jr<|j�dt|jt|���|�||d�|j�d�dS)Nr[rr)r rr�rulerr"� columnize)r�headerZcmdsZcmdlenZmaxcolrrrrcRs zCmd.print_topicsr]cs��s|j�d�dS�fdd�tt���D�}|rJtdd�tt|����t��}|dkrv|j�dt�d��dStdt���D]�}||d|}g}d }t|�D]h} d} t|�D]2} | || } | |kr�q�| } t| t| ��} q�|� | �|| d 7}||kr��qq�||kr��q4q�t��}d}dg}t|�D]�} g}t|�D]4} | || } | |k�rld } n�| } |� | ��qL|�r�|d �s�|d =�q�tt|��D]} || � || �|| <�q�|j�dtd �|����q csg|]}t�|t�s|�qSr)� isinstancer)rDr2�rXrrrGds�z!Cmd.columnize..z list[i] not a string for i in %sz, rr[r������r�����z ) r r�ranger"� TypeError�join�mapr�maxra�ljust)rrXZ displaywidthZ nonstrings�sizeZnrowsZncolsZ colwidthsZtotwidth�colZcolwidth�rowr2�xZtextsrrqrrnZs\ �          z Cmd.columnize)rNN)N)r])"�__name__� __module__� __qualname__�PROMPTr� IDENTCHARSr1rmr:rrbrdrergr_rrr*r$r&rr'r6r%r8r9r?rKrrIrZrlrcrnrrrrr4s:   4   .)�stringr �__all__r�� ascii_letters�digitsr�rrrrr�-s