# Path: elasticmagic/util.py
# def clean_params(params, **kwargs):
#     return {
#         p: v for p, v in chain(params.items(), kwargs.items())
#         if v is not None
#     }
# 
# def collect_doc_classes(expr):
#     if hasattr(expr, '_collect_doc_classes'):
#         return expr._collect_doc_classes()
# 
#     if isinstance(expr, dict):
#         return set().union(
#             *[collect_doc_classes(e)
#               for e in chain(expr.keys(), expr.values())]
#         )
# 
#     if isinstance(expr, (list, tuple)):
#         return set().union(*[collect_doc_classes(e) for e in expr])
# 
#     return set()
# 
# Path: elasticmagic/types.py
# def instantiate(typeobj, *args, **kwargs):
#     if inspect.isclass(typeobj):
#         return typeobj(*args, **kwargs)
#     return typeobj
# 
# class Type(object):
#     python_type = None
# 
#     def __init__(self):
#         self.sub_type = None
#         self.doc_cls = None
# 
#     def to_python(self, value):
#         if value is None:
#             return None
#         if self.python_type is not None:
#             return self.python_type(value)
#         return value
# 
#     def to_python_single(self, value):
#         return self.to_python(value)
# 
#     def from_python(self, value, compiler, validate=False):
#         return value
# 
# Path: elasticmagic/compat.py
# PY2 = sys.version_info[0] == 2
# def force_unicode(value):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
#     class metaclass(meta):


import inspect
import operator
from itertools import count
from .util import clean_params, collect_doc_classes
from .types import instantiate, Type
from .compat import string_types, Mapping
                raise TypeError(
                    'Argument must be string or field type: {} found'.format(
                        args[0].__class__.__name__))
        elif len(args) == 2:
            self._name, self._type = args
        elif len(args) >= 3:
            raise TypeError('Too many positional arguments: %s' % len(args))

        if self._type is None:
            self._type = Type()
        self._type = instantiate(self._type)

        self._fields = kwargs.pop('fields', {})
        self._count = kwargs.pop('_counter', next(self._counter))
        self._mapping_options = kwargs

    def clone(self, cls=None):
        cls = cls or self.__class__
        assert issubclass(cls, Field)
        return cls(
            self._name, self._type, fields=self._fields,
            **self._mapping_options
        )

    def get_name(self):
        return self._name

    def get_type(self):
        return self._type


# Path: elasticmagic/util.py
# def clean_params(params, **kwargs):
#     return {
#         p: v for p, v in chain(params.items(), kwargs.items())
#         if v is not None
#     }
# 
# def collect_doc_classes(expr):
#     if hasattr(expr, '_collect_doc_classes'):
#         return expr._collect_doc_classes()
# 
#     if isinstance(expr, dict):
#         return set().union(
#             *[collect_doc_classes(e)
#               for e in chain(expr.keys(), expr.values())]
#         )
# 
#     if isinstance(expr, (list, tuple)):
#         return set().union(*[collect_doc_classes(e) for e in expr])
# 
#     return set()
# 
# Path: elasticmagic/types.py
# def instantiate(typeobj, *args, **kwargs):
#     if inspect.isclass(typeobj):
#         return typeobj(*args, **kwargs)
#     return typeobj
# 
# class Type(object):
#     python_type = None
# 
#     def __init__(self):
#         self.sub_type = None
#         self.doc_cls = None
# 
#     def to_python(self, value):
#         if value is None:
#             return None
#         if self.python_type is not None:
#             return self.python_type(value)
#         return value
# 
#     def to_python_single(self, value):
#         return self.to_python(value)
# 
#     def from_python(self, value, compiler, validate=False):
#         return value
# 
# Path: elasticmagic/compat.py
# PY2 = sys.version_info[0] == 2
# def force_unicode(value):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
#     class metaclass(meta):


# Path: elasticmagic/expression.py
import inspect
import operator
from itertools import count
from .util import clean_params, collect_doc_classes
from .types import instantiate, Type
from .compat import string_types, Mapping

                raise TypeError(
                    'Argument must be string or field type: {} found'.format(
                        args[0].__class__.__name__))
        elif len(args) == 2:
            self._name, self._type = args
        elif len(args) >= 3:
            raise TypeError('Too many positional arguments: %s' % len(args))

        if self._type is None:
            self._type = Type()
        self._type = instantiate(self._type)

        self._fields = kwargs.pop('fields', {})
        self._count = kwargs.pop('_counter', next(self._counter))
        self._mapping_options = kwargs

    def clone(self, cls=None):
        cls = cls or self.__class__
        assert issubclass(cls, Field)
        return cls(
            self._name, self._type, fields=self._fields,
            **self._mapping_options
        )

    def get_name(self):
        return self._name

    def get_type(self):
        return self._type


    def get_mapping_options(self):