# Path: onecodex/vendored/potion_client/exceptions.py
# class ItemNotFound(Exception):
#     pass
# 
# class MultipleItemsFound(Exception):
#     pass
# 
# Path: onecodex/vendored/potion_client/utils.py
# def escape(html):
#     """Returns the given HTML with ampersands, quotes and carets encoded."""
#     return html \
#         .replace('&', '&amp;') \
#         .replace('<', '&lt;') \
#         .replace('>', '&gt;') \
#         .replace('"', '&quot;') \
#         .replace("'", '&#39;')


import collections
import six
from pprint import pformat
from .exceptions import ItemNotFound, MultipleItemsFound
from .utils import escape
    # TODO cache this property
    @property
    def _validator(self):
        return None

    def __delitem__(self, item):
        del self._properties[item]

    def __setitem__(self, item, value):
        self._properties[item] = value

    def update(self, *args, **kwargs):
        self._properties.update(*args, **kwargs)
        self.save()

    @classmethod
    def first(cls, **params):
        try:
            return cls._instances(per_page=1, **params)[0]
        except IndexError:
            raise ItemNotFound("No '{}' item found matching: {}".format(cls.__name__, repr(params)))

    @classmethod
    def one(cls, **params):
        matching = cls._instances(per_page=1, **params)
        if len(matching) > 1:
            raise MultipleItemsFound("Multiple items found matching: {}".format(repr(params)))
        try:
            return matching[0]
        except IndexError:

# Path: onecodex/vendored/potion_client/exceptions.py
# class ItemNotFound(Exception):
#     pass
# 
# class MultipleItemsFound(Exception):
#     pass
# 
# Path: onecodex/vendored/potion_client/utils.py
# def escape(html):
#     """Returns the given HTML with ampersands, quotes and carets encoded."""
#     return html \
#         .replace('&', '&amp;') \
#         .replace('<', '&lt;') \
#         .replace('>', '&gt;') \
#         .replace('"', '&quot;') \
#         .replace("'", '&#39;')


# Path: onecodex/vendored/potion_client/resource.py
import collections
import six
from pprint import pformat
from .exceptions import ItemNotFound, MultipleItemsFound
from .utils import escape

    # TODO cache this property
    @property
    def _validator(self):
        return None

    def __delitem__(self, item):
        del self._properties[item]

    def __setitem__(self, item, value):
        self._properties[item] = value

    def update(self, *args, **kwargs):
        self._properties.update(*args, **kwargs)
        self.save()

    @classmethod
    def first(cls, **params):
        try:
            return cls._instances(per_page=1, **params)[0]
        except IndexError:
            raise ItemNotFound("No '{}' item found matching: {}".format(cls.__name__, repr(params)))

    @classmethod
    def one(cls, **params):
        matching = cls._instances(per_page=1, **params)
        if len(matching) > 1:
            raise MultipleItemsFound("Multiple items found matching: {}".format(repr(params)))
        try:
            return matching[0]
        except IndexError:

            raise ItemNotFound("No '{}' item found matching: {}".format(cls.__name__, repr(params)))