
                             d dl m Z  d dlmZ d dlmZ d dlmZ d dlZd dlm	Z
 d dlm	Z d dlmZ ded	ed
efdZdee   fdZedk(  r e eedd              yy)    )glob)isdir)argv)ListN)detect)	iana_namecontentcp_acp_bc                     	 | j                  |      }| j                  |      }t        |      }t        d t	        ||      D              }d||z  z
  S # t        $ r Y yw xY w)Ng        c              3   ,   K   | ]  \  }}||k7    y w)N ).0chr_achr_bs      8platform/gsutil/third_party/charset_normalizer/bin/bc.py	<genexpr>z#calc_equivalence.<locals>.<genexpr>   s      +<<5%+<s   g      ?)decodeUnicodeDecodeErrorlensumzip)r	   r
   r   str_astr_bcharacter_countdiff_character_counts          r   calc_equivalencer      st    t$t$ %jO +.ue+<  %788  s   "A 	AA	argumentsc                     t        j                  d      }|j                  ddddt        dd	       |j	                  |       }t        d
      st        d       t        d       d}d}t        t        d            D ]A  }|dz  }t        |d      5 }|j                         }d d d        t              }|d   }	t        |      }
|
d   }|	|gj                  d       dk(  rt        dj                  |||	             ||	k(  r |dz  }t        dj                  |             |	|t!        |	d      t!        |d      k(  r |dz  }t        dj                  |             t#        ||	|      }|dk\  r1|dz  }t        dj                  |||	t%        |dz  d                   &t        dj                  |||	             D t%        ||z  d      dz  }t        dj                  |||             ||j&                  k\  rdS dS # 1 sw Y   bxY w)Nz5BC script checker for Charset-Normalizer with Chardet)descriptionz-cz
--coveragestoreU   coveragez1Define the minimum acceptable coverage to succeed)actiondefaulttypedesthelpz./char-datasetzaThis script require https://github.com/Ousret/char-dataset to be cloned on package root directory   r   z./char-dataset/**/*.*rbencodingu0   ⚡⚡ '{}' (BC-Break) New('{}') vs Legacy('{}')u   ✅✅ '{}' (BC)Fg\(\?u-   ️✅ ️'{}' (got '{}' but eq {} WITH {} %)g      Y@      z#Total EST BC = {} % ({} / {} files))argparseArgumentParseradd_argumentint
parse_argsr   printexitsortedr   openreadchardet_detect
tbt_detectcountformatr   r   roundr#   )r   parserargssuccess_counttotal_counttbt_pathfpr	   chardet_resultchardet_encodingcharset_normalizer_resultcharset_normalizer_encodingcalc_eqsuccess_ratios                 r   cli_bcrI      s   $$KF l7BSWaP  R Y'D!"qrQMK4 789q(D!RggiG " (0)*5$.w$7!&?
&K#9:@@F!KDKKHVq  tD  E  F&*::QM$++H56$)D)LR[\lnsRt  yB  C^  `e  yf  SfQM$++H56"7,<>YZd?QMAHHSn  qA  CH  IP  SW  IW  YZ  C[  \  ]@GGRmo  A  	BC :F -+5q9D@M	
/
6
6}mU`
ab.15A5I "!s   HH	__main__r)   )r   os.pathr   sysr   typingr   r.   charset_normalizerr   r9   chardetr8   charset_normalizer.utilsr   bytesstrr   rI   __name__r4   r       r   <module>rU      sp         3 , .9e 93 9c 986d3i 86v zH	
 rT   