Skip to content

Commit

Permalink
Merge pull request #1180 from jonparrott/master
Browse files Browse the repository at this point in the history
Switching datastore cursors to URLsafe base64 encoding.
  • Loading branch information
tseaver committed Oct 14, 2015
2 parents 60799e8 + d5375cf commit c148adf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions gcloud/datastore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ def next_page(self):

start_cursor = self._start_cursor
if start_cursor is not None:
pb.start_cursor = base64.b64decode(start_cursor)
pb.start_cursor = base64.urlsafe_b64decode(start_cursor)

end_cursor = self._end_cursor
if end_cursor is not None:
pb.end_cursor = base64.b64decode(end_cursor)
pb.end_cursor = base64.urlsafe_b64decode(end_cursor)

if self._limit is not None:
pb.limit = self._limit
Expand Down Expand Up @@ -421,7 +421,7 @@ def next_page(self):
if cursor_as_bytes == b'':
self._start_cursor = None
else:
self._start_cursor = base64.b64encode(cursor_as_bytes)
self._start_cursor = base64.urlsafe_b64encode(cursor_as_bytes)
self._end_cursor = None

if more_results_enum == self._NOT_FINISHED:
Expand Down
12 changes: 6 additions & 6 deletions gcloud/datastore/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ def test_next_page_no_cursors_no_more_w_offset_and_limit(self):
self.assertEqual(connection._called_with, [EXPECTED])

def test_next_page_w_cursors_w_more(self):
from base64 import b64decode
from base64 import b64encode
from base64 import urlsafe_b64decode
from base64 import urlsafe_b64encode
from gcloud.datastore.query import _pb_from_query
connection = _Connection()
client = self._makeClient(connection)
Expand All @@ -428,19 +428,19 @@ def test_next_page_w_cursors_w_more(self):
iterator._end_cursor = self._END
entities, more_results, cursor = iterator.next_page()

self.assertEqual(cursor, b64encode(self._END))
self.assertEqual(cursor, urlsafe_b64encode(self._END))
self.assertTrue(more_results)
self.assertTrue(iterator._more_results)
self.assertEqual(iterator._end_cursor, None)
self.assertEqual(b64decode(iterator._start_cursor), self._END)
self.assertEqual(urlsafe_b64decode(iterator._start_cursor), self._END)
self.assertEqual(len(entities), 1)
self.assertEqual(entities[0].key.path,
[{'kind': self._KIND, 'id': self._ID}])
self.assertEqual(entities[0]['foo'], u'Foo')
qpb = _pb_from_query(query)
qpb.offset = 0
qpb.start_cursor = b64decode(self._START)
qpb.end_cursor = b64decode(self._END)
qpb.start_cursor = urlsafe_b64decode(self._START)
qpb.end_cursor = urlsafe_b64decode(self._END)
EXPECTED = {
'dataset_id': self._DATASET,
'query_pb': qpb,
Expand Down

0 comments on commit c148adf

Please sign in to comment.