B _oa$@sddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdeeed d d Zde eed ddZedkredS)N)dumps)abspath)python_version)List)from_fp)CliDetectionResult) __version__yes)questiondefaultreturncCsdddddd}|dkrd}n(|dkr,d}n|dkr:d }n td |xRtj||t}|dk rz|d krz||S||kr||Stjd qHWdS) aAsk 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 . 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 yZyenonNz [y/n] r z [Y/n] rz [y/N] zinvalid default answer: '%s'z3Please respond with 'yes' or 'no' (or 'y' or 'n'). ) ValueErrorsysstdoutwriteinputlower)r r ZvalidpromptchoicerH/tmp/pip-target-avibdbtm/lib/python/charset_normalizer/cli/normalizer.py query_yes_no s   r)argvr cstjdd}|jdtdddd|jdd d d d d d|jddd d ddd|jddd d ddd|jddd d ddd|jddd d ddd|jdd d d d!d"d|jd#d$d%d&td'd(d)|jd*d+d,ttd-d.||}|j d/kr|j d krt d0t j d1d2S|jd/kr:|j d kr:t d3t j d1d2S|jd4ksR|jd5krdt d6t j d1d2Sg}x|jD]t|j|jd7}|d8krt d9j|jd5krd:nd;t j d1|ttjd8ggdjDjjjjjd8d/ t |d2kr|j!rx^|D]VkrR|ttjjjfd?d>jDjjjjjd8d qRW|j d/krj"d@d/krt dAjt j d1j#d krr$qrj%dB}|j d kr4|&dCjj#d krp$n<|jd krpt'dDjdEd krpj#d krr$qryLtdFdB(||dG_)t*|dGj)dHdIdJ}|+t,Wd8QRXWnJt-k r}z*t t,|t j d1j#d kr$dKSd8}~XYnXj#d krr$qrW|j.d krdt t/t |d2krNdLd>|Dn|dGj0d/dMdNn.x,|jD]"t dO(fdPd>|DqlWdGS)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.) descriptionfilesrb+zFile(s) to be analysed)typenargshelpz-vz --verbose store_trueFverbosezjDisplay 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 --minimalminimalzBOnly output the charset detected to STDOUT. Disabling JSON output.z-rz --replacereplacezGReplace file when trying to normalize it instead of creating a new one.z-fz--forceforcezHReplace file without asking if you are sure, use this flag with caution.z-tz --thresholdstoreg? thresholdzUDefine a custom maximum amount of chaos allowed in decoded content. 0. <= chaos <= 1.)r&r r!r'r#z --versionversionz!Charset-Normalizer {} - Python {}z"Show version information and exit.)r&r/r#Tz.Use --replace in addition of --normalize only.)filez*Use --force in addition of --replace only.gg?z---threshold VALUE should be between 0. AND 1.)r.explainNz4Unable to identify originating encoding for "{}". {}z-Maybe try increasing maximum amount of chaos.rUnknowncsg|]}|jkr|qSr)encoding).0cp) best_guessrr szcli_detect..csg|]}|jkr|qSr)r4)r5r6)elrrr8sutfzJ"{}" file does not need to be normalized, as it already came from unicode..z0Are you sure to normalize "{}" by replacing it ?rz./{}rwzutf-8)r4cSsg|] }|jqSr)__dict__)r5r9rrrr8s) ensure_asciiindentz, cs,g|]$}|jtjkr|jr$|jndqS)Z undefined)pathrnamer4)r5r9)my_filerrr8s)1argparseArgumentParser add_argumentFileTypefloatformatrr parse_argsr+r)printrstderrr,r.rrr%bestrDappendrrr4Zencoding_aliasesZcould_be_from_charsetlanguageZ alphabetsbomZ percent_chaosZpercent_coherencelenr( startswithclosedclosesplitinsertrjoinZ unicode_pathopenrstrIOErrorr*rr?)rparserargsZx_matchesZo_fper)r7r9rEr cli_detect.sV                    $   rb__main__)r )N)rFrjsonros.pathrplatformrtypingrZcharset_normalizerrZcharset_normalizer.modelsrZcharset_normalizer.versionrr[boolrintrb__name__rrrrs       !u