def qname_to_extended(qname, namespaces):
    """
    Maps a QName in prefixed format or a local name to the extended QName format.
    Local names are mapped if *namespaces* has a not empty default namespace.

    :param qname: a QName in prefixed format or a local name.
    :param namespaces: a map from prefixes to namespace URIs.
    :return: a QName in extended format or a local name.
    """
    try:
        if qname[0] == '{' or not namespaces:
            return qname
    except IndexError:
        return qname

    try:
        prefix, name = qname.split(':', 1)
    except ValueError:
        if not namespaces.get(''):
            return qname
        else:
            return '{%s}%s' % (namespaces[''], qname)
    else:
        try:
            uri = namespaces[prefix]
        except KeyError:
            return qname
        else:
            return u'{%s}%s' % (uri, name) if uri else name