
    +hf1                        d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ ddd
Z G d d      ZdddZedk(  r e        yy)    )annotationsN)dumps)abspathbasenamedirnamejoinrealpath)python_version)unidata_version)from_fp)CliDetectionResult)__version__c                8   dddddd}|d}n|dk(  rd}n|dk(  rd}nt        d	|z        	 t        j                  j                  | |z          t	               j                         }|
|d
k(  r||   S ||v r||   S t        j                  j                  d       o)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)yesyyenonz [y/n] r   z [Y/n] r   z [y/N] zinvalid default answer: '%s' z3Please respond with 'yes' or 'no' (or 'y' or 'n').
)
ValueErrorsysstdoutwriteinputlower)questiondefaultvalidpromptchoices        R/var/www/html/venv/lib/python3.12/site-packages/charset_normalizer/cli/__main__.pyquery_yes_nor"      s     t4u5IE	E		D7'ABB


F*+6R<>!u_= JJST     c                  @    e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 ddZddZd	dZy)
FileTypea  Factory for creating file object types

    Instances of FileType are typically passed as type= arguments to the
    ArgumentParser add_argument() method.

    Keyword Arguments:
        - mode -- A string indicating how the file is to be opened. Accepts the
            same values as the builtin open() function.
        - bufsize -- The file's desired buffer size. Accepts the same values as
            the builtin open() function.
        - encoding -- The file's encoding. Accepts the same values as the
            builtin open() function.
        - errors -- A string indicating how encoding and decoding errors are to
            be handled. Accepts the same value as the builtin open() function.

    Backported from CPython 3.12
    Nc                <    || _         || _        || _        || _        y N)_mode_bufsize	_encoding_errors)selfmodebufsizeencodingerrorss        r!   __init__zFileType.__init__E   s      
!r#   c                2    |dk(  rd j                   v r8d j                   v rt        j                  j                  S t        j                  S t	         fddD              r8d j                   v rt        j
                  j                  S t        j
                  S d j                    }t        |      	 t        | j                    j                   j                   j                        S # t        $ r"}d| d| }t        j                  |      d }~ww xY w)	N-rbc              3  :   K   | ]  }|j                   v   y wr'   )r(   ).0cr,   s     r!   	<genexpr>z$FileType.__call__.<locals>.<genexpr>V   s     4Q$**_4s   waxzargument "-" with mode zcan't open 'z': )r(   r   stdinbufferanyr   r   openr)   r*   r+   OSErrorargparseArgumentTypeError)r,   stringmsgemessages   `    r!   __call__zFileType.__call__Q   s    S=djj +.$**+<syy''K#))K4e44,/4::,=szz((M3::M/

|< o%	6

DMM4>>4<<XX 	6$VHCs3G,,W55	6s   46C+ +	D4DDc           
     N   | j                   | j                  f}d| j                  fd| j                  fg}dj	                  |D cg c]  }|dk7  s	t        |       c}|D cg c]  \  }}|	| d| c}}z         }t        |       j                   d| dS c c}w c c}}w )Nr/   r0   , =())r(   r)   r*   r+   r   reprtype__name__)r,   argskwargsargkwargs_strs         r!   __repr__zFileType.__repr__c   s    zz4==(t~~.4<<0HI99"&43#)T#Y4.4H72s"QsgHI
 t*%%&az33 5Hs   
BB#
B!.	B!)r4   rI   NN)r-   strr.   intr/   
str | Noner0   rX   )rB   rV   returnz	typing.IO)rY   rV   )rO   
__module____qualname____doc__r1   rF   rU    r#   r!   r%   r%   2   sJ    ( #!

 
 	

 
6$4r#   r%   c                   t        j                  d      }|j                  dt        d      dd       |j                  dd	d
ddd       |j                  ddd
ddd       |j                  ddd
ddd       |j                  ddd
ddd       |j                  ddd
ddd       |j                  dd d
dd!d"       |j                  d#d$d
dd%d&       |j                  d'd(d)d*t        d+d,-       |j                  d.d/d0j                  t        t               t        t        j                  j                         j                  d1      rd2nd3      d45       |j                  |       }|j                  d6u rW|j                  du rI|j                   r!|j                   D ]  }|j#                           t%        d7t&        j(                  8       y9|j*                  d6u rW|j                  du rI|j                   r!|j                   D ]  }|j#                           t%        d:t&        j(                  8       y9|j,                  d;k  s|j,                  d<kD  rI|j                   r!|j                   D ]  }|j#                           t%        d=t&        j(                  8       y9g }|j                   D ]"  }t/        ||j,                  |j0                  |j2                  du >      }|j5                         }|t%        d@j                  |j6                  |j,                  d<k  rdAndB      t&        j(                  8       |j9                  t;        t=        |j6                        d?g g dCg dd<d;d?d6             n?|j9                  t;        t=        |j6                        |j>                  |j@                  |jB                  D cg c]  }||j>                  k7  r| c}|jD                  |jF                  |jH                  |jJ                  |jL                  d?d6             tO        |      d9kD  r|jP                  r|D ]  }||k7  s	|j9                  t;        t=        |j6                        |j>                  |j@                  |jB                  D cg c]  }||j>                  k7  r| c}|jD                  |jF                  |jH                  |jJ                  |jL                  d?d              |j                  d6u r|j>                  jS                  dD      d6u rTt%        dEj                  |j6                        t&        j(                  8       |jT                  du r|j#                          tW        tY        |j6                              }	t[        tY        |j6                              }
|
j]                  dF      }|j                  du r;|j_                  dG|j>                         |jT                  du rf|j#                          nU|j*                  du rGta        dHj                  |j6                        dI      du r |jT                  du r|j#                          	 tc        |	dFjc                  |            |dJ   _2        tg        |dJ   jd                  dK      5 }|ji                  |jk                                d?d?d?       |jT                  du s|j#                          % |jp                  du rMt%        ts        tO        |      d9kD  r|D cg c]  }|jt                   c}n|dJ   jt                  d6dMN             yJ|j                   D ]Z  }t%        dOjc                  |D cg c]4  }|jv                  t=        |j6                        k(  r|j>                  xs dP6 c}             \ yJc c}w c c}w # 1 sw Y   xY w# tl        $ rM}t%        to        |      t&        j(                  8       |jT                  du r|j#                          Y d?}~ yLd?}~ww xY wc c}w c c}w )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.)descriptionfilesrb+zFile(s) to be analysed)rN   nargshelpz-vz	--verbose
store_trueFverbosezjDisplay complementary information about file if any. Stdout will contain logs about the detection process.)actionr   destrd   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-iz--no-preemptiveno_preemptivez>Disable looking at a charset declaration to hint the detector.z-tz--thresholdstoreg?	thresholdzUDefine a custom maximum amount of noise allowed in decoded content. 0. <= noise <= 1.)rg   r   rN   rh   rd   z	--versionversionz;Charset-Normalizer {} - Python {} - Unicode {} - SpeedUp {}z.pyOFFONz"Show version information and exit.)rg   rq   rd   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.)rp   explainpreemptive_behaviourNz4Unable to identify originating encoding for "{}". {}z-Maybe try increasing maximum amount of chaos.r   UnknownutfzJ"{}" file does not need to be normalized, as it already came from unicode..rI   z0Are you sure to normalize "{}" by replacing it ?r   r   wb      )ensure_asciiindentrH   	undefined)<r@   ArgumentParseradd_argumentr%   floatformatr   r
   r   	md_module__file__r   endswith
parse_argsrl   rj   r`   closeprintr   stderrrm   rp   r   rf   rn   bestnameappendr   r   r/   encoding_aliasescould_be_from_charsetlanguage	alphabetsbompercent_chaospercent_coherencelenri   
startswithclosedr   r	   r   splitinsertr"   r   unicode_pathr>   r   outputr?   rV   rk   r   __dict__path)argvparserrP   my_filex_matches
best_guesscpeldir_path	file_nameo_fprD   s                 r!   
cli_detectr   m   s    $$%F htnC6N   @   X   [   Q   V   W   M   d   MTT''--/88?ET	
 2  
 T"D||t% 7::::   >SZZPzzTdlle3::::   :L~~t~~3::::   =CJJO	B:: @nnLL!%!3!3u!<	
 \\^
FMMLL  >>C/ H ZZ
 II"GLL)  II"GLL)''// #-"B"B!4!44 
 ''((NN,,00( 7|aD$5$5! BZ'		. ' 5 " " 3 3 /1.F.F!"(*')R[['8 %'!"
 !# " " " 0 0 " 4 4 $ %, ~~%&&11%8D@dkk#LL !ZZ	 ~~."8GLL#9:$Xgll%;<	 ) 4<<5(IIb*"5"56~~.JJ%'$JQQ#LL 	  ~~.	)-h)EBqE&be00$7 62!2!2!456 >>U"MMOA@D ||u.1"gkr**r!u~~!	
&  zz 		G		 #%77ggll&;; 2{2		 W.!"j6 6 #a&szz2~~.	 +sI   4^=^<^) ^#^)8`9`^&	"^))	_?2A_::_?__main__)r   )r   rV   r   rV   rY   boolr'   )r   zlist[str] | NonerY   rW   )
__future__r   r@   r   typingjsonr   os.pathr   r   r   r   r	   platformr
   unicodedatar   charset_normalizer.mdmdr   charset_normalizerr   charset_normalizer.modelsr   charset_normalizer.versionr   r"   r%   r   rO   r]   r#   r!   <module>r      sY    "  
   > > # ' ) & 8 2UB84 84vL^ zL r#   