# 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
    def __iter__(self):
        return self

    def __len__(self):
        if hasattr(self, 'count'):
            return self.count
        elif self.values is not None:
            return len(self.values)
        else:
            return 0

    def __next__(self):
        return self.next()


class ZendeskResultGenerator(BaseResultGenerator):
    """ Generic result generator. """
    def __init__(self,
                 response_handler,
                 response_json,
                 response_objects=None,
                 object_type=None):
        super(ZendeskResultGenerator, self).__init__(response_handler,
                                                     response_json)
        self.object_type = object_type or self.response_handler.api.object_type
        self.values = response_objects or None

    def process_page(self):
        response_objects = self.response_handler.deserialize(
            self._response_json)

# 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

    def __iter__(self):
        return self

    def __len__(self):
        if hasattr(self, 'count'):
            return self.count
        elif self.values is not None:
            return len(self.values)
        else:
            return 0

    def __next__(self):
        return self.next()


class ZendeskResultGenerator(BaseResultGenerator):
    """ Generic result generator. """
    def __init__(self,
                 response_handler,
                 response_json,
                 response_objects=None,
                 object_type=None):
        super(ZendeskResultGenerator, self).__init__(response_handler,
                                                     response_json)
        self.object_type = object_type or self.response_handler.api.object_type
        self.values = response_objects or None

    def process_page(self):
        response_objects = self.response_handler.deserialize(
            self._response_json)

        return response_objects[as_plural(self.object_type)]