# Path: zenpy/lib/util.py
# def as_plural(result_key):
#     """
#     Given a result key, return in the plural form.
#     """
#     # Not at all guaranteed to work in all cases...
#     if result_key.endswith('y'):
#         return re.sub("y$", "ies", result_key)
#     elif result_key.endswith('address'):
#         return result_key + 'es'
#     elif result_key.endswith('us'):
#         return re.sub("us$", "uses", result_key)
#     elif not result_key.endswith('s'):
#         return result_key + 's'
#     else:
#         return result_key
# 
# Path: zenpy/lib/exception.py
# class SearchResponseLimitExceeded(APIException):
#     """
#     A ``SearchResponseLimitExceeded`` is raised when a search has too many results
# 
#     See https://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits
#     """


import re
import six
import logging
from abc import abstractmethod
from datetime import datetime, timedelta
from zenpy.lib.util import as_plural
from zenpy.lib.exception import SearchResponseLimitExceeded
    from collections.abc import Iterable
    from collections import Iterable
from math import ceil
        end_time = self._response_json.get('end_time', None)
        # If we are calling an incremental API, make sure to honour the restrictions
        if end_time:
            # We can't request updates from an incremental api if the
            # start_time value is less than 5 minutes in the future.
            if (datetime.fromtimestamp(int(end_time)) +
                    timedelta(minutes=5)) > datetime.now():
                raise StopIteration
        # No more pages to request
        if self._response_json.get("end_of_stream") is True:
            raise StopIteration
        return super(ZendeskResultGenerator,
                     self).get_next_page(page_num, page_size)


class SearchResultGenerator(BaseResultGenerator):
    """ Result generator for search queries. """
    def process_page(self):
        search_results = list()
        for object_json in self._response_json['results']:
            object_type = object_json.pop('result_type')
            search_results.append(
                self.response_handler.api._object_mapping.object_from_json(
                    object_type, object_json))
        return search_results

    def get_next_page(self, page_num, page_size):
        try:
            return super(SearchResultGenerator,
                         self).get_next_page(page_num, page_size)

# Path: zenpy/lib/util.py
# def as_plural(result_key):
#     """
#     Given a result key, return in the plural form.
#     """
#     # Not at all guaranteed to work in all cases...
#     if result_key.endswith('y'):
#         return re.sub("y$", "ies", result_key)
#     elif result_key.endswith('address'):
#         return result_key + 'es'
#     elif result_key.endswith('us'):
#         return re.sub("us$", "uses", result_key)
#     elif not result_key.endswith('s'):
#         return result_key + 's'
#     else:
#         return result_key
# 
# Path: zenpy/lib/exception.py
# class SearchResponseLimitExceeded(APIException):
#     """
#     A ``SearchResponseLimitExceeded`` is raised when a search has too many results
# 
#     See https://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits
#     """


# Path: zenpy/lib/generator.py
import re
import six
import logging
from abc import abstractmethod
from datetime import datetime, timedelta
from zenpy.lib.util import as_plural
from zenpy.lib.exception import SearchResponseLimitExceeded
    from collections.abc import Iterable
    from collections import Iterable
from math import ceil

        end_time = self._response_json.get('end_time', None)
        # If we are calling an incremental API, make sure to honour the restrictions
        if end_time:
            # We can't request updates from an incremental api if the
            # start_time value is less than 5 minutes in the future.
            if (datetime.fromtimestamp(int(end_time)) +
                    timedelta(minutes=5)) > datetime.now():
                raise StopIteration
        # No more pages to request
        if self._response_json.get("end_of_stream") is True:
            raise StopIteration
        return super(ZendeskResultGenerator,
                     self).get_next_page(page_num, page_size)


class SearchResultGenerator(BaseResultGenerator):
    """ Result generator for search queries. """
    def process_page(self):
        search_results = list()
        for object_json in self._response_json['results']:
            object_type = object_json.pop('result_type')
            search_results.append(
                self.response_handler.api._object_mapping.object_from_json(
                    object_type, object_json))
        return search_results

    def get_next_page(self, page_num, page_size):
        try:
            return super(SearchResultGenerator,
                         self).get_next_page(page_num, page_size)

        except SearchResponseLimitExceeded: