
    o[i.                        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                    |dk(  rdnd}	 t        | |z         j                         j                         }|s|dk(  S |dv ry|dv ryt        d       G)	zBAsk a yes/no question via input() and return the answer as a bool.yesz [Y/n] z [y/N] T)yr   )nnoFzPlease respond with 'y' or 'n'.)inputstriplowerprint)questiondefaultpromptchoices       X/mnt/data/GridWatch/venv/lib/python3.12/site-packages/charset_normalizer/cli/__main__.pyquery_yes_nor      sf    !U*Y	F
x&()//1779e##\![ /0     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__3   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>D   s     4Q$**_4s   waxzargument "-" with mode zcan't open 'z': )r#   sysstdinbufferanystdout
ValueErroropenr$   r%   r&   OSErrorargparseArgumentTypeError)r'   stringmsgemessages   `    r   __call__zFileType.__call__?   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*   r+   , =())r#   r$   r%   r&   r   reprtype__name__)r'   argskwargsargkwargs_strs         r   __repr__zFileType.__repr__Q   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!)r/   rG   NN)r(   strr)   intr*   
str | Noner+   rV   )r@   rT   returnz	typing.IO)rW   rT   )rM   
__module____qualname____doc__r,   rD   rS    r   r   r    r        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)rL   nargshelpz-vz	--verbose
store_trueFverbosezjDisplay complementary information about file if any. Stdout will contain logs about the detection process.)actionr   destrb   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.)re   r   rL   rf   rb   z	--versionversionz;Charset-Normalizer {} - Python {} - Unicode {} - SpeedUp {}z.pyOFFONz"Show version information and exit.)re   ro   rb   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.)rn   explainpreemptive_behaviourNz4Unable to identify originating encoding for "{}". {}z-Maybe try increasing maximum amount of chaos. UnknownutfzJ"{}" file does not need to be normalized, as it already came from unicode..rG   z0Are you sure to normalize "{}" by replacing it ?r   r   wb      )ensure_asciiindentrF   	undefined)<r>   ArgumentParseradd_argumentr    floatformatr   r
   r   	md_module__file__r   endswith
parse_argsrj   rh   r^   closer   r6   stderrrk   rn   r   rd   rl   bestnameappendr   r   r*   encoding_aliasescould_be_from_charsetlanguage	alphabetsbompercent_chaospercent_coherencelenrg   
startswithclosedr   r	   r   splitinsertr   r   unicode_pathr<   writeoutputr=   rT   ri   r   __dict__path)argvparserrN   my_filex_matches
best_guesscpeldir_path	file_nameo_fprB   s                 r   
cli_detectr   [   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   rT   r   rT   rW   boolr"   )r   zlist[str] | NonerW   rU   )
__future__r   r>   r6   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   rM   r[   r   r   <module>r      sW    "  
   > > # ' ) & 8 2184 84vL^ zL r   