# Path: chemdataextractor/utils.py
# def python_2_unicode_compatible(klass):
#     """Fix __str__, __unicode__ and __repr__ methods under Python 2."""
#     if six.PY2:
#         if '__str__' not in klass.__dict__:
#             raise ValueError("Define __str__() on %s to use @python_2_unicode_compatible" % klass.__name__)
#         if '__repr__' not in klass.__dict__:
#             raise ValueError("Define __repr__() on %s to use @python_2_unicode_compatible" % klass.__name__)
#         klass.__unicode__ = klass.__str__
#         klass._unicode_repr = klass.__repr__
#         klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
#         klass.__repr__ = lambda self: self._unicode_repr().encode('ascii', errors='backslashreplace')
#     return klass


import copy
import json
import logging
import six
from abc import ABCMeta
from collections import MutableSequence
from .utils import python_2_unicode_compatible
                        return False
                else:
                    # If a single Model type, not contextual if it isn't
                    if isinstance(field, ModelType):
                        if not value.is_contextual:
                            return False
                    elif not field.contextual:
                        return False
        return True

    def serialize(self, primitive=False):
        """Convert Model to python dictionary."""
        # Serialize fields to a dict
        data = {}
        for field_name in self:
            value = getattr(self, field_name)
            field = self.fields.get(field_name)
            if value is not None:
                value = field.serialize(value, primitive=primitive)
            # Skip empty fields unless field.null
            if not field.null and value in [None, '', []]:
                continue
            data[field.name] = value
        return data

    def to_json(self, *args, **kwargs):
        """Convert Model to JSON."""
        return json.dumps(self.serialize(primitive=True), *args, **kwargs)



# Path: chemdataextractor/utils.py
# def python_2_unicode_compatible(klass):
#     """Fix __str__, __unicode__ and __repr__ methods under Python 2."""
#     if six.PY2:
#         if '__str__' not in klass.__dict__:
#             raise ValueError("Define __str__() on %s to use @python_2_unicode_compatible" % klass.__name__)
#         if '__repr__' not in klass.__dict__:
#             raise ValueError("Define __repr__() on %s to use @python_2_unicode_compatible" % klass.__name__)
#         klass.__unicode__ = klass.__str__
#         klass._unicode_repr = klass.__repr__
#         klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
#         klass.__repr__ = lambda self: self._unicode_repr().encode('ascii', errors='backslashreplace')
#     return klass


# Path: chemdataextractor/model.py
import copy
import json
import logging
import six
from abc import ABCMeta
from collections import MutableSequence
from .utils import python_2_unicode_compatible

                        return False
                else:
                    # If a single Model type, not contextual if it isn't
                    if isinstance(field, ModelType):
                        if not value.is_contextual:
                            return False
                    elif not field.contextual:
                        return False
        return True

    def serialize(self, primitive=False):
        """Convert Model to python dictionary."""
        # Serialize fields to a dict
        data = {}
        for field_name in self:
            value = getattr(self, field_name)
            field = self.fields.get(field_name)
            if value is not None:
                value = field.serialize(value, primitive=primitive)
            # Skip empty fields unless field.null
            if not field.null and value in [None, '', []]:
                continue
            data[field.name] = value
        return data

    def to_json(self, *args, **kwargs):
        """Convert Model to JSON."""
        return json.dumps(self.serialize(primitive=True), *args, **kwargs)



@python_2_unicode_compatible