From 38a2ed6f62adcdcb2eba94f6133d4dd976a53af1 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 22 Jan 2015 14:04:25 +0000 Subject: [PATCH] Python 3 fixes for cursor pagination --- rest_framework/pagination.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 0c5abccb7..cf1f1afa1 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -389,7 +389,8 @@ Cursor = namedtuple('Cursor', ['offset', 'reverse', 'position']) def decode_cursor(encoded): try: - tokens = urlparse.parse_qs(b64decode(encoded).decode('ascii'), keep_blank_values=True) + querystring = b64decode(encoded.encode('ascii')).decode('ascii') + tokens = urlparse.parse_qs(querystring, keep_blank_values=True) offset = int(tokens['offset'][0]) reverse = bool(int(tokens['reverse'][0])) position = tokens['position'][0] @@ -405,7 +406,8 @@ def encode_cursor(cursor): 'reverse': '1' if cursor.reverse else '0', 'position': cursor.position } - return b64encode(urlparse.urlencode(tokens, doseq=True).encode('ascii')) + querystring = urlparse.urlencode(tokens, doseq=True) + return b64encode(querystring.encode('ascii')).decode('ascii') class CursorPagination(BasePagination):