def _instance_handler_factory(handler):
    """ Get the instance factory of an Instance or TraitInstance
    """
    from traits.api import BaseInstance, TraitInstance
    if isinstance(handler, TraitInstance):
        return handler.aClass
    elif isinstance(handler, BaseInstance):
        return handler.default_value
    else:
        msg = 'handler should be TraitInstance or BaseInstance, but got {}'
        raise ValueError(msg.format(repr(handler)))
