1010from google .protobuf .json_format import MessageToDict
1111from google .cloud .firestore_v1 ._helpers import GeoPoint
1212from google .api_core .datetime_helpers import DatetimeWithNanoseconds
13+ from google_crc32c import value
1314
1415
1516def _from_datastore (data ):
@@ -36,8 +37,6 @@ def _from_datastore(data):
3637 else :
3738 data_to_restructure [key ] = {}
3839
39- data_to_restructure [key ] = dic
40-
4140 elif isinstance (val .get ('arrayValue' ), dict ):
4241 arr = []
4342
@@ -72,32 +71,33 @@ def _decode_datastore(value):
7271 :raises TypeError: For value types that are unsupported.
7372 """
7473
75- if value . get ( 'nullValue' , False ) is None :
74+ if 'nullValue' in value :
7675 return value ['nullValue' ]
7776
78- elif value . get ( 'booleanValue' ) is not None :
77+ elif 'booleanValue' in value :
7978 return bool (value ['booleanValue' ])
8079
81- elif value . get ( 'bytesValue' ) :
80+ elif 'bytesValue' in value :
8281 return b64decode (value ['bytesValue' ].encode ('utf-8' ))
8382
84- elif value . get ( 'integerValue' ) :
83+ elif 'integerValue' in value :
8584 return int (value ['integerValue' ])
8685
87- elif value . get ( 'doubleValue' ) :
86+ elif 'doubleValue' in value :
8887 return float (value ['doubleValue' ])
8988
90- elif isinstance ( value . get ( 'stringValue' ), str ) and value . get ( 'stringValue' ) is not None :
91- return str ( value ['stringValue' ])
89+ elif 'stringValue' in value and isinstance ( value [ 'stringValue' ], str ) :
90+ return value ['stringValue' ]
9291
93- elif value . get ( 'mapValue' ) :
92+ elif 'mapValue' in value :
9493 return _from_datastore (value ['mapValue' ])
9594
96- elif value . get ( 'timestampValue' ) :
95+ elif 'timestampValue' in value :
9796 return DatetimeWithNanoseconds .from_rfc3339 (value ['timestampValue' ])
9897
99- elif value .get ('geoPointValue' ):
100- return GeoPoint (float (value ['timestampValue' ]['latitude' ]), float (value ['timestampValue' ]['longitude' ]))
98+ elif 'geoPointValue' in value :
99+ geo = value ['geoPointValue' ]
100+ return GeoPoint (float (geo ['latitude' ]), float (geo ['longitude' ]))
101101
102102 else :
103103 raise TypeError ("Cannot convert to a Python Value" , value , "Invalid type" , type (value ))
0 commit comments