
    $8gj0                        d dl mZ d dlZd dlZd dl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)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       Kc:\dev\xtrs\vdcb\.venv\Lib\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__2   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>C   s     4eQ$**_es   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__P   s    zz4==(t~~.4<<0HI99"&4$3#)T#Y$4.4Hf72s"QsgfHI
 t*%%&az33 5Hs   
BB#
B!.	B!)r.   rF   NN)r'   strr(   intr)   
str | Noner*   rU   )r?   rS   returnz	typing.IO)rV   rS   )rL   
__module____qualname____doc__r+   rC   rR    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;t;        t=        |j6                        |j>                  |j@                  |jB                  D cg c]  }||j>                  k7  r| c}|jD                  |jF                  |jH                  |jJ                  |jL                  d?d6      }|j9                  |       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                  |            |_2        tg        |jd                  dJ      5 }|ji                  |jk                                d?d?d?       |jT                  du s|j#                          ! |jp                  du rPdLdMl9m:} t%         |tO        |      d9kD  r|D 	cg c]  }	|	jv                   c}	n|dL   jv                  d6dNO             yL|j                   D ]Z  }t%        dPjc                  |D 	cg c]4  }	|	jx                  t=        |j6                        k(  r|	j>                  xs dQ6 c}	             \ yLc 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?}~ yKd?}~ww xY wc c}	w c c}	w )Rz
    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)rK   nargshelpz-vz	--verbose
store_trueFverbosezjDisplay complementary information about file if any. Stdout will contain logs about the detection process.)actionr   destra   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.)rd   r   rK   re   ra   z	--versionversionz;Charset-Normalizer {} - Python {} - Unicode {} - SpeedUp {}z.pyOFFONz"Show version information and exit.)rd   rn   ra   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.)rm   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..rF   z0Are you sure to normalize "{}" by replacing it ?r   wb   r   )dumps   )ensure_asciiindentrE   	undefined)=r=   ArgumentParseradd_argumentr   floatformatr   r	   r
   	md_module__file__r   endswith
parse_argsri   rg   r]   closer   r5   stderrrj   rm   r   rc   rk   bestnameappendr   r   r)   encoding_aliasescould_be_from_charsetlanguage	alphabetsbompercent_chaospercent_coherencelenrf   
startswithclosedr   r   r   splitinsertr   r   unicode_pathr;   writeoutputr<   rS   rh   jsonr{   __dict__path)argvparserrM   my_filex_matches
best_guesscp
cli_resulteldir_path	file_nameo_fprA   r{   s                   r   
cli_detectr   Z   so    $$%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)  ,%##++ )>>>Z000 >
 ##$$((,,J" IIj!7|aD$5$5!BZ'		. ' 5 " " 3 3 /1.F.F!".F')R[['8 %'.F!"
 !# " " " 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 	  ~~.	.28SXXb\.JJ+j55t<!2!2!45 = >>U"MMO B ||u.1"gkr*rr*r!u~~!	
&  zzG		 #%"$B77ggll&;; 2{2"$ " [.!"j =< #a&szz2~~.	 +sI   )^?^	6^(? ^^(7`9`^%	!^((	_>1A_99_>__main__)r   )r   rS   r   rS   rV   boolr!   )r   zlist[str] | NonerV   rT   )
__future__r   r=   r5   typingos.pathr   r   r   r   r   platformr	   unicodedatar
   charset_normalizer.mdmdr   charset_normalizerr   charset_normalizer.modelsr   charset_normalizer.versionr   r   r   r   rL   rZ   r   r   <module>r      sT    "  
  > > # ' ) & 8 2184 84vM` zL r   