<commit_before>import re, chardet, htmlentitydefs
import lxml.html

def encoding_if_html(text):
    REGX_CHARSET = r"charset=(?P<charset>[a-zA-Z0-9-]+)"
    root = lxml.html.fromstring(text.lower())
    for meta in root.xpath("//meta[@charset]"):
        encoding = meta.get("charset")
        if encoding:
            return encoding
    for meta in root.xpath("//meta[@content]"):
        content = meta.get("content")
        if content:
            encoding = re.compile(REGX_CHARSET).findall(content)
            if encoding:
                return encoding[0].strip()
    raise<commit_msg>syntax error around raise if python > 2.6<commit_after>import re, chardet, htmlentitydefs
import lxml.html

class UnknownEncodingException(Exception):
    def __init__(self):
        Exception.__init__(self, 'Unknown encoding')

def encoding_if_html(text):
    REGX_CHARSET = r"charset=(?P<charset>[a-zA-Z0-9-]+)"
    root = lxml.html.fromstring(text.lower())
    for meta in root.xpath("//meta[@charset]"):
        encoding = meta.get("charset")
        if encoding:
            return encoding
    for meta in root.xpath("//meta[@content]"):
        content = meta.get("content")
        if content:
            encoding = re.compile(REGX_CHARSET).findall(content)
            if encoding:
                return encoding[0].strip()
    raise UnknownEncodingException()
{'fraction_non_alphanumeric': 0.13177159590043924, 'fraction_numerical': 0.005856515373352855, 'mean_word_length': 2.7867036011080333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '613073', 'n_tokens_mistral': 425, 'n_tokens_neox': 406, 'n_words': 87}