관리-도구
편집 파일: normalizer.cpython-37.opt-1.pyc
B �b�$ � @ s� d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm Z d dl mZ d dlm Z d dlmZ deeed �dd�Zde e ed �dd�Zedkr�e� dS )� N)�dumps)�abspath)�python_version)�List)�from_fp)�CliDetectionResult)�__version__�yes)�question�default�returnc C s� dddddd�}|dkrd}n(|dkr,d}n|dkr:d }nt d | ��xRtj�| | � t� �� }|dk rz|dkrz|| S ||kr�|| S tj�d� qHW dS ) a� Ask a yes/no question via input() and return their answer. "question" is a string that is presented to the user. "default" is the presumed answer if the user just hits <Enter>. It must be "yes" (the default), "no" or None (meaning an answer is required of the user). The "answer" return value is True for "yes" or False for "no". Credit goes to (c) https://stackoverflow.com/questions/3041986/apt-command-line-interface-like-yes-no-input TF)r �yZye�no�nNz [y/n] r z [Y/n] r z [y/N] zinvalid default answer: '%s'� z3Please respond with 'yes' or 'no' (or 'y' or 'n'). )� ValueError�sys�stdout�write�input�lower)r r Zvalid�promptZchoice� r �R/opt/alt/python37/lib/python3.7/site-packages/charset_normalizer/cli/normalizer.py�query_yes_no s r )�argvr c s� t jdd�}|jdt �d�ddd� |jdd d ddd d� |jddd dddd� |jddd dddd� |jddd dddd� |jddd dddd� |jdd d dd!d"d� |jd#d$d%d&td'd(d)� |jd*d+d,�tt� �d-d.� |�| �}|j d/k�r|j dk�rtd0tj d1� d2S |jd/k�r:|j dk�r:td3tj d1� d2S |jd4k �sR|jd5k�rdtd6tj d1� d2S g }�x�|jD �]��t�|j|jd7�}|�� � � d8k�r�td9��j|jd5k �r�d:nd;�tj d1� |�tt�j�d8g g d<g dd5d4d8d/�� �n|�tt�j�� j� j� fd=d>�� jD �� j� j� j� j� jd8d/�� t |�d2k�r�|j!�r�x^|D ]V��� k�rR|�tt�j��j�j�fd?d>��jD ��j�j�j�j�jd8d�� �qRW |j d/k�r� j�"d@�d/k�r�tdA��j�tj d1� �j#dk�rr��$� �qr�j�%dB�}|j dk�r4|�&dC� j� �j#dk�rp��$� n<|jdk�rpt'dD��j�dE�dk�rp�j#dk�rr��$� �qryLtdF�dB�(|���|dG _)t*|dG j)dHdIdJ��}|�+t,� �� W d8Q R X W nJ t-k �r } z*tt,|�tj d1� �j#dk�r���$� dKS d8}~X Y nX �j#dk�rr��$� �qrW |j.dk�rdtt/t |�d2k�rNdLd>� |D �n|dG j0d/dMdN�� n.x,|jD ]"�tdO�(�fdPd>�|D ��� �qlW dGS )Qz� CLI assistant using ARGV and ArgumentParser :param argv: :return: 0 if everything is fine, anything else equal trouble zvThe Real First Universal Charset Detector. Discover originating encoding used on text file. Normalize text to unicode.)Zdescription�files�rb�+zFile(s) to be analysed)�type�nargs�helpz-vz --verbose� store_trueF�verbosezjDisplay complementary information about file if any. Stdout will contain logs about the detection process.)�actionr �destr! z-az--with-alternative�alternativeszIOutput complementary possibilities if any. Top-level JSON WILL be a list.z-nz--normalize� normalizezLPermit to normalize input file. If not set, program does not write anything.z-mz --minimal�minimalzBOnly output the charset detected to STDOUT. Disabling JSON output.z-rz --replace�replacezGReplace file when trying to normalize it instead of creating a new one.z-fz--force�forcezHReplace file without asking if you are sure, use this flag with caution.z-tz--thresholdZstoreg�������?� thresholdzUDefine a custom maximum amount of chaos allowed in decoded content. 0. <= chaos <= 1.)r$ r r r% r! z --version�versionz!Charset-Normalizer {} - Python {}z"Show version information and exit.)r$ r, r! Tz.Use --replace in addition of --normalize only.)�file� z*Use --force in addition of --replace only.g g �?z---threshold VALUE should be between 0. AND 1.)r+ ZexplainNz4Unable to identify originating encoding for "{}". {}z-Maybe try increasing maximum amount of chaos.r ZUnknownc s g | ]}|� j kr|�qS r )�encoding)�.0�cp)� best_guessr r � <listcomp>� s zcli_detect.<locals>.<listcomp>c s g | ]}|� j kr|�qS r )r/ )r0 r1 )�elr r r3 � s �utfzJ"{}" file does not need to be normalized, as it already came from unicode.�.���z0Are you sure to normalize "{}" by replacing it ?r z./{}r �wzutf-8)r/ � c S s g | ] }|j �qS r )�__dict__)r0 r4 r r r r3 s � )Zensure_ascii�indentz, c s&