def lookup_extension(typeinfo, default=None):
    """Returns a stix.Entity class for that has been registered for the
    `typeinfo` value.

    Note:
        This is for internal use only.

    Args:
        typeinfo: An object or string containing type information. This can be
            either an xsi:type attribute value or a stix.bindings object.
        default: Return class if typeinfo is None or contains no xml type
            information.

    Returns:
        A stix.Entity implementation class for the `xsi_type`.

    Raises:
        ValueError: If no class has been registered for the `xsi_type`.

    """
    if typeinfo is None and default:
        return default

    # If the `typeinfo` was a string, consider it a  full xsi:type value.
    if isinstance(typeinfo, basestring):
        return _lookup_extension(typeinfo)

    # Most extension bindings include this attribute.
    if not hasattr(typeinfo, 'xml_type'):
        if default:
            return default

        error = "Input %s is missing xml_type attribute. Cannot lookup class."
        raise ValueError(error)
    
    # Extension binding classes usually (always?) have an `xmlns_prefix`
    # class attribute.
    if hasattr(typeinfo, 'xmlns_prefix'):
        xsi_type = "%s:%s" % (typeinfo.xmlns_prefix, typeinfo.xml_type)
        return _lookup_extension(xsi_type)

    # no xmlns_prefix found, try to resolve the class by just the `xml_type`
    return _lookup_unprefixed(typeinfo.xml_type)
dataset/ETHPy150Open STIXProject/python-stix/stix/__init__.py/lookup_extension/original