def to_yaml(self, stream=None): d = self.to_dict() out = compat.u(dump(d)) if stream is None: return out stream.write(compat.b(out, encoding="utf-8"))