import inspect
import stringprep
SASLPREP_PROHIBITED = (
stringprep.in_table_a1, stringprep.in_table_c12,
stringprep.in_table_c21_c22,
stringprep.in_table_c3,
stringprep.in_table_c4,
stringprep.in_table_c5,
stringprep.in_table_c6,
stringprep.in_table_c7,
stringprep.in_table_c8,
stringprep.in_table_c9,
)
def gen(name, f):
r = None
print()
print(f"// {inspect.getsource(f).strip().replace('\n', '\n// ')}")
print(f"super::stringprep::process_ranges!({name} =>")
for c in range(0, 0x110000):
c = chr(c)
prohibited = f(c)
if prohibited and r is None:
r = ord(c)
if not prohibited and r is not None:
print(f"(0x{r:x}, 0x{ord(c):x})")
r = None
if r:
print(f"0x{r:x}")
print(");")
print("// Autogenerated by stringprep_table_prep.py: DO NOT EDIT")
gen("not_prohibited", lambda c: not any(
in_prohibited_table(c)
for in_prohibited_table in SASLPREP_PROHIBITED
))
gen("maps_to_space", lambda c: stringprep.in_table_c12(c))
gen("maps_to_nothing", lambda c: stringprep.in_table_b1(c))
gen("table_d1", lambda c: stringprep.in_table_d1(c))
gen("table_d2", lambda c: stringprep.in_table_d2(c))