# Path: src/cloudant/_2to3.py
# STRTYPE = basestring if PY2 else str
# 
# Path: src/cloudant/error.py
# class ResultException(CloudantException):
#     """
#     Provides a way to issue Cloudant Python client library result specific
#     exceptions.
# 
#     :param int code: A code value used to identify the result exception.
#         Defaults to 100.
#     :param args: A list of arguments used to format the exception message.
#     """
# 
#     def __init__(self, code=100, *args):
#         try:
#             msg = RESULT[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = RESULT[code]
#         super(ResultException, self).__init__(msg, code)
# 
# Path: src/cloudant/_common_util.py
# def py_to_couch_validate(key, val):
#     """
#     Validates the individual parameter key and value.
#     """
#     if key not in RESULT_ARG_TYPES:
#         raise CloudantArgumentError(116, key)
#     # pylint: disable=unidiomatic-typecheck
#     # 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 type_or_none(typerefs, value):
#     """
#     Provides a helper function to check that a value is of the types passed or
#     None.
#     """
#     return isinstance(value, typerefs) or value is None


from collections import deque
from functools import partial
from ._2to3 import STRTYPE
from .error import ResultException
from ._common_util import py_to_couch_validate, type_or_none

        A slice argument that contains ``str``, ``list``, or
        :class:`~cloudant.result.ResultByKey` will be interpreted as a
        ``startkey: endkey`` style pair.  For example ``['bar': 'foo']`` means
        get the range of records where the keys are between and including
        'bar' and 'foo'.

        See :class:`~cloudant.result.Result` for more detailed key access and
        slicing examples.

        :param arg:  A single value representing a key or a pair of values
            representing a slice.  The argument value(s) can be ``int``,
            ``str``, ``list`` (in the case of complex keys), or
            :class:`~cloudant.result.ResultByKey`.

        :returns: Rows data as a list in JSON format
        """
        data = None
        if isinstance(arg, int):
            data = self._handle_result_by_index(arg)
        elif isinstance(arg, (STRTYPE, list)):
            data = self._handle_result_by_key(arg)
        elif isinstance(arg, ResultByKey):
            data = self._handle_result_by_key(arg())
        elif isinstance(arg, slice):
            # slice is entire result set - no additional processing required
            if arg.start is None and arg.stop is None:
                data = self._ref(**self.options)
            # key slice identified
            elif (type_or_none((STRTYPE, list, ResultByKey), arg.start) and

# Path: src/cloudant/_2to3.py
# STRTYPE = basestring if PY2 else str
# 
# Path: src/cloudant/error.py
# class ResultException(CloudantException):
#     """
#     Provides a way to issue Cloudant Python client library result specific
#     exceptions.
# 
#     :param int code: A code value used to identify the result exception.
#         Defaults to 100.
#     :param args: A list of arguments used to format the exception message.
#     """
# 
#     def __init__(self, code=100, *args):
#         try:
#             msg = RESULT[code].format(*args)
#         except (KeyError, IndexError):
#             code = 100
#             msg = RESULT[code]
#         super(ResultException, self).__init__(msg, code)
# 
# Path: src/cloudant/_common_util.py
# def py_to_couch_validate(key, val):
#     """
#     Validates the individual parameter key and value.
#     """
#     if key not in RESULT_ARG_TYPES:
#         raise CloudantArgumentError(116, key)
#     # pylint: disable=unidiomatic-typecheck
#     # 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 type_or_none(typerefs, value):
#     """
#     Provides a helper function to check that a value is of the types passed or
#     None.
#     """
#     return isinstance(value, typerefs) or value is None


# Path: src/cloudant/result.py
from collections import deque
from functools import partial
from ._2to3 import STRTYPE
from .error import ResultException
from ._common_util import py_to_couch_validate, type_or_none


        A slice argument that contains ``str``, ``list``, or
        :class:`~cloudant.result.ResultByKey` will be interpreted as a
        ``startkey: endkey`` style pair.  For example ``['bar': 'foo']`` means
        get the range of records where the keys are between and including
        'bar' and 'foo'.

        See :class:`~cloudant.result.Result` for more detailed key access and
        slicing examples.

        :param arg:  A single value representing a key or a pair of values
            representing a slice.  The argument value(s) can be ``int``,
            ``str``, ``list`` (in the case of complex keys), or
            :class:`~cloudant.result.ResultByKey`.

        :returns: Rows data as a list in JSON format
        """
        data = None
        if isinstance(arg, int):
            data = self._handle_result_by_index(arg)
        elif isinstance(arg, (STRTYPE, list)):
            data = self._handle_result_by_key(arg)
        elif isinstance(arg, ResultByKey):
            data = self._handle_result_by_key(arg())
        elif isinstance(arg, slice):
            # slice is entire result set - no additional processing required
            if arg.start is None and arg.stop is None:
                data = self._ref(**self.options)
            # key slice identified
            elif (type_or_none((STRTYPE, list, ResultByKey), arg.start) and

                  type_or_none((STRTYPE, list, ResultByKey), arg.stop)):