
    Je              
       (   d Z ddlZddlZ ej                  e      Zd ZddZdZe	e
u rEedj                   ee edd                  z   Zdj                   ee edd	                  Zd
 Zye e	 edd            z   Z e	 edd	            Zd
 Zy)z
binaryornot.helpers
-------------------

Helper utilities used by BinaryOrNot.

Adapted from binaryornot/helpers.py of
`BinaryOrNot <https://github.com/audreyr/binaryornot>`_.
    Nc                 F    t        dj                  d | D                     y)z&
    Print a string as hex bytes.
    :c              3   P   K   | ]  }d j                  t        |               yw)z{0:x}N)formatord).0cs     K/usr/lib/python3/dist-packages/spyder/utils/external/binaryornot/helpers.py	<genexpr>zprint_as_hex.<locals>.<genexpr>   s     5a7>>#a&)5s   $&N)printjoin)ss    r
   print_as_hexr      s     
#((515
56    c                 l    t        | d      5 }|j                  |      }|cddd       S # 1 sw Y   yxY w)z
    :param filename: File to open and get the first little chunk of.
    :param length: Number of bytes to read, default 1024.
    :returns: Starting chunk of bytes.
    rbN)openread)filenamelengthfchunks       r
   get_starting_chunkr   "   s5     
h	 v  s   *3s   
	r             c                 d   | sy| j                  dt              }t        t        |            t        t        |             z  }t        j                  dt                      | j                  dt              }t        t        |            t        t        |             z  }t        j                  dt                      |dkD  xr |dk  xs |dkD  xr |dkD  }t        j                  dt                      t        j                  |       }t        j                  d	t                      d}|d
   dkD  r?|d   dk7  r7	 	 | j                  |d          d}t        j                  dt                      t        j                  dt                      |r|ryy|ryd| v sd| v r$t        j                  dt        d| v       z          yy# t        $ r t        | |d          Y w xY w# t        $ r t        j                  d|       Y t        $ r! t        j                  dt                      Y w xY w)a  
    Uses a simplified version of the Perl detection algorithm,
    based roughly on Eli Bendersky's translation to Python:
    https://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/

    This is biased slightly more in favour of deeming files as text
    files than the Perl algorithm, since all ASCII compatible character
    sets are accepted as text, not just utf-8.

    :param bytes: A chunk of bytes to check.
    :returns: True if appears to be a binary, otherwise False.
    FNz"nontext_ratio1: %(nontext_ratio1)rz"nontext_ratio2: %(nontext_ratio2)rg333333?g?g?z&is_likely_binary: %(is_likely_binary)rz(detected_encoding: %(detected_encoding)r
confidenceg?encodingascii)r   Tz7success: decodable_as_unicode: %(decodable_as_unicode)rz0failure: could not look up encoding %(encoding)sz7failure: decodable_as_unicode: %(decodable_as_unicode)r       z
has nulls:)	translate_printable_asciifloatlenloggerdebuglocals_printable_high_asciichardetdetectdecode	TypeErrorunicodeLookupErrorUnicodeDecodeErrorrepr)bytes_to_check	low_charsnontext_ratio1
high_charsnontext_ratio2is_likely_binarydetected_encodingdecodable_as_unicodes           r
   is_binary_stringr;   9   s     ((/?@I3y>*U3~3F-GGN
LL5vx@  ))$0EFJ3z?+eC4G.HHN
LL5vx@ 
#		7.4"7 	8	#		6.3"6  LL968D  ~6
LL;VXF !,'#-j)W4	?P%%/@/L%M $( LL 45;X? LL ,-3X7.(G~,E\DN1J,KKL9  P1B:1NOP  	,LLK*,! 	?LL 45;X?	?s6   =G  G% G"G% !G""G% %H/&H/.H/)i   )__doc__r+   logging	getLogger__name__r'   r   r   _control_charsbytesstrr   mapchrranger$   r*   r;    r   r
   <module>rG      s      
		8	$7	 C<%S%C.1I(JJHHSeCo%>?Q	 &eBn(==!%S/2Qr   