<commit_before>import re, unicodedata, sys

if sys.maxunicode == 65535:
    raise RuntimeError, "need UCS-4 Python"

def gen_category(cats):
    for i in range(0, 0x110000):
        if unicodedata.category(unichr(i)) in cats:
            yield(i)

def gen_bidirectional(cats):
    for i in range(0, 0x110000):
        if unicodedata.bidirectional(unichr(i)) in cats:
            yield(i)

def compact_set(l):
    single = []
    tuple = []
    prev = None
    span = 0
    for e in l:
        if prev is None:
            prev = e
            span = 0
            continue
        if prev+span+1 != e:
            if span > 2:
                tuple.append((prev,prev+span+1))
            else:
                for i in range(prev, prev+span+1):
                    single.append(i)
            prev = e
            span = 0
        else:
            span += 1
    if span:
        tuple.append((prev,prev+span+1))
    else:
        single.append(prev)
    tuple = " + ".join(["range(%d,%d)" % t for t in tuple])
    if not single:
        return "set(%s)" % tuple
    if not tuple:
        return "set(%s)" % repr(single)
    return "set(%s + %s)" % (repr(single),tuple)

############## Read the tables in the RFC #######################

data = open("rfc3454.txt").readlines()

tables = []
curname = None
for l in data:
    l = l.strip()
    if not l:
        continue
    # Skip RFC page breaks
    if l.startswith("Hoffman & Blanchet") or\
       l.startswith("RFC 3454"):
        continue
    # Find start/end lines
    m = re.match("----- (Start|End) Table ([A-Z](.[0-9])+) -----", l)
    if m:
        if m.group(1) == "Start":
            if curname:
                raise "Double Start",(curname, l)
            curname = m.group(2)
            table = {}
            tables.append((curname, table))
            continue
        else:
            if not curname:
                raise "End without start", l
            curname = None
            continue
    if not curname:
        continue
    # Now we are in a table
    fields = l.split(";")
    if len(fields) > 1:
        # Drop comment field
        fields = fields[:-1]
    if len(fields) == 1:<commit_msg>Tools/unicode/mkstringprep.py: Don't use string exceptions, partial backport from r78982.<commit_after>import re, unicodedata, sys

if sys.maxunicode == 65535:
    raise RuntimeError("need UCS-4 Python")

def gen_category(cats):
    for i in range(0, 0x110000):
        if unicodedata.category(unichr(i)) in cats:
            yield(i)

def gen_bidirectional(cats):
    for i in range(0, 0x110000):
        if unicodedata.bidirectional(unichr(i)) in cats:
            yield(i)

def compact_set(l):
    single = []
    tuple = []
    prev = None
    span = 0
    for e in l:
        if prev is None:
            prev = e
            span = 0
            continue
        if prev+span+1 != e:
            if span > 2:
                tuple.append((prev,prev+span+1))
            else:
                for i in range(prev, prev+span+1):
                    single.append(i)
            prev = e
            span = 0
        else:
            span += 1
    if span:
        tuple.append((prev,prev+span+1))
    else:
        single.append(prev)
    tuple = " + ".join(["range(%d,%d)" % t for t in tuple])
    if not single:
        return "set(%s)" % tuple
    if not tuple:
        return "set(%s)" % repr(single)
    return "set(%s + %s)" % (repr(single),tuple)

############## Read the tables in the RFC #######################

data = open("rfc3454.txt").readlines()

tables = []
curname = None
for l in data:
    l = l.strip()
    if not l:
        continue
    # Skip RFC page breaks
    if l.startswith("<NAME>") or\
       l.startswith("RFC 3454"):
        continue
    # Find start/end lines
    m = re.match("----- (Start|End) Table ([A-Z](.[0-9])+) -----", l)
    if m:
        if m.group(1) == "Start":
            if curname:
                raise RuntimeError("Double Start", (curname, l))
            curname = m.group(2)
            table = {}
            tables.append((curname, table))
            continue
        else:
            if not curname:
                raise RuntimeError("End without start", l)
            curname = None
            continue
    if not curname:
        continue
    # Now we are in a table
    fields = l.split(";")
    if len(fields) > 1:
        # Drop comment field
        fields = fields[:-1]
    if len(fields) == 1:
{'fraction_non_alphanumeric': 0.14259968461365172, 'fraction_numerical': 0.02185176841630998, 'mean_word_length': 1.6763110307414104, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 8, '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': '749402', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1396, 'n_words': 404}