<commit_before>import re

from mediawords.util.perl import decode_string_from_bytes_if_needed


class SchemaVersionFromLinesException(Exception):
    pass


def schema_version_from_lines(sql: str) -> int:
    """Utility function to determine a database schema version from a bunch of SQL commands."""
    sql = decode_string_from_bytes_if_needed(sql)
    matches = re.search(r'[+\-]*\s*MEDIACLOUD_DATABASE_SCHEMA_VERSION CONSTANT INT := (\d+?);', sql)
    if matches is None:
        raise SchemaVersionFromLinesException("Unable to parse the database schema version number")
    schema_version = int(matches.group(1))
    if schema_version == 0:
        raise SchemaVersionFromLinesException("Invalid schema version")
    return schema_version<commit_msg>Prepend “Mc” to exception name<commit_after>import re

from mediawords.util.perl import decode_string_from_bytes_if_needed


class McSchemaVersionFromLinesException(Exception):
    pass


def schema_version_from_lines(sql: str) -> int:
    """Utility function to determine a database schema version from a bunch of SQL commands."""
    sql = decode_string_from_bytes_if_needed(sql)
    matches = re.search(r'[+\-]*\s*MEDIACLOUD_DATABASE_SCHEMA_VERSION CONSTANT INT := (\d+?);', sql)
    if matches is None:
        raise McSchemaVersionFromLinesException("Unable to parse the database schema version number")
    schema_version = int(matches.group(1))
    if schema_version == 0:
        raise McSchemaVersionFromLinesException("Invalid schema version")
    return schema_version
{'fraction_non_alphanumeric': 0.08599348534201955, 'fraction_numerical': 0.0026058631921824105, 'mean_word_length': 4.93050193050193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2223296', 'n_tokens_mistral': 443, 'n_tokens_neox': 436, 'n_words': 121}