Mini Shell

Direktori : /usr/lib/python3.6/site-packages/enchant/checker/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/enchant/checker/__pycache__/CmdLineChecker.cpython-36.pyc

3

��]�+�@s�dZddlZddlmZddlmZyeZWnek
rDe	ZYnXddddd	d
ddd
d
dd�Z
d!dd�Zdd�Zdd�Z
dd�Zdd�ZGdd�d�Zdd�Zed kr�e�dS)"a

    enchant.checker.CmdLineChecker:  Command-Line spell checker

    This module provides the class CmdLineChecker, which interactively
    spellchecks a piece of text by interacting with the user on the
    command line.  It can also be run as a script to spellcheck a file.

�N)�SpellChecker)�printfzzzzzzzzzz)�normalZblack�red�green�yellow�blueZpurple�cyanZgreyZgray�boldr�cCs.tjj�r"t|||tdS||SdS)aB
    Change text color for the Linux terminal.

    Args:
        string (str): String to colorify
        color (str): Color to colorify the string in the following list:
            black, red, green, yellow, blue, purple, cyan, gr[ae]y
        prefix (str): Prefix to add to string (ex: Beginning of line graphics)
    rN)�sys�stdout�isatty�colors)�string�color�prefix�r�$/usr/lib/python3.6/CmdLineChecker.pyrBs

rcCsdtddd�d|S)N�[�+r)rz] )r)rrrr�successQsrcCsdtddd�d|S)Nr�!r)rz] )r)rrrr�errorTsrcCsdtddd�d|S)Nr�*r)rz] )r)rrrr�warningWsrcCsdtddd�d|S)Nr�.r)rz] )r)rrrr�infoZsrc@s|eZdZdZddgZdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
dd��Zdd�Zdd�Z
dd�Zddd�Zddddge_dS)�CmdLineCheckeraA simple command-line spell checker.

    This class implements a simple command-line spell checker.  It must
    be given a SpellChecker instance to operate on, and interacts with
    the user by printing instructions on stdout and reading commands from
    stdin.
    r
�stdincCsd|_d|_dS)NF)�_stop�_checker)�selfrrr�__init__hszCmdLineChecker.__init__cCs
||_dS)N)r!)r"�chkrrrr�set_checkerlszCmdLineChecker.set_checkercCs|jS)N)r!)r"r$rrr�get_checkeroszCmdLineChecker.get_checkercCs\d|_xP|jD]F}||_|j�|j�|j�}x|rJ|jrJ|j�}q2W|jrPqWdS)zRun the spellchecking loop.FN)r r!r�print_error�print_suggestions�read_command)r"�errZstatusrrr�runrszCmdLineChecker.runcCsh|j|jj�|jj|jj�}ttdt|jjdd��g�ttd�g�tt|�g�ttd�g�dS)a2print the spelling error to the console.

        Prints the misspelled word along with 100 characters of
        context on either side.  This number was arbitrarily chosen
        and could be modified to be tunable or changed entirely.
        It seems to be enough context to be helpful though
        z	ERROR: %sr)rrN)�_build_contextr�get_text�wordZwordposrrr)r"Zerror_stringrrrr's
zCmdLineChecker.print_errorcCs:|jdd|�}|jd|�}||d|�j|t|dd��S)z�creates the context line.

        This function will search forward and backward
        from the error word to find the nearest newlines.
        it will return this line with the error word
        colored red.�
r�r)r)�rfind�find�replacer)�textZ
error_wordZerror_startZ
start_newlineZend_newlinerrrr,�szCmdLineChecker._build_contextcCs�d}|jj�}xjt|�D]^\}}|dkrN|tt|�dd�dt|dd�}q|dtt|�dd�dt|dd�}qWttd�|g�d	S)
a,Prints out the suggestions for a given error.

        This function will add vertical pipes to separate choices
        as well as the index of the replacement as expected by the replace function.
        I don't believe zero indexing is a problem as long as the user can see the numbers :)
        rrr)rz: r
z | z
HOW ABOUT:N)r�suggest�	enumerater�strrr)r"�resultZsuggestions�indexZsuggrrrr(�s
&,z CmdLineChecker.print_suggestionscCs�tttddd�dtddd�dtddd�d	�g�tttd
dd�tddd�dtd
dd�tddd�dtddd�d	�g�tttd
dd�dtddd�d�g�tttddd�dtddd�d�g�tttddd�dtddd�d�g�tttddd�dtddd�d�g�tttddd�dtddd�d�g�tttddd�dtddd�d�g�ttd �g�|j�dS)!N�0r)rz..�Nz:	r3r
z with the numbered suggestion�Rr	zalways replace�iz:		�ignorez
 this word�Iz
always ignore�a�addz word to personal dictionary�eZeditz	 the word�q�quitz	 checking�hz:		print this �helpz messagez4----------------------------------------------------)rrrr()r"rrr�
print_help�s:R******zCmdLineChecker.print_helpcCs�td�}|j�}|j�r�t|�}|jj�}|t|�krJttd�|g�dStt	dt
|jjdd�t
||dd�f�g�|jj||�dS|d	d
k�r
|dd�j�s�ttd�g�dSt|dd��}|jj�}|t|�kr�ttd�|g�dS|jj
||�dS|d
k�rdS|dk�r0|jj�dS|dk�rH|jj�dS|dk�rrttd��}|jj|j��dS|dk�r�d|_dSdj|j���r�|j�dSttd�g�dS)Nz>> zNo suggestion numberFzReplacing '%s' with '%s'r)rrTrr<r0z$Badly formatted command (try 'help')r=r?r@rBz
New Word: rCrF)�	get_input�strip�isdigit�intrr5�lenrrrrr.r3Zreplace_alwaysZ
ignore_alwaysrArr �
startswith�lowerrG)r"�cmd�replZsuggsrrrr)�sT
.







zCmdLineChecker.read_commandNcCs�djt|d�j��}|dk	r&|j|�}|jj|�d|}tt|�g�ttdt|��g�|j	�tt
d|�g�|jj�}|dk	r�|j|�}|dkr�t|d�}n|dkr�t
j}n
t|d�}|j|�|j�dS)aRun spellchecking on the named file.
        This method can be used to run the spellchecker over the named file.
        If <outfile> is not given, the corrected contents replace the contents
        of <infile>.  If <outfile> is given, the corrected contents will be
        written to that file.  Use "-" to have the contents written to stdout.
        If <enc> is given, it specifies the encoding used to read the
        file's contents into a unicode string.  The output will be written
        in the same encoding.
        r�rNzBeginning spell check of %s�-zCompleted spell check of %s�w)�join�file�	readlines�decoder!Zset_textrrrLr+rr-�encoderr
�write�close)r"�infile�outfile�encZinStrZ	begin_msgZoutStrZoutFrrr�run_on_file�s&





zCmdLineChecker.run_on_filer\r[)NN)�__name__�
__module__�__qualname__�__doc__Z_DOC_ERRORSr#r%r&r+r'�staticmethodr,r(rGr)r^rrrrr^s
5
rcCs�ddlm}|�}|jdddddd�|jd	d
ddd
dd�|jdddddd�|j�\}}t|�dkrptd��t|�dkr�td��t|j�}t�}|j	|�|j
|d|j|j�dS)z�Run the command-line spellchecker as a script.
    This function allows the spellchecker to be invoked from the command-line
    to check spelling in a file.
    r)�OptionParserz-oz--outputr\�FILEzwrite changes into FILE)�dest�metavarrFz-lz--lang�langZTAGZen_USzuse language idenfified by TAG)rfrg�defaultrFz-ez
--encodingr]ZENCz!file is unicode with encoding ENCr0zMust name a file to checkzCan only check a single fileN)
ZoptparserdZ
add_option�
parse_argsrL�
ValueErrorrrhrr%r^r\r])rd�opZopts�argsr$Zcmdlnrrr�_run_as_script
s"

rn�__main__)rr)rbrZenchant.checkerrZ
enchant.utilsrZ	raw_inputrH�	NameError�inputrrrrrrrrnr_rrrr�<module>&s8

-