Split given URI into a tuple of (protocol, module URI, attribute chain).

    @param mod_attr_sep: the separator between module name and attribute name.

def split_uri(uri, mod_attr_sep='::'):
    """Split given URI into a tuple of (protocol, module URI, attribute chain).

    @param mod_attr_sep: the separator between module name and attribute name.
    """
    uri_parts = uri.split(mod_attr_sep, 1)

    if len(uri_parts) == 2:
        mod_uri, attr_chain = uri_parts
    else:
        mod_uri = uri_parts[0]

        attr_chain = None

    if mod_uri.startswith('py://'):
        protocol = 'py'

        mod_uri = mod_uri[5:]

    elif mod_uri.startswith('file://'):
        protocol = 'file'

        mod_uri = mod_uri[7:]

    # If no protocol prefix is present, and the uri ends with `.py`, then
    # consider the uri as module file path instead of module name.
    elif mod_uri.endswith('.py'):
        protocol = 'file'

    else:
        protocol = 'py'

    info = (protocol, mod_uri, attr_chain)

    return info