Skip to content

Commit

Permalink
Add support for 'list_value' field of a Value protobuf.
Browse files Browse the repository at this point in the history
Fixes #223.

Manually lands Tagtoo/gcloud-python@0475d5e, included by mistake in PR #126.
  • Loading branch information
tseaver committed Oct 16, 2014
1 parent 0a2cd13 commit 61e3c2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gcloud/datastore/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def _get_value_from_value_pb(value_pb):
elif value_pb.HasField('entity_value'):
return Entity.from_protobuf(value_pb.entity_value)

elif value_pb.list_value:
return [_get_value_from_value_pb(x) for x in value_pb.list_value]

else:
return None

Expand Down
12 changes: 12 additions & 0 deletions gcloud/datastore/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ def test_entity(self):
self.assertTrue(isinstance(entity, Entity))
self.assertEqual(entity['foo'], 'Foo')

def test_list(self):
from gcloud.datastore.datastore_v1_pb2 import Value

pb = Value()
list_pb = pb.list_value
item_pb = list_pb.add()
item_pb.string_value = 'Foo'
item_pb = list_pb.add()
item_pb.string_value = 'Bar'
items = self._callFUT(pb)
self.assertEqual(items, ['Foo', 'Bar'])

def test_unknown(self):
from gcloud.datastore.datastore_v1_pb2 import Value

Expand Down

0 comments on commit 61e3c2c

Please sign in to comment.