# Path: src/cloudant/_2to3.py
# def iteritems_(adict):
#     """
#     iterate dict key, value tuples in a py2 and 3 compatible way
# 
#     :param dict adict:
#     :return: iterator of (key, value) tuples
#     """
#     return adict.iteritems()
# 
# def next_(itr):
#     """
#     return next item from an iterable is a py2 and 3 compatible way
# 
#     :param Iterable itr:
#     :return: the next item in itr
#     """
#     return itr.next()
# 
# def unicode_(astr):
#     """
#     return a unicode string representation of astr in a py2 and 3 compatible way
# 
#     :param bytes astr:
#     :return: unicode string
#     """
#     return astr.decode(ENCODING) if hasattr(astr, 'decode') else astr
# 
# STRTYPE = basestring if PY2 else str
# 
# NONETYPE = type(None)
# 
# Path: src/cloudant/error.py
# class CloudantArgumentError(CloudantException):
#     """
#     Provides a way to issue Cloudant Python client library specific exceptions
#     that pertain to invalid argument errors.
# 
#     Note:  The intended use for this class is internal to the Cloudant Python
#     client library.
# 
#     :param int code: An optional code value used to identify the exception.
#         Defaults to 100.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = ARGUMENT_ERROR[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = ARGUMENT_ERROR[code]
#         super(CloudantArgumentError, self).__init__(msg, code)
# 
# class CloudantFeedException(CloudantException):
#     """
#     Provides a way to issue Cloudant library feed specific exceptions.
# 
#     :param int code: A code value used to identify the feed exception.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = FEED[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = FEED[code]
#         super(CloudantFeedException, self).__init__(msg, code)
# 
# Path: src/cloudant/_common_util.py
# ANY_ARG = object()
# 
# ANY_TYPE = object()
# 
# def feed_arg_types(feed_type):
#     """
#     Return the appropriate argument type dictionary based on the type of feed.
#     """
#     if feed_type == 'Cloudant':
#         return _DB_UPDATES_ARG_TYPES
#     if feed_type == 'CouchDB':
#         return _COUCH_DB_UPDATES_ARG_TYPES
#     return _CHANGES_ARG_TYPES
# 
# TYPE_CONVERTERS = {
#     STRTYPE: lambda x: json.dumps(x),
#     str: lambda x: json.dumps(x),
#     UNITYPE: lambda x: json.dumps(x),
#     Sequence: lambda x: json.dumps(list(x)),
#     list: lambda x: json.dumps(x),
#     tuple: lambda x: json.dumps(list(x)),
#     int: lambda x: x,
#     LONGTYPE: lambda x: x,
#     bool: lambda x: 'true' if x else 'false',
#     NONETYPE: lambda x: x
# }


import json
from ._2to3 import iteritems_, next_, unicode_, STRTYPE, NONETYPE
from .error import CloudantArgumentError, CloudantFeedException
from ._common_util import ANY_ARG, ANY_TYPE, feed_arg_types, TYPE_CONVERTERS
        self._resp.raise_for_status()
        self._lines = self._resp.iter_lines(self._chunk_size)

    def _translate(self, options):
        """
        Perform translation of feed options passed in as keyword
        arguments to CouchDB/Cloudant equivalent.
        """
        translation = dict()
        for key, val in iteritems_(options):
            self._validate(key, val, feed_arg_types(self._source))
            try:
                if isinstance(val, STRTYPE):
                    translation[key] = val
                elif not isinstance(val, NONETYPE):
                    arg_converter = TYPE_CONVERTERS.get(type(val), json.dumps)
                    translation[key] = arg_converter(val)
            except Exception as ex:
                raise CloudantArgumentError(115, key, ex)
        return translation

    def _validate(self, key, val, arg_types):
        """
        Ensures that the key and the value are valid arguments to be used with
        the feed.
        """
        if key in arg_types:
            arg_type = arg_types[key]
        else:
            if ANY_ARG not in arg_types:

# Path: src/cloudant/_2to3.py
# def iteritems_(adict):
#     """
#     iterate dict key, value tuples in a py2 and 3 compatible way
# 
#     :param dict adict:
#     :return: iterator of (key, value) tuples
#     """
#     return adict.iteritems()
# 
# def next_(itr):
#     """
#     return next item from an iterable is a py2 and 3 compatible way
# 
#     :param Iterable itr:
#     :return: the next item in itr
#     """
#     return itr.next()
# 
# def unicode_(astr):
#     """
#     return a unicode string representation of astr in a py2 and 3 compatible way
# 
#     :param bytes astr:
#     :return: unicode string
#     """
#     return astr.decode(ENCODING) if hasattr(astr, 'decode') else astr
# 
# STRTYPE = basestring if PY2 else str
# 
# NONETYPE = type(None)
# 
# Path: src/cloudant/error.py
# class CloudantArgumentError(CloudantException):
#     """
#     Provides a way to issue Cloudant Python client library specific exceptions
#     that pertain to invalid argument errors.
# 
#     Note:  The intended use for this class is internal to the Cloudant Python
#     client library.
# 
#     :param int code: An optional code value used to identify the exception.
#         Defaults to 100.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = ARGUMENT_ERROR[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = ARGUMENT_ERROR[code]
#         super(CloudantArgumentError, self).__init__(msg, code)
# 
# class CloudantFeedException(CloudantException):
#     """
#     Provides a way to issue Cloudant library feed specific exceptions.
# 
#     :param int code: A code value used to identify the feed exception.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = FEED[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = FEED[code]
#         super(CloudantFeedException, self).__init__(msg, code)
# 
# Path: src/cloudant/_common_util.py
# ANY_ARG = object()
# 
# ANY_TYPE = object()
# 
# def feed_arg_types(feed_type):
#     """
#     Return the appropriate argument type dictionary based on the type of feed.
#     """
#     if feed_type == 'Cloudant':
#         return _DB_UPDATES_ARG_TYPES
#     if feed_type == 'CouchDB':
#         return _COUCH_DB_UPDATES_ARG_TYPES
#     return _CHANGES_ARG_TYPES
# 
# TYPE_CONVERTERS = {
#     STRTYPE: lambda x: json.dumps(x),
#     str: lambda x: json.dumps(x),
#     UNITYPE: lambda x: json.dumps(x),
#     Sequence: lambda x: json.dumps(list(x)),
#     list: lambda x: json.dumps(x),
#     tuple: lambda x: json.dumps(list(x)),
#     int: lambda x: x,
#     LONGTYPE: lambda x: x,
#     bool: lambda x: 'true' if x else 'false',
#     NONETYPE: lambda x: x
# }


# Path: src/cloudant/feed.py
import json
from ._2to3 import iteritems_, next_, unicode_, STRTYPE, NONETYPE
from .error import CloudantArgumentError, CloudantFeedException
from ._common_util import ANY_ARG, ANY_TYPE, feed_arg_types, TYPE_CONVERTERS

        self._resp.raise_for_status()
        self._lines = self._resp.iter_lines(self._chunk_size)

    def _translate(self, options):
        """
        Perform translation of feed options passed in as keyword
        arguments to CouchDB/Cloudant equivalent.
        """
        translation = dict()
        for key, val in iteritems_(options):
            self._validate(key, val, feed_arg_types(self._source))
            try:
                if isinstance(val, STRTYPE):
                    translation[key] = val
                elif not isinstance(val, NONETYPE):
                    arg_converter = TYPE_CONVERTERS.get(type(val), json.dumps)
                    translation[key] = arg_converter(val)
            except Exception as ex:
                raise CloudantArgumentError(115, key, ex)
        return translation

    def _validate(self, key, val, arg_types):
        """
        Ensures that the key and the value are valid arguments to be used with
        the feed.
        """
        if key in arg_types:
            arg_type = arg_types[key]
        else:
            if ANY_ARG not in arg_types:

                raise CloudantArgumentError(116, key)