def query(self, before=None, after=None, before_id=None, after_id=None,
              types=None, direction=None, limit=None):
        before = none_or(before, Timestamp)
        after = none_or(after, Timestamp)
        before_id = none_or(before_id, int)
        after_id = none_or(after_id, int)
        types = none_or(types, levels=self.TYPES)
        direction = none_or(direction, levels=self.DIRECTIONS)
        limit = none_or(limit, int)

        query = """
            SELECT * FROM recentchanges
            WHERE 1
        """
        values = []

        if before is not None:
            query += " AND rc_timestamp < %s "
            values.append(before.short_format())
        if after is not None:
            query += " AND rc_timestamp < %s "
            values.append(after.short_format())
        if before_id is not None:
            query += " AND rc_id < %s "
            values.append(before_id)
        if after_id is not None:
            query += " AND rc_id < %s "
            values.append(after_id)
        if types is not None:
            query += " AND rc_type IN ({0}) ".format(
                ",".join(self.TYPES[t] for t in types)
            )

        if direction is not None:
            direction = ("ASC " if direction == "newer" else "DESC ")
            query += " ORDER BY rc_timestamp {0}, rc_id {0}".format(dir)

        if limit is not None:
            query += " LIMIT %s "
            values.append(limit)

        cursor.execute(query, values)
        for row in cursor:
            yield row
Wait, optionally timing out, for the event to fire. cf also the :func:`any` and
dataset/ETHPy150Open mediawiki-utilities/python-mediawiki-utilities/mw/database/collections/recent_changes.py/RecentChanges.query--crossover with--dataset/ETHPy150Open tjguk/winsys/winsys/ipc.py/Event.wait