Returns dict containing zmq configuration arguments
    parsed from xbahn url

    Arguments:

        - u (urlparse.urlparse result)

    Returns:

        dict:
            - id (str): connection index key
            - typ_str (str): string representation of zmq socket type
            - typ (int): zmq socket type (PUB, SUB, REQ, REP, PUSH, PULL)
            - topic (str): subscription topic
            - url (str): url to use with zmq's bind function

def config_from_url(u, **kwargs):

    """
    Returns dict containing zmq configuration arguments
    parsed from xbahn url

    Arguments:

        - u (urlparse.urlparse result)

    Returns:

        dict:
            - id (str): connection index key
            - typ_str (str): string representation of zmq socket type
            - typ (int): zmq socket type (PUB, SUB, REQ, REP, PUSH, PULL)
            - topic (str): subscription topic
            - url (str): url to use with zmq's bind function
    """

    path = u.path.lstrip("/").split("/")
    if len(path) > 2 or not path:
        raise AssertionError("zmq url format: zmq://<host>:<port>/<pub|sub>/<topic>")

    typ = path[0].upper()

    try:
        topic = path[1]
    except IndexError as _:
        topic = ''

    param = dict(urllib.parse.parse_qsl(u.query))

    #FIXME: should come from schema, maybe zmq+tcp:// ?
    transport = param.get("transport", "tcp")

    _id = "%s-%s-%s-%s" % (typ, topic, transport, u.netloc)
    if kwargs.get("prefix") is not None:
        _id = "%s-%s" % (kwargs.get("prefix"), _id)

    return {
        "id" : _id,
        "typ_str" : typ,
        "typ" : getattr(zmq, typ),
        "topic" : topic,
        "transport" : transport,
        "url" : "%s://%s" % (transport, u.netloc)
    }