a oe8'@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}|durd}n(|dkr,d}n|dkr:d }n td |tj||t}|durx|d krx||S||vr||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)rrZvalidpromptchoicer@C:\Program Files\Certbot\pkgs\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| |}|jd2ur(|jd ur(td3tjd4d5S|jd2urR|jd urRtd6tjd4d5S|jd7ksj|jd8kr|td9tjd4d5Sg}|jD]؉t|j|jd:}|d;urtd<j|jd8krd=nd>tjd4|ttjd;ggd?gd d8d7d;d2 nF|ttjjjfd@dAjDj j!j"j#j$d;d2 t%|d5kr|j&r|D]Vkrd|ttjjjfdBdAjDj j!j"j#j$d;d qd|jd2urJj'dCd2urtdDjtjd4j(d ur)qt*t+j}t,t+j}|-dE}|jd ur^|.dFjj(d ur)n<|jd urt/dGjdHd urj(d ur)qz^t0|dE0||dI_1t2|dIj1dJdKdL}|3t4Wd;n1s0YWnPt5yH} z6tt4| tjd4j(d ur0)WYd;} ~ dMSd;} ~ 00j(d ur)q|j6d urtt7t%|d5krdNdA|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.pyZOFFZONz"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.)r4ZexplainNz4Unable to identify originating encoding for "{}". {}z-Maybe try increasing maximum amount of chaos.rZUnknowncsg|]}|jkr|qSrencoding.0Zcp) best_guessrr s zcli_detect..csg|]}|jkr|qSrr8r:)elrr r=s utfzJ"{}" file does not need to be normalized, as it already came from unicode..z0Are you sure to normalize "{}" by replacing it ?rrwzutf-8r8cSsg|] }|jqSr)__dict__r;r>rrr r=)Z ensure_asciiindentz, cs&g|]}|jtjkr|jp dqS)Z undefined)pathrnamer9rE)my_filerr r=s)9argparseArgumentParser add_argumentFileTypefloatformatrrr md_module__file__rendswith parse_argsr1r/printrstderrr2r4r$r r+ZbestrJappendr rr9Zencoding_aliasesZcould_be_from_charsetlanguageZ alphabetsZbomZ percent_chaosZpercent_coherencelenr. startswithclosedcloserrrsplitinsertr!rZ unicode_pathopenrstrIOErrorr0rrD) r"parserargsZx_matchesZdir_path file_nameZo_fper)r<r>rKr cli_detect0s                2    $   ri__main__)r)N) rLrZjsonrZos.pathrrrrrplatformrtypingr r unicodedatar Zcharset_normalizer.mdZmdrRZcharset_normalizerr Zcharset_normalizer.modelsr Zcharset_normalizer.versionrraboolr!intri__name__rrrr s       !x