def __getitem__(self, key):
        if isinstance(key, slice):
            if key.start and key.stop:
                # Translate slice into LIMIT, e.g.
                # [0:2] ->
                #          LIMIT 0, 2
                # [10:15] ->
                #          LIMIT 10, 5
                offset = self._check_limit(key.start)
                end = self._check_limit(key.stop)
                row_count = max(0, end - offset)
                self.base_query['limit'] = [offset, row_count]
            elif key.start:
                self.base_query['limit'] = [self._check_limit(key.start)]
            elif key.stop:
                self.base_query['limit'] = [0, self._check_limit(key.stop)]
            self._build_cursor()
            self._build_record_set()
            return self._record_set
        elif isinstance(key, int):
            if not len(self._record_set):
                # Get all rows!  Better to use a limit with slices.
                self._build_cursor()
                self._build_record_set()
            return self._record_set[key]
        else:
            raise TypeError('Key must be a slice or integer.')
dataset/ETHPy150Open mozilla/addons-server/src/olympia/editors/sql_model.py/RawSQLManager.__getitem__/original