@@ -72,8 +72,8 @@ def _get_protobuf_attribute_and_value(val):
7272 return name + '_value' , value
7373
7474
75- def _get_value_from_protobuf ( pb ):
76- """Given a protobuf for a Property , get the correct value.
75+ def _get_value_from_value_pb ( value_pb ):
76+ """Given a protobuf for a Value , get the correct value.
7777
7878 The Cloud Datastore Protobuf API returns a Property Protobuf
7979 which has one value set and the rest blank.
@@ -82,38 +82,59 @@ def _get_value_from_protobuf(pb):
8282 Some work is done to coerce the return value into a more useful type
8383 (particularly in the case of a timestamp value, or a key value).
8484
85- :type pb : :class:`gcloud.datastore.datastore_v1_pb2.Property `
86- :param pb : The Property Protobuf.
85+ :type value_pb : :class:`gcloud.datastore.datastore_v1_pb2.Value `
86+ :param value_pb : The Value Protobuf.
8787
8888 :returns: The value provided by the Protobuf.
8989 """
9090
91- if pb .value .HasField ('timestamp_microseconds_value' ):
92- microseconds = pb .value .timestamp_microseconds_value
91+ result = None
92+ if value_pb .HasField ('timestamp_microseconds_value' ):
93+ microseconds = value_pb .timestamp_microseconds_value
9394 naive = (datetime .utcfromtimestamp (0 ) +
9495 timedelta (microseconds = microseconds ))
95- return naive .replace (tzinfo = pytz .utc )
96+ result = naive .replace (tzinfo = pytz .utc )
9697
97- elif pb . value .HasField ('key_value' ):
98- return Key .from_protobuf (pb . value .key_value )
98+ elif value_pb .HasField ('key_value' ):
99+ result = Key .from_protobuf (value_pb .key_value )
99100
100- elif pb . value .HasField ('boolean_value' ):
101- return pb . value .boolean_value
101+ elif value_pb .HasField ('boolean_value' ):
102+ result = value_pb .boolean_value
102103
103- elif pb . value .HasField ('double_value' ):
104- return pb . value .double_value
104+ elif value_pb .HasField ('double_value' ):
105+ result = value_pb .double_value
105106
106- elif pb . value .HasField ('integer_value' ):
107- return pb . value .integer_value
107+ elif value_pb .HasField ('integer_value' ):
108+ result = value_pb .integer_value
108109
109- elif pb . value .HasField ('string_value' ):
110- return pb . value .string_value
110+ elif value_pb .HasField ('string_value' ):
111+ result = value_pb .string_value
111112
112- elif pb . value .HasField ('entity_value' ):
113- return Entity .from_protobuf (pb . value .entity_value )
113+ elif value_pb .HasField ('entity_value' ):
114+ result = Entity .from_protobuf (value_pb .entity_value )
114115
115- else :
116- return None
116+ elif value_pb .list_value :
117+ result = [_get_value_from_value_pb (x ) for x in value_pb .list_value ]
118+
119+ return result
120+
121+
122+ def _get_value_from_property_pb (property_pb ):
123+ """Given a protobuf for a Property, get the correct value.
124+
125+ The Cloud Datastore Protobuf API returns a Property Protobuf
126+ which has one value set and the rest blank.
127+ This function retrieves the the one value provided.
128+
129+ Some work is done to coerce the return value into a more useful type
130+ (particularly in the case of a timestamp value, or a key value).
131+
132+ :type property_pb: :class:`gcloud.datastore.datastore_v1_pb2.Property`
133+ :param property_pb: The Property Protobuf.
134+
135+ :returns: The value provided by the Protobuf.
136+ """
137+ return _get_value_from_value_pb (property_pb .value )
117138
118139
119140def _set_protobuf_value (value_pb , val ):
0 commit comments