Skip to content

Commit d341b19

Browse files
committed
Replacing datastore pb uses with entity shim.
This is just a superficial rename in preparation for v1beta3.
1 parent f143da2 commit d341b19

File tree

11 files changed

+90
-58
lines changed

11 files changed

+90
-58
lines changed

gcloud/datastore/_entity_pb2.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Datastore shim to emulate v1beta3 module structure.
16+
17+
This module intended to pair with entity.proto.
18+
"""
19+
20+
from gcloud.datastore import _datastore_v1_pb2
21+
22+
23+
PartitionId = _datastore_v1_pb2.PartitionId
24+
Key = _datastore_v1_pb2.Key
25+
Value = _datastore_v1_pb2.Value
26+
Entity = _datastore_v1_pb2.Entity

gcloud/datastore/connection.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from gcloud.environment_vars import GCD_HOST
2121
from gcloud.exceptions import make_exception
2222
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
23+
from gcloud.datastore import _entity_pb2
2324

2425

2526
class Connection(connection.Connection):
@@ -150,8 +151,8 @@ def lookup(self, dataset_id, key_pbs,
150151
Maps the ``DatastoreService.Lookup`` protobuf RPC.
151152
152153
This method deals only with protobufs
153-
(:class:`gcloud.datastore._datastore_v1_pb2.Key` and
154-
:class:`gcloud.datastore._datastore_v1_pb2.Entity`) and is used
154+
(:class:`gcloud.datastore._entity_pb2.Key` and
155+
:class:`gcloud.datastore._entity_pb2.Entity`) and is used
155156
under the hood in :func:`gcloud.datastore.get`:
156157
157158
>>> from gcloud import datastore
@@ -167,7 +168,7 @@ def lookup(self, dataset_id, key_pbs,
167168
:type dataset_id: string
168169
:param dataset_id: The ID of the dataset to look up the keys.
169170
170-
:type key_pbs: list of :class:`gcloud.datastore._datastore_v1_pb2.Key`
171+
:type key_pbs: list of :class:`gcloud.datastore._entity_pb2.Key`
171172
:param key_pbs: The keys to retrieve from the datastore.
172173
173174
:type eventual: boolean
@@ -183,9 +184,9 @@ def lookup(self, dataset_id, key_pbs,
183184
:rtype: tuple
184185
:returns: A triple of (``results``, ``missing``, ``deferred``) where
185186
both ``results`` and ``missing`` are lists of
186-
:class:`gcloud.datastore._datastore_v1_pb2.Entity` and
187+
:class:`gcloud.datastore._entity_pb2.Entity` and
187188
``deferred`` is a list of
188-
:class:`gcloud.datastore._datastore_v1_pb2.Key`.
189+
:class:`gcloud.datastore._entity_pb2.Key`.
189190
"""
190191
lookup_request = datastore_pb.LookupRequest()
191192
_set_read_options(lookup_request, eventual, transaction_id)
@@ -360,10 +361,10 @@ def allocate_ids(self, dataset_id, key_pbs):
360361
:param dataset_id: The ID of the dataset to which the transaction
361362
belongs.
362363
363-
:type key_pbs: list of :class:`gcloud.datastore._datastore_v1_pb2.Key`
364+
:type key_pbs: list of :class:`gcloud.datastore._entity_pb2.Key`
364365
:param key_pbs: The keys for which the backend should allocate IDs.
365366
366-
:rtype: list of :class:`gcloud.datastore._datastore_v1_pb2.Key`
367+
:rtype: list of :class:`gcloud.datastore._entity_pb2.Key`
367368
:returns: An equal number of keys, with IDs filled in by the backend.
368369
"""
369370
request = datastore_pb.AllocateIdsRequest()
@@ -399,15 +400,15 @@ def _prepare_key_for_request(key_pb): # pragma: NO COVER copied from helpers
399400
This is copied from `helpers` to avoid a cycle:
400401
_implicit_environ -> connection -> helpers -> key -> _implicit_environ
401402
402-
:type key_pb: :class:`gcloud.datastore._datastore_v1_pb2.Key`
403+
:type key_pb: :class:`gcloud.datastore._entity_pb2.Key`
403404
:param key_pb: A key to be added to a request.
404405
405-
:rtype: :class:`gcloud.datastore._datastore_v1_pb2.Key`
406+
:rtype: :class:`gcloud.datastore._entity_pb2.Key`
406407
:returns: A key which will be added to a request. It will be the
407408
original if nothing needs to be changed.
408409
"""
409410
if key_pb.partition_id.HasField('dataset_id'):
410-
new_key_pb = datastore_pb.Key()
411+
new_key_pb = _entity_pb2.Key()
411412
new_key_pb.CopyFrom(key_pb)
412413
new_key_pb.partition_id.ClearField('dataset_id')
413414
key_pb = new_key_pb
@@ -420,7 +421,7 @@ def _add_keys_to_request(request_field_pb, key_pbs):
420421
:type request_field_pb: `RepeatedCompositeFieldContainer`
421422
:param request_field_pb: A repeated proto field that contains keys.
422423
423-
:type key_pbs: list of :class:`gcloud.datastore._datastore_v1_pb2.Key`
424+
:type key_pbs: list of :class:`gcloud.datastore._entity_pb2.Key`
424425
:param key_pbs: The keys to add to a request.
425426
"""
426427
for key_pb in key_pbs:

gcloud/datastore/helpers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from gcloud._helpers import _datetime_from_microseconds
2626
from gcloud._helpers import _microseconds_from_datetime
2727
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
28+
from gcloud.datastore import _entity_pb2
2829
from gcloud.datastore.entity import Entity
2930
from gcloud.datastore.key import Key
3031

@@ -79,7 +80,7 @@ def entity_from_protobuf(pb):
7980
The protobuf should be one returned from the Cloud Datastore
8081
Protobuf API.
8182
82-
:type pb: :class:`gcloud.datastore._datastore_v1_pb2.Entity`
83+
:type pb: :class:`gcloud.datastore._entity_pb2.Entity`
8384
:param pb: The Protobuf representing the entity.
8485
8586
:rtype: :class:`gcloud.datastore.entity.Entity`
@@ -122,7 +123,7 @@ def key_from_protobuf(pb):
122123
The protobuf should be one returned from the Cloud Datastore
123124
Protobuf API.
124125
125-
:type pb: :class:`gcloud.datastore._datastore_v1_pb2.Key`
126+
:type pb: :class:`gcloud.datastore._entity_pb2.Key`
126127
:param pb: The Protobuf representing the key.
127128
128129
:rtype: :class:`gcloud.datastore.key.Key`
@@ -216,7 +217,7 @@ def _get_value_from_value_pb(value_pb):
216217
Some work is done to coerce the return value into a more useful type
217218
(particularly in the case of a timestamp value, or a key value).
218219
219-
:type value_pb: :class:`gcloud.datastore._datastore_v1_pb2.Value`
220+
:type value_pb: :class:`gcloud.datastore._entity_pb2.Value`
220221
:param value_pb: The Value Protobuf.
221222
222223
:returns: The value provided by the Protobuf.
@@ -280,7 +281,7 @@ def _set_protobuf_value(value_pb, val):
280281
Some value types (entities, keys, lists) cannot be directly
281282
assigned; this function handles them correctly.
282283
283-
:type value_pb: :class:`gcloud.datastore._datastore_v1_pb2.Value`
284+
:type value_pb: :class:`gcloud.datastore._entity_pb2.Value`
284285
:param value_pb: The value protobuf to which the value is being assigned.
285286
286287
:type val: :class:`datetime.datetime`, boolean, float, integer, string,
@@ -317,10 +318,10 @@ def _set_protobuf_value(value_pb, val):
317318
def _prepare_key_for_request(key_pb):
318319
"""Add protobuf keys to a request object.
319320
320-
:type key_pb: :class:`gcloud.datastore._datastore_v1_pb2.Key`
321+
:type key_pb: :class:`gcloud.datastore._entity_pb2.Key`
321322
:param key_pb: A key to be added to a request.
322323
323-
:rtype: :class:`gcloud.datastore._datastore_v1_pb2.Key`
324+
:rtype: :class:`gcloud.datastore._entity_pb2.Key`
324325
:returns: A key which will be added to a request. It will be the
325326
original if nothing needs to be changed.
326327
"""
@@ -334,7 +335,7 @@ def _prepare_key_for_request(key_pb):
334335
# both go to the datastore given by 's~foo'. So if the key
335336
# protobuf in the request body has dataset_id='foo', the
336337
# backend will reject since 'foo' != 's~foo'.
337-
new_key_pb = datastore_pb.Key()
338+
new_key_pb = _entity_pb2.Key()
338339
new_key_pb.CopyFrom(key_pb)
339340
new_key_pb.partition_id.ClearField('dataset_id')
340341
key_pb = new_key_pb

gcloud/datastore/key.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import copy
1818
import six
1919

20-
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
20+
from gcloud.datastore import _entity_pb2
2121

2222

2323
class Key(object):
@@ -235,10 +235,10 @@ def completed_key(self, id_or_name):
235235
def to_protobuf(self):
236236
"""Return a protobuf corresponding to the key.
237237
238-
:rtype: :class:`gcloud.datastore._datastore_v1_pb2.Key`
238+
:rtype: :class:`gcloud.datastore._entity_pb2.Key`
239239
:returns: The protobuf representing the key.
240240
"""
241-
key = datastore_pb.Key()
241+
key = _entity_pb2.Key()
242242
key.partition_id.dataset_id = self.dataset_id
243243

244244
if self.namespace:

gcloud/datastore/test_batch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ def is_partial(self):
426426
return self._id is None
427427

428428
def to_protobuf(self):
429-
from gcloud.datastore import _datastore_v1_pb2
430-
key = self._key = _datastore_v1_pb2.Key()
429+
from gcloud.datastore import _entity_pb2
430+
key = self._key = _entity_pb2.Key()
431431
# Don't assign it, because it will just get ripped out
432432
# key.partition_id.dataset_id = self.dataset_id
433433

gcloud/datastore/test_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717

1818
def _make_entity_pb(dataset_id, kind, integer_id, name=None, str_val=None):
19-
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
19+
from gcloud.datastore import _entity_pb2
2020

21-
entity_pb = datastore_pb.Entity()
21+
entity_pb = _entity_pb2.Entity()
2222
entity_pb.key.partition_id.dataset_id = dataset_id
2323
path_element = entity_pb.key.path_element.add()
2424
path_element.kind = kind
@@ -314,14 +314,14 @@ def test_get_multi_miss(self):
314314
self.assertEqual(results, [])
315315

316316
def test_get_multi_miss_w_missing(self):
317-
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
317+
from gcloud.datastore import _entity_pb2
318318
from gcloud.datastore.key import Key
319319

320320
KIND = 'Kind'
321321
ID = 1234
322322

323323
# Make a missing entity pb to be returned from mock backend.
324-
missed = datastore_pb.Entity()
324+
missed = _entity_pb2.Entity()
325325
missed.key.partition_id.dataset_id = self.DATASET_ID
326326
path_element = missed.key.path_element.add()
327327
path_element.kind = KIND
@@ -378,7 +378,7 @@ def test_get_multi_miss_w_deferred(self):
378378
[key.to_protobuf()])
379379

380380
def test_get_multi_w_deferred_from_backend_but_not_passed(self):
381-
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
381+
from gcloud.datastore import _entity_pb2
382382
from gcloud.datastore.entity import Entity
383383
from gcloud.datastore.key import Key
384384

@@ -387,9 +387,9 @@ def test_get_multi_w_deferred_from_backend_but_not_passed(self):
387387
key2 = Key('Kind', 2345, dataset_id=self.DATASET_ID)
388388
key2_pb = key2.to_protobuf()
389389

390-
entity1_pb = datastore_pb.Entity()
390+
entity1_pb = _entity_pb2.Entity()
391391
entity1_pb.key.CopyFrom(key1_pb)
392-
entity2_pb = datastore_pb.Entity()
392+
entity2_pb = _entity_pb2.Entity()
393393
entity2_pb.key.CopyFrom(key2_pb)
394394

395395
creds = object()

gcloud/datastore/test_connection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,12 @@ def test_lookup_single_key_empty_response_w_transaction(self):
337337

338338
def test_lookup_single_key_nonempty_response(self):
339339
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
340+
from gcloud.datastore import _entity_pb2
340341

341342
DATASET_ID = 'DATASET'
342343
key_pb = self._make_key_pb(DATASET_ID)
343344
rsp_pb = datastore_pb.LookupResponse()
344-
entity = datastore_pb.Entity()
345+
entity = _entity_pb2.Entity()
345346
entity.key.CopyFrom(key_pb)
346347
rsp_pb.found.add(entity=entity)
347348
conn = self._makeOne()
@@ -606,10 +607,11 @@ def test_run_query_wo_namespace_empty_result(self):
606607

607608
def test_run_query_w_namespace_nonempty_result(self):
608609
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
610+
from gcloud.datastore import _entity_pb2
609611

610612
DATASET_ID = 'DATASET'
611613
KIND = 'Kind'
612-
entity = datastore_pb.Entity()
614+
entity = _entity_pb2.Entity()
613615
q_pb = self._make_query_pb(KIND)
614616
rsp_pb = datastore_pb.RunQueryResponse()
615617
rsp_pb.batch.entity_result.add(entity=entity)

0 commit comments

Comments
 (0)