import re


def camel2snake(name):
    """
    Convert name of callback by inserting underscores between small and capital
    letters. For example, `TestCallback` becomes `test_callback`.
    """
    pattern1 = re.compile("(.)([A-Z][a-z]+)")
    pattern2 = re.compile("([a-z0-9])([A-Z])")
    name = re.sub(pattern1, r"\1_\2", name)
    return re.sub(pattern2, r"\1_\2", name).lower()