def get_encoding_of_file(p):
    """
    Return the encoding of a file.
    :param p: path to file
    :type p: str
    :return: the encoding of the file or None
    :rtype: str or None
    """
    with open(p, "r") as fin:
        lines = fin.readlines()
        i = 0
        for line in lines:
            i += 1
            if i > 2:
                # encoding must be specified in the first two lines
                return None
            if is_encoding_line(line):
                return get_encoding_from_line(line)

    Return the encoding of a file.
    :param p: path to file
    :type p: str
    :return: the encoding of the file or None
    :rtype: str or None
    
tools/encoding_utils.py