def class_case(string):
    """
    Converts a string to class case. For example::

        class_case('one_two_three') -> 'OneTwoThree'
    """
    if not string:
        return string
    string = string.replace(' ', '_').replace('-', '_')
    parts = de_camel(string, '_', _lowercase=False).split('_')
    rv = ''
    while parts:
        part = parts.pop(0)
        rv += part.title() or '_'
        if part:
            break
    return rv + ''.join([part if part.isupper() else part.title()
                         for part in parts])
Converts a string to class case. For example::

        class_case('one_two_three') -> 'OneTwoThree'