def classinit(cls, realcls = None):
    """
    Automatically initialize a class by calling __clsinit__ if it exists on cls and its base types.
    Currently used to implement class static initialization, and in particular the Flags functionality.
    """
    for base in cls.__bases__:
        classinit(base, cls)
    f = getattr(cls, '__clsinit__', None)
    if f:
        f.__func__(realcls or cls)
    return cls