def dispatch(source, tag, buffer):
    """Dispatch on source for tag with buffer

    Find the attribute or key tag[0] of source,
    then call it with (tag, buffer)
    """
    try:
        function = getattr(source, tag[0])
    except AttributeError:
        try:
            function = source[tag[0]]
        except:
            raise AttributeError(
                'No processing function for tag "%s" in object %s! Check the parser definition!'
                 % (tag[0], repr(source)))
    return function(tag, buffer)
