# Path: src/cloudant/_2to3.py
# PY2 = sys.version_info[0] < 3
# ENCODING = 'utf-8'
# NONETYPE = type(None)
# STRTYPE = basestring if PY2 else str
# UNITYPE = unicode if PY2 else str
# LONGTYPE = long if PY2 else int
# UNICHR = unichr if PY2 else chr
#     def iteritems_(adict):
#     def next_(itr):
#     def iteritems_(adict):
#     def next_(itr):
# def bytes_(astr):
# def unicode_(astr):
# 
# Path: src/cloudant/_common_util.py
# def response_to_json_dict(response, **kwargs):
#     """
#     Standard place to convert responses to JSON.
# 
#     :param response: requests response object
#     :param **kwargs: arguments accepted by json.loads
# 
#     :returns: dict of JSON response
#     """
#     if response.encoding is None:
#         response.encoding = 'utf-8'
#     return json.loads(response.text, **kwargs)
# 
# def assert_document_type_id(docid):
#     """
#     Validate the document ID.  Raises an error if the ID is an `_` prefixed name
#     that isn't either `_design` or `_local`.
#     :return:
#     """
#     invalid = False
#     if docid.startswith('_'):
#         if docid.startswith(DESIGN_PREFIX) and DESIGN_PREFIX != docid:
#             invalid = False
#         elif docid.startswith(LOCAL_PREFIX) and LOCAL_PREFIX != docid:
#             invalid = False
#         else:
#             invalid = True
#     if invalid:
#         raise CloudantArgumentError(137, docid)
# 
# def assert_attachment_name(attname):
#     """
#     Validate the document attachment's name.  Raises an error if `_` prefixed name exists.
#     :return:
#     """
#     if attname.startswith('_'):
#         raise CloudantArgumentError(138, attname)
# 
# Path: src/cloudant/error.py
# class CloudantDocumentException(CloudantException):
#     """
#     Provides a way to issue Cloudant library document specific exceptions.
# 
#     :param int code: A code value used to identify the document exception.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = DOCUMENT[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = DOCUMENT[code]
#         super(CloudantDocumentException, self).__init__(msg, code)


import json
import requests
from requests.exceptions import HTTPError
from ._2to3 import url_quote, url_quote_plus
from ._common_util import response_to_json_dict, assert_document_type_id, assert_attachment_name
from .error import CloudantDocumentException
            doc.update_field(
                action=doc.list_field_append,
                field='words',
                value='foo'
            )

        :param callable action: A routine that takes a Document object,
            a field name, and a value. The routine should attempt to
            update a field in the locally cached Document object with the
            given value, using whatever logic is appropriate.
            Valid actions are
            :func:`~cloudant.document.Document.list_field_append`,
            :func:`~cloudant.document.Document.list_field_remove`,
            :func:`~cloudant.document.Document.field_set`
        :param str field: Name of the field to update
        :param value: Value to update the field with
        :param int max_tries: In the case of a conflict, the number of retries
            to attempt
        """
        self._update_field(action, field, value, max_tries)

    def delete(self):
        """
        Removes the document from the remote database and clears the content of
        the locally cached Document object with the exception of the ``_id``
        field.  In order to successfully remove a document from the remote
        database, a ``_rev`` value must exist in the locally cached Document
        object.
        """
        if not self.get("_rev"):

# Path: src/cloudant/_2to3.py
# PY2 = sys.version_info[0] < 3
# ENCODING = 'utf-8'
# NONETYPE = type(None)
# STRTYPE = basestring if PY2 else str
# UNITYPE = unicode if PY2 else str
# LONGTYPE = long if PY2 else int
# UNICHR = unichr if PY2 else chr
#     def iteritems_(adict):
#     def next_(itr):
#     def iteritems_(adict):
#     def next_(itr):
# def bytes_(astr):
# def unicode_(astr):
# 
# Path: src/cloudant/_common_util.py
# def response_to_json_dict(response, **kwargs):
#     """
#     Standard place to convert responses to JSON.
# 
#     :param response: requests response object
#     :param **kwargs: arguments accepted by json.loads
# 
#     :returns: dict of JSON response
#     """
#     if response.encoding is None:
#         response.encoding = 'utf-8'
#     return json.loads(response.text, **kwargs)
# 
# def assert_document_type_id(docid):
#     """
#     Validate the document ID.  Raises an error if the ID is an `_` prefixed name
#     that isn't either `_design` or `_local`.
#     :return:
#     """
#     invalid = False
#     if docid.startswith('_'):
#         if docid.startswith(DESIGN_PREFIX) and DESIGN_PREFIX != docid:
#             invalid = False
#         elif docid.startswith(LOCAL_PREFIX) and LOCAL_PREFIX != docid:
#             invalid = False
#         else:
#             invalid = True
#     if invalid:
#         raise CloudantArgumentError(137, docid)
# 
# def assert_attachment_name(attname):
#     """
#     Validate the document attachment's name.  Raises an error if `_` prefixed name exists.
#     :return:
#     """
#     if attname.startswith('_'):
#         raise CloudantArgumentError(138, attname)
# 
# Path: src/cloudant/error.py
# class CloudantDocumentException(CloudantException):
#     """
#     Provides a way to issue Cloudant library document specific exceptions.
# 
#     :param int code: A code value used to identify the document exception.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = DOCUMENT[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = DOCUMENT[code]
#         super(CloudantDocumentException, self).__init__(msg, code)


# Path: src/cloudant/document.py
import json
import requests
from requests.exceptions import HTTPError
from ._2to3 import url_quote, url_quote_plus
from ._common_util import response_to_json_dict, assert_document_type_id, assert_attachment_name
from .error import CloudantDocumentException

            doc.update_field(
                action=doc.list_field_append,
                field='words',
                value='foo'
            )

        :param callable action: A routine that takes a Document object,
            a field name, and a value. The routine should attempt to
            update a field in the locally cached Document object with the
            given value, using whatever logic is appropriate.
            Valid actions are
            :func:`~cloudant.document.Document.list_field_append`,
            :func:`~cloudant.document.Document.list_field_remove`,
            :func:`~cloudant.document.Document.field_set`
        :param str field: Name of the field to update
        :param value: Value to update the field with
        :param int max_tries: In the case of a conflict, the number of retries
            to attempt
        """
        self._update_field(action, field, value, max_tries)

    def delete(self):
        """
        Removes the document from the remote database and clears the content of
        the locally cached Document object with the exception of the ``_id``
        field.  In order to successfully remove a document from the remote
        database, a ``_rev`` value must exist in the locally cached Document
        object.
        """
        if not self.get("_rev"):

            raise CloudantDocumentException(103)