# 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
    def decode(self, value, es_type=None):
        raise NotImplementedError

    def encode(self, value, es_type=None):
        raise NotImplementedError


class StringCodec(TypeCodec):
    def decode(self, value, es_type=None):
        return force_unicode(value)

    def encode(self, value, es_type=None):
        return force_unicode(value)


class FloatCodec(TypeCodec):
    def decode(self, value, es_type=None):
        v = float(value)
        if math.isnan(v) or math.isinf(v):
            raise ValueError('NaN or Inf is not supported')
        return v

    def encode(self, value, es_type=None):
        return value


class IntCodec(TypeCodec):
    def encode(self, value, es_type=None):
        if isinstance(value, int_types):
            return force_unicode(value)

# 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

    def decode(self, value, es_type=None):
        raise NotImplementedError

    def encode(self, value, es_type=None):
        raise NotImplementedError


class StringCodec(TypeCodec):
    def decode(self, value, es_type=None):
        return force_unicode(value)

    def encode(self, value, es_type=None):
        return force_unicode(value)


class FloatCodec(TypeCodec):
    def decode(self, value, es_type=None):
        v = float(value)
        if math.isnan(v) or math.isinf(v):
            raise ValueError('NaN or Inf is not supported')
        return v

    def encode(self, value, es_type=None):
        return value


class IntCodec(TypeCodec):
    def encode(self, value, es_type=None):
        if isinstance(value, int_types):
            return force_unicode(value)

        return force_unicode(int(value))