# Path: src/cloudant/_2to3.py
# LONGTYPE = long if PY2 else int
# 
# STRTYPE = basestring if PY2 else str
# 
# NONETYPE = type(None)
# 
# UNITYPE = unicode if PY2 else str
# 
# 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()
# 
# 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 CloudantException(Exception):
#     """
#     Provides a way to issue Cloudant Python client library specific exceptions.
#     A CloudantException object is instantiated with a message and optional code.
# 
#     Note:  The intended use for this class is internal to the Cloudant Python
#     client library.
# 
#     :param str msg: A message that describes the exception.
#     :param int code: A code value used to identify the exception.
#     """
#     def __init__(self, msg, code=None):
#         super(CloudantException, self).__init__(msg)
#         self.status_code = code
# 
# class CloudantClientException(CloudantException):
#     """
#     Provides a way to issue Cloudant library client specific exceptions.
# 
#     :param int code: A code value used to identify the client exception.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = CLIENT[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = CLIENT[code]
#         super(CloudantClientException, self).__init__(msg, code)


import sys
import platform
import json
from ._2to3 import LONGTYPE, STRTYPE, NONETYPE, UNITYPE, iteritems_
from .error import CloudantArgumentError, CloudantException, CloudantClientException
    from collections.abc import Sequence
    from collections import Sequence
    # Validate argument values and ensure that a boolean is not passed in
    # if an integer is expected
    if (not isinstance(val, RESULT_ARG_TYPES[key]) or
            (type(val) is bool and bool not in RESULT_ARG_TYPES[key] and
             int in RESULT_ARG_TYPES[key])):
        raise CloudantArgumentError(117, key, RESULT_ARG_TYPES[key])
    if key == 'keys':
        for key_list_val in val:
            if (not isinstance(key_list_val, RESULT_ARG_TYPES['key']) or
                    isinstance(key_list_val, bool)):
                raise CloudantArgumentError(134, RESULT_ARG_TYPES['key'])
    if key == 'stale':
        if val not in ('ok', 'update_after'):
            raise CloudantArgumentError(135, val)

def _py_to_couch_translate(key, val, encoder=None):
    """
    Performs the conversion of the Python parameter value to its CouchDB
    equivalent.
    """
    try:
        if key in ['keys', 'endkey_docid', 'startkey_docid', 'stale', 'update']:
            return {key: val}
        if key in ['endkey', 'key', 'startkey']:
            return {key: json.dumps(val, cls=encoder)}
        if val is None:
            return {key: None}
        arg_converter = TYPE_CONVERTERS.get(type(val))
        return {key: arg_converter(val)}
    except Exception as ex:

# Path: src/cloudant/_2to3.py
# LONGTYPE = long if PY2 else int
# 
# STRTYPE = basestring if PY2 else str
# 
# NONETYPE = type(None)
# 
# UNITYPE = unicode if PY2 else str
# 
# 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()
# 
# 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 CloudantException(Exception):
#     """
#     Provides a way to issue Cloudant Python client library specific exceptions.
#     A CloudantException object is instantiated with a message and optional code.
# 
#     Note:  The intended use for this class is internal to the Cloudant Python
#     client library.
# 
#     :param str msg: A message that describes the exception.
#     :param int code: A code value used to identify the exception.
#     """
#     def __init__(self, msg, code=None):
#         super(CloudantException, self).__init__(msg)
#         self.status_code = code
# 
# class CloudantClientException(CloudantException):
#     """
#     Provides a way to issue Cloudant library client specific exceptions.
# 
#     :param int code: A code value used to identify the client exception.
#     :param args: A list of arguments used to format the exception message.
#     """
#     def __init__(self, code=100, *args):
#         try:
#             msg = CLIENT[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = CLIENT[code]
#         super(CloudantClientException, self).__init__(msg, code)


# Path: src/cloudant/_common_util.py
import sys
import platform
import json
from ._2to3 import LONGTYPE, STRTYPE, NONETYPE, UNITYPE, iteritems_
from .error import CloudantArgumentError, CloudantException, CloudantClientException
    from collections.abc import Sequence
    from collections import Sequence

    # Validate argument values and ensure that a boolean is not passed in
    # if an integer is expected
    if (not isinstance(val, RESULT_ARG_TYPES[key]) or
            (type(val) is bool and bool not in RESULT_ARG_TYPES[key] and
             int in RESULT_ARG_TYPES[key])):
        raise CloudantArgumentError(117, key, RESULT_ARG_TYPES[key])
    if key == 'keys':
        for key_list_val in val:
            if (not isinstance(key_list_val, RESULT_ARG_TYPES['key']) or
                    isinstance(key_list_val, bool)):
                raise CloudantArgumentError(134, RESULT_ARG_TYPES['key'])
    if key == 'stale':
        if val not in ('ok', 'update_after'):
            raise CloudantArgumentError(135, val)

def _py_to_couch_translate(key, val, encoder=None):
    """
    Performs the conversion of the Python parameter value to its CouchDB
    equivalent.
    """
    try:
        if key in ['keys', 'endkey_docid', 'startkey_docid', 'stale', 'update']:
            return {key: val}
        if key in ['endkey', 'key', 'startkey']:
            return {key: json.dumps(val, cls=encoder)}
        if val is None:
            return {key: None}
        arg_converter = TYPE_CONVERTERS.get(type(val))
        return {key: arg_converter(val)}
    except Exception as ex:

        raise CloudantArgumentError(136, key, ex)