# Path: elasticsearch_dsl/exceptions.py
# class UnknownDslObject(ElasticsearchDslException):
#     pass
# 
# class ValidationException(ValueError, ElasticsearchDslException):
#     pass


    import collections.abc as collections_abc  # only works on python 3.3+
    import collections as collections_abc
from copy import copy
from six import add_metaclass, iteritems
from six.moves import map
from .exceptions import UnknownDslObject, ValidationException
    def to_dict(self, skip_empty=True):
        out = {}
        for k, v in iteritems(self._d_):
            # if this is a mapped field,
            f = self.__get_field(k)
            if f and f._coerce:
                v = f.serialize(v)

            # if someone assigned AttrList, unwrap it
            if isinstance(v, AttrList):
                v = v._l_

            if skip_empty:
                # don't serialize empty values
                # careful not to include numeric zeros
                if v in ([], {}, None):
                    continue

            out[k] = v
        return out

    def clean_fields(self):
        errors = {}
        for name, field, optional in self.__list_fields():
            data = self._d_.get(name, None)
            if data is None and optional:
                continue
            try:
                # save the cleaned value
                data = field.clean(data)

# Path: elasticsearch_dsl/exceptions.py
# class UnknownDslObject(ElasticsearchDslException):
#     pass
# 
# class ValidationException(ValueError, ElasticsearchDslException):
#     pass


# Path: elasticsearch_dsl/utils.py
    import collections.abc as collections_abc  # only works on python 3.3+
    import collections as collections_abc
from copy import copy
from six import add_metaclass, iteritems
from six.moves import map
from .exceptions import UnknownDslObject, ValidationException

    def to_dict(self, skip_empty=True):
        out = {}
        for k, v in iteritems(self._d_):
            # if this is a mapped field,
            f = self.__get_field(k)
            if f and f._coerce:
                v = f.serialize(v)

            # if someone assigned AttrList, unwrap it
            if isinstance(v, AttrList):
                v = v._l_

            if skip_empty:
                # don't serialize empty values
                # careful not to include numeric zeros
                if v in ([], {}, None):
                    continue

            out[k] = v
        return out

    def clean_fields(self):
        errors = {}
        for name, field, optional in self.__list_fields():
            data = self._d_.get(name, None)
            if data is None and optional:
                continue
            try:
                # save the cleaned value
                data = field.clean(data)

            except ValidationException as e: