# Path: elasticmagic/types.py
# def instantiate(typeobj, *args, **kwargs):
#     if inspect.isclass(typeobj):
#         return typeobj(*args, **kwargs)
#     return typeobj
# 
# Path: elasticmagic/types.py
# 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
# def force_unicode(value):
#     """
#     Forces a bytestring to become a Unicode string.
#     """
#     if PY2:
#         # Python 2.X
#         if isinstance(value, str):
#             value = value.decode('utf-8', 'replace')
#         elif not isinstance(value, basestring):  # noqa:F821
#             value = unicode(value)  # noqa:F821
#     else:
#         # Python 3.X
#         if isinstance(value, bytes):
#             value = value.decode('utf-8', errors='replace')
#         elif not isinstance(value, str):
#             value = str(value)
# 
#     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 datetime
import math
import dateutil.parser
from collections import defaultdict
from elasticmagic.types import instantiate
from elasticmagic.types import Type
from elasticmagic.compat import force_unicode
from elasticmagic.compat import int_types
        return es_type, es_type.python_type

    def decode_value(self, value, es_type=None):
        if value is None or value == self.NULL_VAL:
            return None

        es_type, python_type = self._get_es_and_python_types(es_type)
        value_codec = self.CODECS.get(python_type, StringCodec)()
        return value_codec.decode(value, es_type=es_type)

    def decode(self, params, types=None):
        params = self._normalize_params(params)
        types = types or {}
        decoded_params = {}
        for name, v in params.items():
            name, _, op = name.partition(self.OP_SEP)
            if not op:
                op = self.DEFAULT_OP
            es_type = types.get(name)
            for w in wrap_list(v):
                try:
                    decoded_value = self.decode_value(w, es_type=es_type)
                    decoded_params \
                        .setdefault(name, {}) \
                        .setdefault(op, []) \
                        .append(decoded_value)
                except ValueError:
                    # just ignore values we cannot decode
                    pass


# Path: elasticmagic/types.py
# def instantiate(typeobj, *args, **kwargs):
#     if inspect.isclass(typeobj):
#         return typeobj(*args, **kwargs)
#     return typeobj
# 
# Path: elasticmagic/types.py
# 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
# def force_unicode(value):
#     """
#     Forces a bytestring to become a Unicode string.
#     """
#     if PY2:
#         # Python 2.X
#         if isinstance(value, str):
#             value = value.decode('utf-8', 'replace')
#         elif not isinstance(value, basestring):  # noqa:F821
#             value = unicode(value)  # noqa:F821
#     else:
#         # Python 3.X
#         if isinstance(value, bytes):
#             value = value.decode('utf-8', errors='replace')
#         elif not isinstance(value, str):
#             value = str(value)
# 
#     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/ext/queryfilter/codec.py
import datetime
import math
import dateutil.parser
from collections import defaultdict
from elasticmagic.types import instantiate
from elasticmagic.types import Type
from elasticmagic.compat import force_unicode
from elasticmagic.compat import int_types

        return es_type, es_type.python_type

    def decode_value(self, value, es_type=None):
        if value is None or value == self.NULL_VAL:
            return None

        es_type, python_type = self._get_es_and_python_types(es_type)
        value_codec = self.CODECS.get(python_type, StringCodec)()
        return value_codec.decode(value, es_type=es_type)

    def decode(self, params, types=None):
        params = self._normalize_params(params)
        types = types or {}
        decoded_params = {}
        for name, v in params.items():
            name, _, op = name.partition(self.OP_SEP)
            if not op:
                op = self.DEFAULT_OP
            es_type = types.get(name)
            for w in wrap_list(v):
                try:
                    decoded_value = self.decode_value(w, es_type=es_type)
                    decoded_params \
                        .setdefault(name, {}) \
                        .setdefault(op, []) \
                        .append(decoded_value)
                except ValueError:
                    # just ignore values we cannot decode
                    pass


        return decoded_params