# 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


from abc import ABCMeta, abstractproperty
from ..utils import python_2_unicode_compatible
import json
import six

    @property
    def document(self):
        return self._document

    @document.setter
    def document(self, document):
        # Subclasses may need to override this and also assign the document to sub-elements
        self._document = document
        # If we have problems with garbage collection, use a weakref to document to avoid circular references:
        # try:
        #     self._document = weakref.proxy(document)
        # except TypeError:
        #     self._document = document

    @abstractproperty
    def records(self):
        """Chemical records that have been parsed from this Element."""
        return []

    # @abstractmethod  # TODO: Put this back?
    # def serialize(self):
    #     """Convert Element to python dictionary."""
    #     return []

    def to_json(self, *args, **kwargs):
        """Convert Element to JSON string."""
        return json.dumps(self.serialize(), *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/doc/element.py
from abc import ABCMeta, abstractproperty
from ..utils import python_2_unicode_compatible
import json
import six


    @property
    def document(self):
        return self._document

    @document.setter
    def document(self, document):
        # Subclasses may need to override this and also assign the document to sub-elements
        self._document = document
        # If we have problems with garbage collection, use a weakref to document to avoid circular references:
        # try:
        #     self._document = weakref.proxy(document)
        # except TypeError:
        #     self._document = document

    @abstractproperty
    def records(self):
        """Chemical records that have been parsed from this Element."""
        return []

    # @abstractmethod  # TODO: Put this back?
    # def serialize(self):
    #     """Convert Element to python dictionary."""
    #     return []

    def to_json(self, *args, **kwargs):
        """Convert Element to JSON string."""
        return json.dumps(self.serialize(), *args, **kwargs)



@python_2_unicode_compatible