def is_bin_str(data):
 if ('\x00' in data):
  return True
 if (not data):
  return False
 text_characters = ''.join(([chr(x) for x in range(32, 127)] + list('\n\r DCTB \x08')))
 if six.PY3:
  trans = ''.maketrans('', '', text_characters)
  nontext = data.translate(trans)
 else:
  trans = string.maketrans('', '')
  nontext = data.translate(trans, text_characters)
 if ((len(nontext) / len(data)) > 0.3):
  return True
 return False

def is_bin_str ( data ) : if ( '\x00' in data ) : return True if ( not data ) : return False text_characters = '' . join ( ( [ chr ( x ) for x in range ( 32 , 127 ) ] + list ( '\n\r DCTB \x08' ) ) ) if six . PY3 : trans = '' . maketrans ( '' , '' , text_characters ) nontext = data . translate ( trans ) else : trans = string . maketrans ( '' , '' ) nontext = data . translate ( trans , text_characters ) if ( ( len ( nontext ) / len ( data ) ) > 0.3 ) : return True return False
detects if the passed string of data is bin or text .