def is_binary_file(filename, nbytes=1024):
    """
    An approximate way to tell whether a file is binary.
    :param str filename: The name of the file to be tested.
    :param int nbytes: number of bytes to read for test
    :return:
    """
    with open(filename, 'rb') as ins:
        for c in ins.read(nbytes):
            if isinstance(c, six.integer_types):
                oc = c
            else:
                oc = ord(c)
            if 127 < oc < 256 or (oc < 32 and oc not in (9, 10, 13)):
                return True
        else:
            return False

    An approximate way to tell whether a file is binary.
    :param str filename: The name of the file to be tested.
    :param int nbytes: number of bytes to read for test
    :return:
    
system/shcommon.py