human
I wrote the below code

    def lookup_by_attr(self, ref, before=None):
        u'\n                                Given    a    string    *ref*,    finds    the    first    element    in    the    iterator\n                                where    the    given    attribute    ==    *ref*.        If    *before*    is    provided,\n                                will    stop    searching    at    the    object    *before*.        This    is\n                                important,    since    "forward    references"    are    not    allowed    in    the\n                                VOTABLE    format.\n                                '
        for element in getattr(self, iterator)():
            if (element is before):
                if (getattr(element, attr, None) == ref):
                    vo_raise(u'{}    references    itself'.format(element_name), element._config, element._pos, KeyError)
                break
            if (getattr(element, attr, None) == ref):
                (yield element)
    def lookup_by_attr_unique(self, ref, before=None):
        for element in lookup_by_attr(self, ref, before=before):
            return element
        raise KeyError(u"No    {}    with    {}    '{}'    found    before    the    referencing    {}".format(element_name, attr, ref, element_name))
    if unique:
        lookup_by_attr_unique.__doc__ = doc
        return lookup_by_attr_unique
    else:
        lookup_by_attr.__doc__ = doc
        return lookup_by_attr

What's a good function header?
assistant
#Here's a good function header.

def _lookup_by_attr_factory(attr, unique, iterator, element_name, doc):