1# -*- coding: utf-8 -*- 2 3""" 4binaryornot.check 5----------------- 6 7Main code for checking if a file is binary or text. 8""" 9 10import logging 11 12from .helpers import get_starting_chunk, is_binary_string 13 14 15logger = logging.getLogger(__name__) 16 17 18def is_binary(filename): 19 """ 20 :param filename: File to check. 21 :returns: True if it's a binary file, otherwise False. 22 """ 23 logger.debug('is_binary: %(filename)r', locals()) 24 25 # Check if the file extension is in a list of known binary types 26 binary_extensions = ['.pyc', ] 27 for ext in binary_extensions: 28 if filename.endswith(ext): 29 return True 30 31 # Check if the starting chunk is a binary string 32 chunk = get_starting_chunk(filename) 33 return is_binary_string(chunk) 34