<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _document_by_attribute(self, kind, condition=None):
 """ Helper method to return the document only if it has an attribute that's an instance of the given kind, and passes the condition. """

        doc = self.document
        if doc:
            for attr in doc.attributes:
                if isinstance(attr, kind):
                    if not condition or condition(attr):
                        return doc
                    return None