U f&@sddlZddlZddlmZddlmZmZmZmZm Z ddl m Z ddl m Z mZddlmZddlmZddlmZddlmZdd lmZdeeed d d Zdee eedddZedkredS)N)dumps)abspathbasenamedirnamejoinrealpath)python_version)ListOptional)unidata_version)from_fp)CliDetectionResult) __version__yes)questiondefaultreturncCsdddddd}|dkrd}n(|dkr,d}n|dkr:d }n td |tj||t}|dk rx|d krx||S||kr||Stjd qFdS) 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)ryZyenonNz [y/n] rz [Y/n] rz [y/N] zinvalid default answer: '%s'z3Please respond with 'yes' or 'no' (or 'y' or 'n'). ) ValueErrorsysstdoutwriteinputlower)rrZvalidpromptchoicerR/opt/alt/python38/lib64/python3.8/site-packages/charset_normalizer/cli/__main__.py query_yes_nos   r!)argvrc stjdd}|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,tttt j d-rd.nd/d0d1| |}|jd2kr(|jd kr(td3tjd4d5S|jd2krR|jd krRtd6tjd4d5S|jd7ksj|jd8kr|td9tjd4d5Sg}|jD]ĉt|j|jd:}|d;krtd<j|jd8krd=nd>tjd4|ttjd;ggd?gd d8d7d;d2 n2|ttjjjfd@dAjDj j!j"j#j$d;d2 t%|d5kr|j&r|D]Vkrd|ttjjjfdBdAjDj j!j"j#j$d;d qd|jd2kr6j'dCd2krtdDjtjd4j(d kr)qt*t+j}t,t+j}|-dE}|jd kr^|.dFjj(d kr)n<|jd krt/dGjdHd krj(d kr)qzHt0|dE0||dI_1t2|dIj1dJdKdL}|3t4W5QRXWnRt5k r4} z2tt4| tjd4j(d kr)WYdMSd;} ~ XYnXj(d kr)q|j6d krtt7t%|d5krzdNdA|Dn|dIj8d2dOdPn*|jD]"tdQ0fdRdA|DqdIS)Sz 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.)actionrdestr)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,rr'r-r)z --versionversionz;Charset-Normalizer {} - Python {} - Unicode {} - SpeedUp {}z.pyZOFFONz"Show version information and exit.)r,r5r)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.)r4explainNz4Unable to identify originating encoding for "{}". {}z-Maybe try increasing maximum amount of chaos.rUnknowncsg|]}|jkr|qSrencoding.0cp) best_guessrr s zcli_detect..csg|]}|jkr|qSrr;r=)elrr rAs utfzJ"{}" file does not need to be normalized, as it already came from unicode..z0Are you sure to normalize "{}" by replacing it ?rrwzutf-8r;cSsg|] }|jqSr)__dict__r>rBrrr rAs) ensure_asciiindentz, cs&g|]}|jtjkr|jp dqS) undefined)pathrnamer<rI)my_filerr rAs)9argparseArgumentParser add_argumentFileTypefloatformatrrr md_module__file__rendswith parse_argsr1r/printrstderrr2r4r$r r+bestrOappendr rr<Zencoding_aliasesZcould_be_from_charsetlanguageZ alphabetsbomZ percent_chaosZpercent_coherencelenr. startswithclosedcloserrrsplitinsertr!rZ unicode_pathopenrstrIOErrorr0rrH) r"parserargsZx_matchesZdir_path file_nameZo_fper)r@rBrPr cli_detect0s                    $   rp__main__)r)N) rQrjsonros.pathrrrrrplatformrtypingr r unicodedatar Zcharset_normalizer.mdmdrWZcharset_normalizerr Zcharset_normalizer.modelsr Zcharset_normalizer.versionrrhboolr!intrp__name__rrrr s       !x