<commit_before>from itertools import chain
import requests

_HEADERS = {'Accept': 'application/json'}

class ScopusResponse(object):

    def __init__(self, data):
        self._data = data

    def __getitem__(self, key):
        return self._data['search-results'][key]

    def __iter__(self):
        resp = self
        while resp:
            yield resp
            resp = resp.next()

    def entries(self):
        return [] if self.is_empty() else self['entry']

    def is_empty(self):
        return int(self['opensearch:totalResults']) == 0

    def next_page_url(self):
        try: return next(l['@href'] for l in self['link'] if l['@ref']=='next')
        except: return None

    def next(self):
        url = self.next_page_url()
        if not url: return None
        return ScopusResponse(requests.get(url, headers=_HEADERS).json())

    def all_entries(self):<commit_msg>comply with python iterator specifications<commit_after>from itertools import chain
import requests

_HEADERS = {'Accept': 'application/json'}

class ScopusResponse(object):

    def __init__(self, data):
        self._data = data

    def __getitem__(self, key):
        return self._data['search-results'][key]

    def __iter__(self):
        while True:
            yield self
            self = self.next()

    def entries(self):
        return [] if self.is_empty() else self['entry']

    def is_empty(self):
        return int(self['opensearch:totalResults']) == 0

    def next_page_url(self):
        try: return next(l['@href'] for l in self['link'] if l['@ref']=='next')
        except: return None

    def next(self):
        url = self.next_page_url()
        if not url: raise StopIteration
        return ScopusResponse(requests.get(url, headers=_HEADERS).json())

    def all_entries(self):
{'fraction_non_alphanumeric': 0.12382009994447529, 'fraction_numerical': 0.001110494169905608, 'mean_word_length': 2.80168776371308, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2793748', 'n_tokens_mistral': 546, 'n_tokens_neox': 526, 'n_words': 143}