Return keyset's state as a dict.

        The result can be used to serialize the instance and reconstitute
        it later using :meth:`_from_dict`.

        :rtype: dict
        :returns: state of this instance.

def _to_dict(self):
        """Return keyset's state as a dict.

        The result can be used to serialize the instance and reconstitute
        it later using :meth:`_from_dict`.

        :rtype: dict
        :returns: state of this instance.
        """
        if self.all_:
            return {"all": True}

        return {
            "keys": self.keys,
            "ranges": [keyrange._to_dict() for keyrange in self.ranges],
        }