Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0803416

Browse filesBrowse files
kryzthovSimon Zeltser
authored andcommitted
Update Endpoints gRPC bookstore example (GoogleCloudPlatform#1500)
- Now works with Python2 and Python3 - Updated ProtoBuf/gRPC generated code Signed-off-by: Christophe Taton <christophe.taton@gmail.com>
1 parent 96c9dcb commit 0803416
Copy full SHA for 0803416

File tree

Expand file treeCollapse file tree

8 files changed

+296
-377
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+296
-377
lines changed

‎endpoints/bookstore-grpc/README.md

Copy file name to clipboardExpand all lines: endpoints/bookstore-grpc/README.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ gRPC libraries and tools are installed, run:
5555
--include_imports \
5656
--include_source_info \
5757
--proto_path=. \
58-
--python_out=generated_pb2 \
59-
--grpc_python_out=generated_pb2 \
58+
--python_out=. \
59+
--grpc_python_out=. \
6060
--descriptor_set_out=api_descriptor.pb \
6161
bookstore.proto
6262

‎endpoints/bookstore-grpc/bookstore.py

Copy file name to clipboardExpand all lines: endpoints/bookstore-grpc/bookstore.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import threading
1616

17+
import six
18+
1719

1820
class ShelfInfo(object):
1921
"""The contents of a single shelf."""
@@ -33,7 +35,7 @@ def __init__(self):
3335

3436
def list_shelf(self):
3537
with self._lock:
36-
return [s._shelf for (_, s) in self._shelves.iteritems()]
38+
return [s._shelf for (_, s) in six.iteritems(self._shelves)]
3739

3840
def create_shelf(self, shelf):
3941
with self._lock:
@@ -54,7 +56,7 @@ def delete_shelf(self, shelf_id):
5456
def list_books(self, shelf_id):
5557
with self._lock:
5658
return [book for (
57-
_, book) in self._shelves[shelf_id]._books.iteritems()]
59+
_, book) in six.iteritems(self._shelves[shelf_id]._books)]
5860

5961
def create_book(self, shelf_id, book):
6062
with self._lock:

‎endpoints/bookstore-grpc/bookstore_client.py

Copy file name to clipboardExpand all lines: endpoints/bookstore-grpc/bookstore_client.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717
import argparse
1818

1919
from google.protobuf import empty_pb2
20-
2120
import grpc
2221

23-
from generated_pb2 import bookstore_pb2
22+
import bookstore_pb2_grpc
2423

2524

2625
def run(host, port, api_key, auth_token, timeout):
2726
"""Makes a basic ListShelves call against a gRPC Bookstore server."""
2827

2928
channel = grpc.insecure_channel('{}:{}'.format(host, port))
3029

31-
stub = bookstore_pb2.BookstoreStub(channel)
30+
stub = bookstore_pb2_grpc.BookstoreStub(channel)
3231
metadata = []
3332
if api_key:
3433
metadata.append(('x-api-key', api_key))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.