code: def _document_by_attribute(self, kind, condition=None):
          
          doc = self.document
          if doc:
              for attr in doc.attributes:
                  if isinstance(attr, kind):
                      if not condition or condition(attr):
                          return doc
                      return None
docs: Helper method to return the document only if it has an attribute
          that's an instance of the given kind, and passes the condition.