
     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             dS dS )    )annotationsN)dumps)abspathbasenamedirnamejoinrealpath)python_version)unidata_version)from_fp)CliDetectionResult)__version__yesquestionstrdefaultreturnboolc                    |dk    rdnd}	 t          | |z                                                                             }|s|dk    S |dv rdS |dv rdS t          d           Z)	zBAsk a yes/no question via input() and return the answer as a bool.r   z [Y/n] z [y/N] T)yr   )nnoFzPlease respond with 'y' or 'n'.)inputstriplowerprint)r   r   promptchoices       i/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/charset_normalizer/cli/__main__.pyquery_yes_nor       s    !U**YY	F1x&())//117799 	$e##\!!4[  5/0001    c                  4    e Zd ZdZ	 	 	 	 dddZddZddZdS )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
    rNmoder   bufsizeintencoding
str | Noneerrorsc                >    || _         || _        || _        || _        d S N)_mode_bufsize	_encoding_errors)selfr&   r'   r)   r+   s        r   __init__zFileType.__init__3   s$     
!r!   stringr   	typing.IOc                    |dk    rd j         v r&d j         v rt          j        j        nt          j        S t	           fddD                       r&d j         v rt          j        j        n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 V  d S r-   )r.   ).0cr2   s     r   	<genexpr>z$FileType.__call__.<locals>.<genexpr>D   s)      44Q$*_444444r!   waxzargument "-" with mode zcan't open 'z': )r.   sysstdinbufferanystdout
ValueErroropenr/   r0   r1   OSErrorargparseArgumentTypeError)r2   r4   msgemessages   `    r   __call__zFileType.__call__?   s    S==dj  +.$*+<+<sy''#)K4444e44444 &,/4:,=,=sz((3:M<
<< oo%	6
DM4>4<XXX 	6 	6 	63V3333G,W555	6s   &B9 9
C$CC$c                    | j         | j        f}d| j        fd| j        fg}d                    d |D             d |D             z             }t          |           j         d| dS )Nr)   r+   , c                8    g | ]}|d k    t          |          S )r%   )repr)r:   args     r   
<listcomp>z%FileType.__repr__.<locals>.<listcomp>U   s#    4443#))T#YY)))r!   c                &    g | ]\  }}|| d|S )N= )r:   kwrP   s      r   rQ   z%FileType.__repr__.<locals>.<listcomp>V   s'    HHH72s"sr!   ())r.   r/   r0   r1   r   type__name__)r2   argskwargsargs_strs       r   __repr__zFileType.__repr__Q   s    z4=(t~.4<0HI9944$444HHfHHHI
 
 t**%333333r!   )r$   r%   NN)r&   r   r'   r(   r)   r*   r+   r*   )r4   r   r   r5   )r   r   )rY   
__module____qualname____doc__r3   rK   r]   rT   r!   r   r#   r#       sm         ( #!
 
 
 
 
6 6 6 6$4 4 4 4 4 4r!   r#   argvlist[str] | Noner(   c                  
 t          j        d          }|                    dt          d          dd           |                    dd	d
ddd           |                    ddd
ddd           |                    ddd
ddd           |                    ddd
ddd           |                    ddd
ddd           |                    dd d
dd!d"           |                    d#d$d
dd%d&           |                    d'd(d)d*t          d+d,-           |                    d.d/d0                    t          t                      t          t          j
                                                            d1          rd2nd3          d45           |                    |           }|j        d6u rK|j        du rB|j        r|j        D ]                                 t%          d7t&          j        8           d9S |j        d6u rK|j        du rB|j        r|j        D ]                                 t%          d:t&          j        8           d9S |j        d;k     s|j        d<k    rB|j        r|j        D ]                                 t%          d=t&          j        8           d9S g }|j        D ]/t/          |j        |j        |j        du >          }|                                

t%          d@                    j        |j        d<k     rdAndB          t&          j        8           |                    t;          t=          j                  d?g g dCg dd<d;d?d6                     nT|                    t;          t=          j                  
j        
j         
fdD
j!        D             
j"        
j#        
j$        
j%        
j&        d?d6                     tO          |          d9k    r|j(        r}|D ]z
k    rr|                    t;          t=          j                  j        j         fdEj!        D             j"        j#        j$        j%        j&        d?d                     {|j        d6u rA
j        )                    dF          d6u rRt%          dG                    j                  t&          j        8           j*        du r                                 ?tW          tY          j                            }t[          tY          j                            }|.                    dH          }|j        du r9|/                    dI
j                   j*        du r                                 nR|j        du rIta          dJ                    j                  dK          du rj*        du r                                 *	 tc          |dH1                    |                    |dL         _2        tg          |dL         j2        dM          5 }|4                    
5                                           d?d?d?           n# 1 swxY w Y   n^# tl          $ rQ}	t%          to          |	          t&          j        8           j*        du r                                 Y d?}	~	 dNS d?}	~	ww xY wj*        du r                                 1|j8        du rJt%          ts          tO          |          d9k    rdO |D             n|dL         j:        d6dPQ                     n8|j        D ]0t%          dR1                    fdS|D                                  1dLS )Tz
    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)rX   nargshelpz-vz	--verbose
store_trueFverbosezjDisplay complementary information about file if any. Stdout will contain logs about the detection process.)actionr   destri   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.)rl   r   rX   rm   ri   z	--versionversionz;Charset-Normalizer {} - Python {} - Unicode {} - SpeedUp {}z.pyOFFONz"Show version information and exit.)rl   rv   ri   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.)ru   explainpreemptive_behaviourNz4Unable to identify originating encoding for "{}". {}z-Maybe try increasing maximum amount of chaos. Unknownc                *    g | ]}|j         k    |S rT   r)   )r:   cp
best_guesss     r   rQ   zcli_detect.<locals>.<listcomp>   s1       !444 444r!   c                *    g | ]}|j         k    |S rT   r   )r:   r   els     r   rQ   zcli_detect.<locals>.<listcomp>  s0     !" !" !"(*')R['8'8 %''8'8'8r!   utfzJ"{}" file does not need to be normalized, as it already came from unicode..r%   z0Are you sure to normalize "{}" by replacing it ?r   r   wb   c                    g | ]	}|j         
S rT   )__dict__)r:   r   s     r   rQ   zcli_detect.<locals>.<listcomp>V  s    ******r!      )ensure_asciiindentrM   c                \    g | ](}|j         t          j                  k    |j        pd )S )	undefined)pathr   namer)   )r:   r   my_files     r   rQ   zcli_detect.<locals>.<listcomp>_  sA       7ggl&;&;;; 2{;;;r!   );rF   ArgumentParseradd_argumentr#   floatformatr   r
   r   	md_module__file__r   endswith
parse_argsrq   ro   re   closer   r>   stderrrr   ru   r   rk   rs   bestr   appendr   r   r)   encoding_aliasescould_be_from_charsetlanguage	alphabetsbompercent_chaospercent_coherencelenrn   
startswithclosedr   r	   r   splitinsertr    r   unicode_pathrD   writeoutputrE   r   rp   r   r   )ra   parserrZ   x_matchesdir_path	file_nameo_fprI   r   r   r   s             @@@r   
cli_detectr   [   s+	    $%  F htnnC6N     @     X     [     Q     V     W     M     d     MTT'--//88??IEET	
 
 2  
 
 
 T""D|t% 7 7: 	 :    >SZPPPPqzTdle33: 	 :    :LLLLq~t~33: 	 :    =CJOOOOq	B: @ @nL!%!3u!<	
 
 
 \\^^
FMML  >C// HG  Z
 
 
 
 II"GL))      II"GL))'/   ","B  
 '(N,0   ( 7||aD$5!  BZ''		. ' 5 5 " " 3!" !" !" !".0.F!" !" !"
 !# " " " 0 " 4 $ %   ( ~%%&11%88D@@dkk#L  !Z	    ~.."8GL#9#9::$Xgl%;%;<<	 ) 4 4<5((IIb*"5666~..J%''$JQQ#L  	    ~..	)-h)E)EBqE&be0$77 62!2!2!4!45556 6 6 6 6 6 6 6 6 6 6 6 6 6 6   #a&&sz2222~..111111	 >U""MMOOO|u.1"ggkk**r****r!u~!  	
 	
 	
 	
 z 		 		G		   "$       1s>   A	Y''(YY'Y	Y'"Y	#Y''
[1AZ==[__main__)r   )r   r   r   r   r   r   r-   )ra   rb   r   r(   )
__future__r   rF   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   rY   rT   r!   r   <module>r      s_   " " " " " "  



        > > > > > > > > > > > > > > # # # # # # ' ' ' ' ' ' ) ) ) ) ) ) & & & & & & 8 8 8 8 8 8 2 2 2 2 2 21 1 1 1 184 84 84 84 84 84 84 84vL L L L L^ zJLLLLL r!   