Decode a tree splitted URI in format returned by uri_split_tree() or
    uri_tree_normalize(), the returned value keeping the same layout.

    user, passwd, path, fragment are percent decoded, and so is host if of
    type reg-name.

    >>> uri_tree_decode(
    ...     uri_split_tree(
    ...             'http://%42%20+blabla:lol@%77ww.foobar.org/%7Exilun/' +
    ...             '?query=+++%2b&=&===&a=b&&&+++aaa%3D=+%2B%2D&&&&' +
    ...             '#frag+++%42'))
    ('http', ('B +blabla', 'lol', 'www.foobar.org', None), '/~xilun/', (('query', '   +'), ('', ''), ('', '=='), ('a', 'b'), ('   aaa=', ' +-')), 'frag+++B')

def uri_tree_decode(uri_tree):
    """
    Decode a tree splitted URI in format returned by uri_split_tree() or
    uri_tree_normalize(), the returned value keeping the same layout.

    user, passwd, path, fragment are percent decoded, and so is host if of
    type reg-name.

    >>> uri_tree_decode(
    ...     uri_split_tree(
    ...             'http://%42%20+blabla:lol@%77ww.foobar.org/%7Exilun/' +
    ...             '?query=+++%2b&=&===&a=b&&&+++aaa%3D=+%2B%2D&&&&' +
    ...             '#frag+++%42'))
    ('http', ('B +blabla', 'lol', 'www.foobar.org', None), '/~xilun/', (('query', '   +'), ('', ''), ('', '=='), ('a', 'b'), ('   aaa=', ' +-')), 'frag+++B')
    """
    scheme, authority, path, query, fragment = uri_tree
    if authority:
        user, passwd, host, port = authority
        user, passwd = pct_decode(user), pct_decode(passwd)
        if host and host_type(host) == HOST_REG_NAME:
            host = pct_decode(host)
        authority = (user, passwd, host, port)
    path, fragment = pct_decode(path), pct_decode(fragment)
    if query:
        query = tuple([(query_elt_decode(x), query_elt_decode(y)) for (x, y) in query])
    return (scheme, authority, path, query, fragment)