# Path: pyston/exception.py
# class RestException(Exception):
#     message = None
# 
#     def __init__(self, message=None):
#         super().__init__()
#         self.message = message or self.message
# 
#     @property
#     def errors(self):
#         return {'error': self.message}
# 
# Path: pyston/paginator.py
# class BasePaginator:
# 
#     def get_response(self, qs, request):
#         raise NotImplementedError
# 
# Path: pyston/response.py
# class HeadersResponse:
# 
#     fieldset = True
# 
#     def __init__(self, result, http_headers=None, code=200):
#         http_headers = {} if http_headers is None else http_headers
#         self.result = result
#         self.http_headers = http_headers
#         self.status_code = code


import base64
import json
from django.utils.translation import ugettext
from pyston.exception import RestException
from pyston.paginator import BasePaginator
from pyston.response import HeadersResponse
        if cursor is not None:
            qs = qs.set_last_evaluated_key(cursor)
        qs = qs.set_limit(base)

        return HeadersResponse(
            qs, self.get_headers(self.get_next_cursor(qs))
        )

    def _get_base(self, request):
        base = request._rest_context.get('base')
        if not base:
            return self.default_base
        elif base.isdigit():
            base_int = int(base)
            if base_int > self.max_base:
                raise RestException(ugettext('Base must lower or equal to {}').format(self.max_base))
            else:
                return base_int
        else:
            raise RestException(ugettext('Base must be natural number or empty'))

    def _get_cursor(self, request):
        cursor = request._rest_context.get('cursor')
        if cursor:
            try:
                cursor = base64.b64decode(
                    cursor.encode('ascii')
                ).decode('ascii')
                return json.loads(cursor)
            except json.JSONDecodeError:

# Path: pyston/exception.py
# class RestException(Exception):
#     message = None
# 
#     def __init__(self, message=None):
#         super().__init__()
#         self.message = message or self.message
# 
#     @property
#     def errors(self):
#         return {'error': self.message}
# 
# Path: pyston/paginator.py
# class BasePaginator:
# 
#     def get_response(self, qs, request):
#         raise NotImplementedError
# 
# Path: pyston/response.py
# class HeadersResponse:
# 
#     fieldset = True
# 
#     def __init__(self, result, http_headers=None, code=200):
#         http_headers = {} if http_headers is None else http_headers
#         self.result = result
#         self.http_headers = http_headers
#         self.status_code = code


# Path: pyston/contrib/dynamo/paginator.py
import base64
import json
from django.utils.translation import ugettext
from pyston.exception import RestException
from pyston.paginator import BasePaginator
from pyston.response import HeadersResponse

        if cursor is not None:
            qs = qs.set_last_evaluated_key(cursor)
        qs = qs.set_limit(base)

        return HeadersResponse(
            qs, self.get_headers(self.get_next_cursor(qs))
        )

    def _get_base(self, request):
        base = request._rest_context.get('base')
        if not base:
            return self.default_base
        elif base.isdigit():
            base_int = int(base)
            if base_int > self.max_base:
                raise RestException(ugettext('Base must lower or equal to {}').format(self.max_base))
            else:
                return base_int
        else:
            raise RestException(ugettext('Base must be natural number or empty'))

    def _get_cursor(self, request):
        cursor = request._rest_context.get('cursor')
        if cursor:
            try:
                cursor = base64.b64decode(
                    cursor.encode('ascii')
                ).decode('ascii')
                return json.loads(cursor)
            except json.JSONDecodeError:

                raise RestException(ugettext('Invalid next cursor value'))