| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,20 +95,20 @@ def _get_meaning(value_pb, is_list=False): | |||
| 95 | 95 | if is_list: | |
| 96 | 96 | # An empty list will have no values, hence no shared meaning | |
| 97 | 97 | # set among them. | |
| 98 | - if len(value_pb.list_value) == 0: | ||
| 98 | + if len(value_pb.array_value.values) == 0: | ||
| 99 | 99 | return None | |
| 100 | 100 | ||
| 101 | 101 | # We check among all the meanings, some of which may be None, | |
| 102 | 102 | # the rest which may be enum/int values. | |
| 103 | 103 | all_meanings = set(_get_meaning(sub_value_pb) | |
| 104 | - for sub_value_pb in value_pb.list_value) | ||
| 104 | + for sub_value_pb in value_pb.array_value.values) | ||
| 105 | 105 | meaning = all_meanings.pop() | |
| 106 | 106 | # The value we popped off should have been unique. If not | |
| 107 | 107 | # then we can't handle a list with values that have more | |
| 108 | 108 | # than one meaning. | |
| 109 | 109 | if all_meanings: | |
| 110 | 110 | raise ValueError('Different meanings set on values ' | |
| 111 | - 'within a list_value') | ||
| 111 | + 'within an array_value') | ||
| 112 | 112 | elif value_pb.meaning: # Simple field (int32) | |
| 113 | 113 | meaning = value_pb.meaning | |
| 114 | 114 | ||
@@ -178,10 +178,11 @@ def entity_from_protobuf(pb): | |||
| 178 | 178 | # in a list agree. | |
| 179 | 179 | if is_list: | |
| 180 | 180 | exclude_values = set(value_pb.exclude_from_indexes | |
| 181 | - for value_pb in value_pb.list_value) | ||
| 181 | + for value_pb in value_pb.array_value.values) | ||
| 182 | 182 | if len(exclude_values) != 1: | |
| 183 | - raise ValueError('For a list_value, subvalues must either all ' | ||
| 184 | - 'be indexed or all excluded from indexes.') | ||
| 183 | + raise ValueError('For an array_value, subvalues must either ' | ||
| 184 | + 'all be indexed or all excluded from ' | ||
| 185 | + 'indexes.') | ||
| 185 | 186 | ||
| 186 | 187 | if exclude_values.pop(): | |
| 187 | 188 | exclude_from_indexes.append(prop_name) | |
@@ -223,7 +224,7 @@ def entity_to_protobuf(entity): | |||
| 223 | 224 | if not value_is_list: | |
| 224 | 225 | value_pb.exclude_from_indexes = True | |
| 225 | 226 | ||
| 226 | - for sub_value in value_pb.list_value: | ||
| 227 | + for sub_value in value_pb.array_value.values: | ||
| 227 | 228 | sub_value.exclude_from_indexes = True | |
| 228 | 229 | ||
| 229 | 230 | # Add meaning information to protobuf. | |
@@ -234,7 +235,7 @@ def entity_to_protobuf(entity): | |||
| 234 | 235 | if orig_value is value: | |
| 235 | 236 | # For lists, we set meaning on each sub-element. | |
| 236 | 237 | if value_is_list: | |
| 237 | - for sub_value_pb in value_pb.list_value: | ||
| 238 | + for sub_value_pb in value_pb.array_value.values: | ||
| 238 | 239 | sub_value_pb.meaning = meaning | |
| 239 | 240 | else: | |
| 240 | 241 | value_pb.meaning = meaning | |
@@ -325,7 +326,7 @@ def _pb_attr_value(val): | |||
| 325 | 326 | elif isinstance(val, Entity): | |
| 326 | 327 | name, value = 'entity', val | |
| 327 | 328 | elif isinstance(val, list): | |
| 328 | - name, value = 'list', val | ||
| 329 | + name, value = 'array', val | ||
| 329 | 330 | else: | |
| 330 | 331 | raise ValueError("Unknown protobuf attr type %s" % type(val)) | |
| 331 | 332 | ||
@@ -374,9 +375,9 @@ def _get_value_from_value_pb(value_pb): | |||
| 374 | 375 | elif value_pb.HasField('entity_value'): # Message field (Entity) | |
| 375 | 376 | result = entity_from_protobuf(value_pb.entity_value) | |
| 376 | 377 | ||
| 377 | - elif value_pb.list_value: | ||
| 378 | + elif value_pb.array_value.values: | ||
| 378 | 379 | result = [_get_value_from_value_pb(value) | |
| 379 | - for value in value_pb.list_value] | ||
| 380 | + for value in value_pb.array_value.values] | ||
| 380 | 381 | ||
| 381 | 382 | return result | |
| 382 | 383 | ||
@@ -408,8 +409,8 @@ def _set_protobuf_value(value_pb, val): | |||
| 408 | 409 | elif attr == 'entity_value': | |
| 409 | 410 | entity_pb = entity_to_protobuf(val) | |
| 410 | 411 | value_pb.entity_value.CopyFrom(entity_pb) | |
| 411 | - elif attr == 'list_value': | ||
| 412 | - l_pb = value_pb.list_value | ||
| 412 | + elif attr == 'array_value': | ||
| 413 | + l_pb = value_pb.array_value.values | ||
| 413 | 414 | for item in val: | |
| 414 | 415 | i_pb = l_pb.add() | |
| 415 | 416 | _set_protobuf_value(i_pb, item) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,18 +80,18 @@ def test_it(self): | |||
| 80 | 80 | unindexed_val_pb.integer_value = 10 | |
| 81 | 81 | unindexed_val_pb.exclude_from_indexes = True | |
| 82 | 82 | ||
| 83 | - list_val_pb1 = _new_value_pb(entity_pb, 'baz') | ||
| 84 | - list_pb1 = list_val_pb1.list_value | ||
| 83 | + array_val_pb1 = _new_value_pb(entity_pb, 'baz') | ||
| 84 | + array_pb1 = array_val_pb1.array_value.values | ||
| 85 | 85 | ||
| 86 | - unindexed_list_val_pb = list_pb1.add() | ||
| 87 | - unindexed_list_val_pb.integer_value = 11 | ||
| 88 | - unindexed_list_val_pb.exclude_from_indexes = True | ||
| 86 | + unindexed_array_val_pb = array_pb1.add() | ||
| 87 | + unindexed_array_val_pb.integer_value = 11 | ||
| 88 | + unindexed_array_val_pb.exclude_from_indexes = True | ||
| 89 | 89 | ||
| 90 | - list_val_pb2 = _new_value_pb(entity_pb, 'qux') | ||
| 91 | - list_pb2 = list_val_pb2.list_value | ||
| 90 | + array_val_pb2 = _new_value_pb(entity_pb, 'qux') | ||
| 91 | + array_pb2 = array_val_pb2.array_value.values | ||
| 92 | 92 | ||
| 93 | - indexed_list_val_pb = list_pb2.add() | ||
| 94 | - indexed_list_val_pb.integer_value = 12 | ||
| 93 | + indexed_array_val_pb = array_pb2.add() | ||
| 94 | + indexed_array_val_pb.integer_value = 12 | ||
| 95 | 95 | ||
| 96 | 96 | entity = self._callFUT(entity_pb) | |
| 97 | 97 | self.assertEqual(entity.kind, _KIND) | |
@@ -119,14 +119,14 @@ def test_mismatched_value_indexed(self): | |||
| 119 | 119 | entity_pb.key.partition_id.project_id = _PROJECT | |
| 120 | 120 | entity_pb.key.path.add(kind=_KIND, id=_ID) | |
| 121 | 121 | ||
| 122 | - list_val_pb = _new_value_pb(entity_pb, 'baz') | ||
| 123 | - list_pb = list_val_pb.list_value | ||
| 122 | + array_val_pb = _new_value_pb(entity_pb, 'baz') | ||
| 123 | + array_pb = array_val_pb.array_value.values | ||
| 124 | 124 | ||
| 125 | - unindexed_value_pb1 = list_pb.add() | ||
| 125 | + unindexed_value_pb1 = array_pb.add() | ||
| 126 | 126 | unindexed_value_pb1.integer_value = 10 | |
| 127 | 127 | unindexed_value_pb1.exclude_from_indexes = True | |
| 128 | 128 | ||
| 129 | - unindexed_value_pb2 = list_pb.add() | ||
| 129 | + unindexed_value_pb2 = array_pb.add() | ||
| 130 | 130 | unindexed_value_pb2.integer_value = 11 | |
| 131 | 131 | ||
| 132 | 132 | with self.assertRaises(ValueError): | |
@@ -305,14 +305,14 @@ def test_inverts_to_protobuf(self): | |||
| 305 | 305 | ||
| 306 | 306 | # Add a list property. | |
| 307 | 307 | val_pb4 = _new_value_pb(original_pb, 'list-quux') | |
| 308 | - list_val1 = val_pb4.list_value.add() | ||
| 309 | - list_val1.exclude_from_indexes = True | ||
| 310 | - list_val1.meaning = meaning = 22 | ||
| 311 | - list_val1.blob_value = b'\xe2\x98\x83' | ||
| 312 | - list_val2 = val_pb4.list_value.add() | ||
| 313 | - list_val2.exclude_from_indexes = True | ||
| 314 | - list_val2.meaning = meaning | ||
| 315 | - list_val2.blob_value = b'\xe2\x98\x85' | ||
| 308 | + array_val1 = val_pb4.array_value.values.add() | ||
| 309 | + array_val1.exclude_from_indexes = False | ||
| 310 | + array_val1.meaning = meaning = 22 | ||
| 311 | + array_val1.blob_value = b'\xe2\x98\x83' | ||
| 312 | + array_val2 = val_pb4.array_value.add() | ||
| 313 | + array_val2.exclude_from_indexes = False | ||
| 314 | + array_val2.meaning = meaning | ||
| 315 | + array_val2.blob_value = b'\xe2\x98\x85' | ||
| 316 | 316 | ||
| 317 | 317 | # Convert to the user-space Entity. | |
| 318 | 318 | entity = entity_from_protobuf(original_pb) | |
@@ -489,10 +489,10 @@ def test_entity(self): | |||
| 489 | 489 | self.assertEqual(name, 'entity_value') | |
| 490 | 490 | self.assertTrue(value is entity) | |
| 491 | 491 | ||
| 492 | - def test_list(self): | ||
| 492 | + def test_array(self): | ||
| 493 | 493 | values = ['a', 0, 3.14] | |
| 494 | 494 | name, value = self._callFUT(values) | |
| 495 | - self.assertEqual(name, 'list_value') | ||
| 495 | + self.assertEqual(name, 'array_value') | ||
| 496 | 496 | self.assertTrue(value is values) | |
| 497 | 497 | ||
| 498 | 498 | def test_object(self): | |
@@ -569,14 +569,14 @@ def test_entity(self): | |||
| 569 | 569 | self.assertTrue(isinstance(entity, Entity)) | |
| 570 | 570 | self.assertEqual(entity['foo'], 'Foo') | |
| 571 | 571 | ||
| 572 | - def test_list(self): | ||
| 572 | + def test_array(self): | ||
| 573 | 573 | from gcloud.datastore._generated import entity_pb2 | |
| 574 | 574 | ||
| 575 | 575 | pb = entity_pb2.Value() | |
| 576 | - list_pb = pb.list_value | ||
| 577 | - item_pb = list_pb.add() | ||
| 576 | + array_pb = pb.array_value.values | ||
| 577 | + item_pb = array_pb.add() | ||
| 578 | 578 | item_pb.string_value = 'Foo' | |
| 579 | - item_pb = list_pb.add() | ||
| 579 | + item_pb = array_pb.add() | ||
| 580 | 580 | item_pb.string_value = 'Bar' | |
| 581 | 581 | items = self._callFUT(pb) | |
| 582 | 582 | self.assertEqual(items, ['Foo', 'Bar']) | |
@@ -717,11 +717,11 @@ def test_entity_w_key(self): | |||
| 717 | 717 | self.assertEqual(list(prop_dict.keys()), [name]) | |
| 718 | 718 | self.assertEqual(prop_dict[name].string_value, value) | |
| 719 | 719 | ||
| 720 | - def test_list(self): | ||
| 720 | + def test_array(self): | ||
| 721 | 721 | pb = self._makePB() | |
| 722 | 722 | values = [u'a', 0, 3.14] | |
| 723 | 723 | self._callFUT(pb, values) | |
| 724 | - marshalled = pb.list_value | ||
| 724 | + marshalled = pb.array_value.values | ||
| 725 | 725 | self.assertEqual(len(marshalled), len(values)) | |
| 726 | 726 | self.assertEqual(marshalled[0].string_value, values[0]) | |
| 727 | 727 | self.assertEqual(marshalled[1].integer_value, values[1]) | |
@@ -830,23 +830,23 @@ def test_single(self): | |||
| 830 | 830 | result = self._callFUT(value_pb) | |
| 831 | 831 | self.assertEqual(meaning, result) | |
| 832 | 832 | ||
| 833 | - def test_empty_list_value(self): | ||
| 833 | + def test_empty_array_value(self): | ||
| 834 | 834 | from gcloud.datastore._generated import entity_pb2 | |
| 835 | 835 | ||
| 836 | 836 | value_pb = entity_pb2.Value() | |
| 837 | - value_pb.list_value.add() | ||
| 838 | - value_pb.list_value.pop() | ||
| 837 | + value_pb.array_value.values.add() | ||
| 838 | + value_pb.array_value.values.pop() | ||
| 839 | 839 | ||
| 840 | 840 | result = self._callFUT(value_pb, is_list=True) | |
| 841 | 841 | self.assertEqual(None, result) | |
| 842 | 842 | ||
| 843 | - def test_list_value(self): | ||
| 843 | + def test_array_value(self): | ||
| 844 | 844 | from gcloud.datastore._generated import entity_pb2 | |
| 845 | 845 | ||
| 846 | 846 | value_pb = entity_pb2.Value() | |
| 847 | 847 | meaning = 9 | |
| 848 | - sub_value_pb1 = value_pb.list_value.add() | ||
| 849 | - sub_value_pb2 = value_pb.list_value.add() | ||
| 848 | + sub_value_pb1 = value_pb.array_value.values.add() | ||
| 849 | + sub_value_pb2 = value_pb.array_value.values.add() | ||
| 850 | 850 | ||
| 851 | 851 | sub_value_pb1.meaning = sub_value_pb2.meaning = meaning | |
| 852 | 852 | sub_value_pb1.string_value = u'hi' | |
@@ -855,14 +855,14 @@ def test_list_value(self): | |||
| 855 | 855 | result = self._callFUT(value_pb, is_list=True) | |
| 856 | 856 | self.assertEqual(meaning, result) | |
| 857 | 857 | ||
| 858 | - def test_list_value_disagreeing(self): | ||
| 858 | + def test_array_value_disagreeing(self): | ||
| 859 | 859 | from gcloud.datastore._generated import entity_pb2 | |
| 860 | 860 | ||
| 861 | 861 | value_pb = entity_pb2.Value() | |
| 862 | 862 | meaning1 = 9 | |
| 863 | 863 | meaning2 = 10 | |
| 864 | - sub_value_pb1 = value_pb.list_value.add() | ||
| 865 | - sub_value_pb2 = value_pb.list_value.add() | ||
| 864 | + sub_value_pb1 = value_pb.array_value.values.add() | ||
| 865 | + sub_value_pb2 = value_pb.array_value.values.add() | ||
| 866 | 866 | ||
| 867 | 867 | sub_value_pb1.meaning = meaning1 | |
| 868 | 868 | sub_value_pb2.meaning = meaning2 | |
@@ -872,13 +872,13 @@ def test_list_value_disagreeing(self): | |||
| 872 | 872 | with self.assertRaises(ValueError): | |
| 873 | 873 | self._callFUT(value_pb, is_list=True) | |
| 874 | 874 | ||
| 875 | - def test_list_value_partially_unset(self): | ||
| 875 | + def test_array_value_partially_unset(self): | ||
| 876 | 876 | from gcloud.datastore._generated import entity_pb2 | |
| 877 | 877 | ||
| 878 | 878 | value_pb = entity_pb2.Value() | |
| 879 | 879 | meaning1 = 9 | |
| 880 | - sub_value_pb1 = value_pb.list_value.add() | ||
| 881 | - sub_value_pb2 = value_pb.list_value.add() | ||
| 880 | + sub_value_pb1 = value_pb.array_value.values.add() | ||
| 881 | + sub_value_pb2 = value_pb.array_value.values.add() | ||
| 882 | 882 | ||
| 883 | 883 | sub_value_pb1.meaning = meaning1 | |
| 884 | 884 | sub_value_pb1.string_value = u'hi' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments