Skip to content

Commit 04dad71

Browse files
committed
Replacing datastore pb uses with "datastore" shim.
This is just a superficial rename in preparation for v1beta3. In particular, we went from a single datastore.proto file in v1beta2 to entity.proto, query.proto and datastore.proto in v1beta3, so this shim is intended to be the third of these files.
1 parent 8b09538 commit 04dad71

File tree

8 files changed

+124
-86
lines changed

8 files changed

+124
-86
lines changed

gcloud/datastore/_datastore_pb2.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 datastore.proto.
18+
"""
19+
20+
from gcloud.datastore import _datastore_v1_pb2
21+
22+
23+
LookupRequest = _datastore_v1_pb2.LookupRequest
24+
LookupResponse = _datastore_v1_pb2.LookupResponse
25+
RunQueryRequest = _datastore_v1_pb2.RunQueryRequest
26+
RunQueryResponse = _datastore_v1_pb2.RunQueryResponse
27+
BeginTransactionRequest = _datastore_v1_pb2.BeginTransactionRequest
28+
BeginTransactionResponse = _datastore_v1_pb2.BeginTransactionResponse
29+
RollbackRequest = _datastore_v1_pb2.RollbackRequest
30+
RollbackResponse = _datastore_v1_pb2.RollbackResponse
31+
CommitRequest = _datastore_v1_pb2.CommitRequest
32+
CommitResponse = _datastore_v1_pb2.CommitResponse
33+
AllocateIdsRequest = _datastore_v1_pb2.AllocateIdsRequest
34+
AllocateIdsResponse = _datastore_v1_pb2.AllocateIdsResponse
35+
Mutation = _datastore_v1_pb2.Mutation
36+
MutationResult = _datastore_v1_pb2.MutationResult
37+
ReadOptions = _datastore_v1_pb2.ReadOptions
38+
Property = _datastore_v1_pb2.Property # Not present in v1beta3

gcloud/datastore/batch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from gcloud.datastore import helpers
2525
from gcloud.datastore.key import _dataset_ids_equal
26-
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
26+
from gcloud.datastore import _datastore_pb2
2727

2828

2929
class Batch(object):
@@ -64,7 +64,7 @@ class Batch(object):
6464

6565
def __init__(self, client):
6666
self._client = client
67-
self._mutation = datastore_pb.Mutation()
67+
self._mutation = _datastore_pb2.Mutation()
6868
self._partial_key_entities = []
6969

7070
def current(self):
@@ -109,7 +109,7 @@ def mutation(self):
109109
This getter returns the Mutation protobuf that
110110
has been built-up so far.
111111
112-
:rtype: :class:`gcloud.datastore._datastore_v1_pb2.Mutation`
112+
:rtype: :class:`gcloud.datastore._datastore_pb2.Mutation`
113113
:returns: The Mutation protobuf to be sent in the commit request.
114114
"""
115115
return self._mutation
@@ -223,7 +223,7 @@ def _assign_entity_to_pb(entity_pb, entity):
223223
224224
Helper method for ``Batch.put``.
225225
226-
:type entity_pb: :class:`gcloud.datastore._datastore_v1_pb2.Entity`
226+
:type entity_pb: :class:`gcloud.datastore._entity_pb2.Entity`
227227
:param entity_pb: The entity owned by a mutation.
228228
229229
:type entity: :class:`gcloud.datastore.entity.Entity`

gcloud/datastore/connection.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from gcloud import connection
2020
from gcloud.environment_vars import GCD_HOST
2121
from gcloud.exceptions import make_exception
22-
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
22+
from gcloud.datastore import _datastore_pb2
2323
from gcloud.datastore import _entity_pb2
2424

2525

@@ -188,12 +188,12 @@ def lookup(self, dataset_id, key_pbs,
188188
``deferred`` is a list of
189189
:class:`gcloud.datastore._entity_pb2.Key`.
190190
"""
191-
lookup_request = datastore_pb.LookupRequest()
191+
lookup_request = _datastore_pb2.LookupRequest()
192192
_set_read_options(lookup_request, eventual, transaction_id)
193193
_add_keys_to_request(lookup_request.key, key_pbs)
194194

195195
lookup_response = self._rpc(dataset_id, 'lookup', lookup_request,
196-
datastore_pb.LookupResponse)
196+
_datastore_pb2.LookupResponse)
197197

198198
results = [result.entity for result in lookup_response.found]
199199
missing = [result.entity for result in lookup_response.missing]
@@ -255,15 +255,15 @@ def run_query(self, dataset_id, query_pb, namespace=None,
255255
the given transaction. Incompatible with
256256
``eventual==True``.
257257
"""
258-
request = datastore_pb.RunQueryRequest()
258+
request = _datastore_pb2.RunQueryRequest()
259259
_set_read_options(request, eventual, transaction_id)
260260

261261
if namespace:
262262
request.partition_id.namespace = namespace
263263

264264
request.query.CopyFrom(query_pb)
265265
response = self._rpc(dataset_id, 'runQuery', request,
266-
datastore_pb.RunQueryResponse)
266+
_datastore_pb2.RunQueryResponse)
267267
return (
268268
[e.entity for e in response.batch.entity_result],
269269
response.batch.end_cursor, # Assume response always has cursor.
@@ -279,14 +279,14 @@ def begin_transaction(self, dataset_id):
279279
:type dataset_id: string
280280
:param dataset_id: The ID dataset to which the transaction applies.
281281
282-
:rtype: :class:`._datastore_v1_pb2.BeginTransactionResponse`
282+
:rtype: :class:`._datastore_pb2.BeginTransactionResponse`
283283
:returns': the result protobuf for the begin transaction request.
284284
"""
285-
request = datastore_pb.BeginTransactionRequest()
285+
request = _datastore_pb2.BeginTransactionRequest()
286286
request.isolation_level = (
287-
datastore_pb.BeginTransactionRequest.SERIALIZABLE)
287+
_datastore_pb2.BeginTransactionRequest.SERIALIZABLE)
288288
response = self._rpc(dataset_id, 'beginTransaction', request,
289-
datastore_pb.BeginTransactionResponse)
289+
_datastore_pb2.BeginTransactionResponse)
290290
return response.transaction
291291

292292
def commit(self, dataset_id, mutation_pb, transaction_id):
@@ -297,28 +297,28 @@ def commit(self, dataset_id, mutation_pb, transaction_id):
297297
:type dataset_id: string
298298
:param dataset_id: The ID dataset to which the transaction applies.
299299
300-
:type mutation_pb: :class:`datastore_pb.Mutation`.
300+
:type mutation_pb: :class:`._datastore_pb2.Mutation`.
301301
:param mutation_pb: The protobuf for the mutations being saved.
302302
303303
:type transaction_id: string or None
304304
:param transaction_id: The transaction ID returned from
305305
:meth:`begin_transaction`. Non-transactional
306306
batches must pass ``None``.
307307
308-
:rtype: :class:`gcloud.datastore._datastore_v1_pb2.MutationResult`.
308+
:rtype: :class:`gcloud.datastore._datastore_pb2.MutationResult`.
309309
:returns': the result protobuf for the mutation.
310310
"""
311-
request = datastore_pb.CommitRequest()
311+
request = _datastore_pb2.CommitRequest()
312312

313313
if transaction_id:
314-
request.mode = datastore_pb.CommitRequest.TRANSACTIONAL
314+
request.mode = _datastore_pb2.CommitRequest.TRANSACTIONAL
315315
request.transaction = transaction_id
316316
else:
317-
request.mode = datastore_pb.CommitRequest.NON_TRANSACTIONAL
317+
request.mode = _datastore_pb2.CommitRequest.NON_TRANSACTIONAL
318318

319319
request.mutation.CopyFrom(mutation_pb)
320320
response = self._rpc(dataset_id, 'commit', request,
321-
datastore_pb.CommitResponse)
321+
_datastore_pb2.CommitResponse)
322322
return response.mutation_result
323323

324324
def rollback(self, dataset_id, transaction_id):
@@ -334,11 +334,11 @@ def rollback(self, dataset_id, transaction_id):
334334
:param transaction_id: The transaction ID returned from
335335
:meth:`begin_transaction`.
336336
"""
337-
request = datastore_pb.RollbackRequest()
337+
request = _datastore_pb2.RollbackRequest()
338338
request.transaction = transaction_id
339339
# Nothing to do with this response, so just execute the method.
340340
self._rpc(dataset_id, 'rollback', request,
341-
datastore_pb.RollbackResponse)
341+
_datastore_pb2.RollbackResponse)
342342

343343
def allocate_ids(self, dataset_id, key_pbs):
344344
"""Obtain backend-generated IDs for a set of keys.
@@ -355,11 +355,11 @@ def allocate_ids(self, dataset_id, key_pbs):
355355
:rtype: list of :class:`gcloud.datastore._entity_pb2.Key`
356356
:returns: An equal number of keys, with IDs filled in by the backend.
357357
"""
358-
request = datastore_pb.AllocateIdsRequest()
358+
request = _datastore_pb2.AllocateIdsRequest()
359359
_add_keys_to_request(request.key, key_pbs)
360360
# Nothing to do with this response, so just execute the method.
361361
response = self._rpc(dataset_id, 'allocateIds', request,
362-
datastore_pb.AllocateIdsResponse)
362+
_datastore_pb2.AllocateIdsResponse)
363363
return list(response.key)
364364

365365

@@ -376,7 +376,7 @@ def _set_read_options(request, eventual, transaction_id):
376376

377377
opts = request.read_options
378378
if eventual:
379-
opts.read_consistency = datastore_pb.ReadOptions.EVENTUAL
379+
opts.read_consistency = _datastore_pb2.ReadOptions.EVENTUAL
380380
elif transaction_id:
381381
opts.transaction = transaction_id
382382

gcloud/datastore/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def _get_value_from_property_pb(property_pb):
263263
Some work is done to coerce the return value into a more useful type
264264
(particularly in the case of a timestamp value, or a key value).
265265
266-
:type property_pb: :class:`gcloud.datastore._datastore_v1_pb2.Property`
266+
:type property_pb: :class:`gcloud.datastore._datastore_pb2.Property`
267267
:param property_pb: The Property Protobuf.
268268
269269
:returns: The value provided by the Protobuf.

gcloud/datastore/test_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _makeOne(self, client):
2626
return self._getTargetClass()(client)
2727

2828
def test_ctor(self):
29-
from gcloud.datastore._datastore_v1_pb2 import Mutation
29+
from gcloud.datastore._datastore_pb2 import Mutation
3030
_DATASET = 'DATASET'
3131
_NAMESPACE = 'NAMESPACE'
3232
connection = _Connection()

0 commit comments

Comments
 (0)