<commit_before>import json
from twilio.exceptions import TwilioException


class Page(object):
    META_KEYS = {
        'end',
        'first_page_uri',
        'next_page_uri',
        'last_page_uri',
        'page',
        'page_size',
        'previous_page_uri',
        'total',
        'num_pages',
        'start',
        'uri'
    }

    def __init__(self, version, response):
        payload = self.process_response(response)

        self._version = version
        self._payload = payload
        self._solution = {}
        self._records = iter(self.load_page(payload))

    def __iter__(self):
        return self

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

    def next(self):
        return self.get_instance(next(self._records))

    @classmethod
    def process_response(self, response):
        if response.status_code != 200:
            raise TwilioException('Unable to fetch page', response)

        return json.loads(response.content)

    def load_page(self, payload):
        if 'meta' in payload and 'key' in payload['meta']:
            return payload[payload['meta']['key']]
        else:
            keys = set(payload.keys())
            key = keys - self.META_KEYS
            if len(key) == 1:
                return payload[key.pop()]

        raise TwilioException('Page Records can not be deserialized')

    @property
    def previous_page_url(self):
        if 'meta' in self._payload and 'previous_page_url' in self._payload['meta']:
            return self._payload['meta']['previous_page_url']
        elif 'previous_page_uri' in self._payload:
            return self._version.domain.absolute_url(self._payload['previous_page_uri'])

        return None

    @property
    def next_page_url(self):
        if 'meta' in self._payload and 'next_page_url' in self._payload['meta']:
            return self._payload['meta']['next_page_url']
        elif 'next_page_uri' in self._payload and self._payload['next_page_uri']:
            return self._version.domain.absolute_url(self._payload['next_page_uri'])

        return None

    def get_instance(self, payload):
        raise TwilioException('Page.get_instance() must be implemented in the derived class')

    def next_page(self):
        if not self.next_page_url:
            return None<commit_msg>Check for null previous_page_uri<commit_after>import json
from twilio.exceptions import TwilioException


class Page(object):
    META_KEYS = {
        'end',
        'first_page_uri',
        'next_page_uri',
        'last_page_uri',
        'page',
        'page_size',
        'previous_page_uri',
        'total',
        'num_pages',
        'start',
        'uri'
    }

    def __init__(self, version, response):
        payload = self.process_response(response)

        self._version = version
        self._payload = payload
        self._solution = {}
        self._records = iter(self.load_page(payload))

    def __iter__(self):
        return self

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

    def next(self):
        return self.get_instance(next(self._records))

    @classmethod
    def process_response(self, response):
        if response.status_code != 200:
            raise TwilioException('Unable to fetch page', response)

        return json.loads(response.content)

    def load_page(self, payload):
        if 'meta' in payload and 'key' in payload['meta']:
            return payload[payload['meta']['key']]
        else:
            keys = set(payload.keys())
            key = keys - self.META_KEYS
            if len(key) == 1:
                return payload[key.pop()]

        raise TwilioException('Page Records can not be deserialized')

    @property
    def previous_page_url(self):
        if 'meta' in self._payload and 'previous_page_url' in self._payload['meta']:
            return self._payload['meta']['previous_page_url']
        elif 'previous_page_uri' in self._payload and self._payload['previous_page_uri']:
            return self._version.domain.absolute_url(self._payload['previous_page_uri'])

        return None

    @property
    def next_page_url(self):
        if 'meta' in self._payload and 'next_page_url' in self._payload['meta']:
            return self._payload['meta']['next_page_url']
        elif 'next_page_uri' in self._payload and self._payload['next_page_uri']:
            return self._version.domain.absolute_url(self._payload['next_page_uri'])

        return None

    def get_instance(self, payload):
        raise TwilioException('Page.get_instance() must be implemented in the derived class')

    def next_page(self):
        if not self.next_page_url:
            return None
{'fraction_non_alphanumeric': 0.10637842465753425, 'fraction_numerical': 0.0017123287671232876, 'mean_word_length': 2.458919319022946, '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': '2432095', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1312, 'n_words': 312}