<commit_before>import logger

class Results(object):
    def __init__(self, url, options, model, bridge, cache, is_singleton = False, mode = "list"):
        self.url = url
        self.options = options
        self.model = model
        self.name = "users"
        self.index = -1
        self.loaded = []
        self.bridge = bridge
        self.cache = cache
        self.has_more = True
        self.is_singleton = is_singleton
        self.mode = mode

    def __iter__(self):
        return self

    def next(self):
        if (self.index+1) < len(self.loaded) or (self.has_more and self.__load_next_batch()):
            try:
                self.index += 1
                return self.loaded[self.index]
            except:
                raise StopIteration

    def all(self):
        return list(self)

    def __load_next_batch(self):
        response = self.bridge.next_batch(self.url, self.name, self.options, self.is_singleton, self.mode)
        batch = response['items']
        self.has_more = not self.is_singleton and self.mode == 'list' and response['has_more']
        if self.is_singleton:
          self.loaded = [ self.model.from_raw(batch, self.cache, response['supplemental']) ]
        else:
          self.loaded += [self.model.from_raw(o, self.cache, response['supplemental']) for o in batch ]
        return batch
<commit_msg>Fixed the iterator class by adding the Exception<commit_after>import logger

class Results(object):
    def __init__(self, url, options, model, bridge, cache, is_singleton=False, mode="list"):
        self.url = url
        self.options = options
        self.model = model
        self.name = "users" #todo
        self.index = -1
        self.loaded = []
        self.bridge = bridge
        self.cache = cache
        self.has_more = True
        self.is_singleton = is_singleton
        self.mode = mode

    def __iter__(self):
        return self

    def next(self):
        if (self.index+1) < len(self.loaded) or (self.has_more and self.__load_next_batch()):
            self.index += 1
            next_value = self.loaded[self.index]
            print next_value
            return next_value
        else:
            raise StopIteration


    def all(self):
        return list(self)

    def __load_next_batch(self):
        response = self.bridge.next_batch(self.url, self.name, self.options, self.is_singleton, self.mode)
        batch = response['items']
        print "Batch"
        print batch
        self.has_more = not self.is_singleton and self.mode == 'list' and response['has_more']
        if self.is_singleton:
          self.loaded = [ self.model.from_raw(batch) ]
        else:
          self.loaded += [self.model.from_raw(o) for o in batch ]
        return batch

{'fraction_non_alphanumeric': 0.10486211901306242, 'fraction_numerical': 0.0021770682148040637, 'mean_word_length': 2.0908071748878925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4358319', 'n_tokens_mistral': 821, 'n_tokens_neox': 806, 'n_words': 201}