def read_content_file(dirpath):
    # Read page content
    c_ht = os.path.join(dirpath, 'content.ht')
    c_rst = os.path.join(dirpath, 'content.rst')

    if os.path.exists(c_ht):
        raw_input = open(c_ht, 'rb').read()
        detection = chardet.detect(raw_input)

        input = open(c_ht, 'r', encoding=detection['encoding'], errors='ignore')
        msg = email.message_from_file(input)

        filename = c_ht

    elif os.path.exists(c_rst):
        rst_text = open(c_rst, 'r').read()
        rst_msg = """Content-type: text/x-rst

%s""" % rst_text.lstrip()
        msg = email.message_from_string(rst_msg)
        filename = c_rst

    else:
        return None, None

    return filename, msg
(str): (str, email.Message)
dataset/ETHPy150Open python/pythondotorg/pages/parser.py/read_content_file