Skip to content

Commit f55355f

Browse files
author
Jon Wayne Parrott
committed
Update to latest google-cloud-python
1 parent 6229a69 commit f55355f

File tree

21 files changed

+140
-68
lines changed

21 files changed

+140
-68
lines changed

2-structured-data/bookshelf/model_datastore.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ def from_datastore(entity):
5151
# [START list]
5252
def list(limit=10, cursor=None):
5353
ds = get_client()
54+
5455
query = ds.query(kind='Book', order=['title'])
55-
it = query.fetch(limit=limit, start_cursor=cursor)
56-
entities, more_results, cursor = it.next_page()
57-
entities = builtin_list(map(from_datastore, entities))
58-
return entities, cursor.decode('utf-8') if len(entities) == limit else None
56+
query_iterator = query.fetch(limit=limit, start_cursor=cursor)
57+
page = next(query_iterator.pages)
58+
59+
entities = builtin_list(map(from_datastore, page))
60+
next_cursor = (
61+
query_iterator.next_page_token.decode('utf-8')
62+
if query_iterator.next_page_token else None)
63+
64+
return entities, next_cursor
5965
# [END list]
6066

6167

2-structured-data/requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tox==2.4.1
2-
flake8==3.1.0
2+
flake8==3.2.0
33
flaky==3.3.0
44
pytest==3.0.4
55
pytest-cov==2.4.0

2-structured-data/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Flask==0.11.1
2-
google-cloud==0.20.0
2+
google-cloud==0.21.0
33
gunicorn==19.6.0
44
oauth2client==4.0.0
55
Flask-SQLAlchemy==2.1

3-binary-data/bookshelf/model_datastore.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ def from_datastore(entity):
4848

4949
def list(limit=10, cursor=None):
5050
ds = get_client()
51+
5152
query = ds.query(kind='Book', order=['title'])
52-
it = query.fetch(limit=limit, start_cursor=cursor)
53-
entities, more_results, cursor = it.next_page()
54-
entities = builtin_list(map(from_datastore, entities))
55-
return entities, cursor.decode('utf-8') if len(entities) == limit else None
53+
query_iterator = query.fetch(limit=limit, start_cursor=cursor)
54+
page = next(query_iterator.pages)
55+
56+
entities = builtin_list(map(from_datastore, page))
57+
next_cursor = (
58+
query_iterator.next_page_token.decode('utf-8')
59+
if query_iterator.next_page_token else None)
60+
61+
return entities, next_cursor
5662

5763

5864
def read(id):

3-binary-data/requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tox==2.4.1
2-
flake8==3.1.0
2+
flake8==3.2.0
33
flaky==3.3.0
44
pytest==3.0.4
55
pytest-cov==2.4.0

3-binary-data/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Flask==0.11.1
2-
google-cloud==0.20.0
2+
google-cloud==0.21.0
33
gunicorn==19.6.0
44
oauth2client==4.0.0
55
Flask-SQLAlchemy==2.1

4-auth/bookshelf/model_datastore.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ def from_datastore(entity):
4848

4949
def list(limit=10, cursor=None):
5050
ds = get_client()
51+
5152
query = ds.query(kind='Book', order=['title'])
52-
it = query.fetch(limit=limit, start_cursor=cursor)
53-
entities, more_results, cursor = it.next_page()
54-
entities = builtin_list(map(from_datastore, entities))
55-
return entities, cursor.decode('utf-8') if len(entities) == limit else None
53+
query_iterator = query.fetch(limit=limit, start_cursor=cursor)
54+
page = next(query_iterator.pages)
55+
56+
entities = builtin_list(map(from_datastore, page))
57+
next_cursor = (
58+
query_iterator.next_page_token.decode('utf-8')
59+
if query_iterator.next_page_token else None)
60+
61+
return entities, next_cursor
5662

5763

5864
# [START list_by_user]
@@ -64,10 +70,16 @@ def list_by_user(user_id, limit=10, cursor=None):
6470
('createdById', '=', user_id)
6571
]
6672
)
67-
it = query.fetch(limit=limit, start_cursor=cursor)
68-
entities, more_results, cursor = it.next_page()
69-
entities = builtin_list(map(from_datastore, entities))
70-
return entities, cursor.decode('utf-8') if len(entities) == limit else None
73+
74+
query_iterator = query.fetch(limit=limit, start_cursor=cursor)
75+
page = next(query_iterator.pages)
76+
77+
entities = builtin_list(map(from_datastore, page))
78+
next_cursor = (
79+
query_iterator.next_page_token.decode('utf-8')
80+
if query_iterator.next_page_token else None)
81+
82+
return entities, next_cursor
7183
# [END list_by_user]
7284

7385

4-auth/requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tox==2.4.1
2-
flake8==3.1.0
2+
flake8==3.2.0
33
flaky==3.3.0
44
pytest==3.0.4
55
pytest-cov==2.4.0

4-auth/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Flask==0.11.1
2-
google-cloud==0.20.0
2+
google-cloud==0.21.0
33
gunicorn==19.6.0
44
oauth2client==4.0.0
55
Flask-SQLAlchemy==2.1

5-logging/bookshelf/model_datastore.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ def from_datastore(entity):
4848

4949
def list(limit=10, cursor=None):
5050
ds = get_client()
51+
5152
query = ds.query(kind='Book', order=['title'])
52-
it = query.fetch(limit=limit, start_cursor=cursor)
53-
entities, more_results, cursor = it.next_page()
54-
entities = builtin_list(map(from_datastore, entities))
55-
return entities, cursor.decode('utf-8') if len(entities) == limit else None
53+
query_iterator = query.fetch(limit=limit, start_cursor=cursor)
54+
page = next(query_iterator.pages)
55+
56+
entities = builtin_list(map(from_datastore, page))
57+
next_cursor = (
58+
query_iterator.next_page_token.decode('utf-8')
59+
if query_iterator.next_page_token else None)
60+
61+
return entities, next_cursor
5662

5763

5864
def list_by_user(user_id, limit=10, cursor=None):
@@ -63,10 +69,16 @@ def list_by_user(user_id, limit=10, cursor=None):
6369
('createdById', '=', user_id)
6470
]
6571
)
66-
it = query.fetch(limit=limit, start_cursor=cursor)
67-
entities, more_results, cursor = it.next_page()
68-
entities = builtin_list(map(from_datastore, entities))
69-
return entities, cursor.decode('utf-8') if len(entities) == limit else None
72+
73+
query_iterator = query.fetch(limit=limit, start_cursor=cursor)
74+
page = next(query_iterator.pages)
75+
76+
entities = builtin_list(map(from_datastore, page))
77+
next_cursor = (
78+
query_iterator.next_page_token.decode('utf-8')
79+
if query_iterator.next_page_token else None)
80+
81+
return entities, next_cursor
7082

7183

7284
def read(id):

0 commit comments

Comments
 (0)