1+ """Connections to gcloud datastore API servers.
2+ """
13from gcloud import connection
24from gcloud .datastore import datastore_v1_pb2 as datastore_pb
35from gcloud .datastore import _helpers
@@ -59,6 +61,22 @@ def _request(self, dataset_id, method, data):
5961 return content
6062
6163 def _rpc (self , dataset_id , method , request_pb , response_pb_cls ):
64+ """ Make an protobuf RPC request.
65+
66+ :type dataset_id: string
67+ :param dataset_id: The ID of the dataset to connect to. This is
68+ usually your project name in the cloud console.
69+
70+ :type method: string
71+ :param method: The name of the method to invoke.
72+
73+ :type request_pb: :class:`google.protobuf.message.Message` instance
74+ :param method: the protobuf instance representing the request.
75+
76+ :type response_pb_cls: a :class:`google.protobuf.message.Message'
77+ subclass.
78+ :param method: The class used to unmarshall the response protobuf.
79+ """
6280 response = self ._request (dataset_id = dataset_id , method = method ,
6381 data = request_pb .SerializeToString ())
6482 return response_pb_cls .FromString (response )
@@ -94,13 +112,29 @@ def build_api_url(cls, dataset_id, method, base_url=None,
94112 dataset_id = dataset_id , method = method )
95113
96114 def transaction (self , transaction = connection .Connection ._EMPTY ):
115+ """Getter/setter for the connection's transaction object.
116+
117+ :type transaction: :class:`gcloud.datastore.transaction.Transaction`,
118+ (setting), or omitted (getting).
119+ :param transaction: The new transaction (if passed).
120+
121+ :rtype: :class:`gcloud.datastore.transaction.Transaction`, (getting)
122+ or :class:`gcloud.datastore.connection.Connection' (setting)
123+ :returns: the current transaction (getting) or self (setting).
124+ """
97125 if transaction is self ._EMPTY :
98126 return self ._current_transaction
99127 else :
100128 self ._current_transaction = transaction
101129 return self
102130
103131 def mutation (self ):
132+ """Getter for mutation usable with current connection.
133+
134+ :rtype: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
135+ :returns: the mutation instance associated with the current transaction
136+ (if one exists) or or a new mutation instance.
137+ """
104138 if self .transaction ():
105139 return self .transaction ().mutation ()
106140 else :
@@ -278,6 +312,17 @@ def lookup(self, dataset_id, key_pbs):
278312 return results
279313
280314 def commit (self , dataset_id , mutation_pb ):
315+ """Commit dataset mutations in context of current transation (if any).
316+
317+ :type dataset_id: string
318+ :param dataset_id: The dataset in which to perform the changes.
319+
320+ :type mutation_pb: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
321+ :param mutation_pb: The protobuf for the mutations being saved.
322+
323+ :rtype: :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
324+ :returns': the result protobuf for the mutation.
325+ """
281326 request = datastore_pb .CommitRequest ()
282327
283328 if self .transaction ():
@@ -350,8 +395,11 @@ def delete_entities(self, dataset_id, key_pbs):
350395 :param dataset_id: The dataset from which to delete the keys.
351396
352397 :type key_pbs: list of :class:`gcloud.datastore.datastore_v1_pb2.Key`
353- (or a single Key)
354- :param key_pbs: The key (or keys) to delete from the datastore.
398+ :param key_pbs: The keys to delete from the datastore.
399+
400+ :rtype: boolean (if in a transaction) or else
401+ :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
402+ :returns: True (if in a transaction) or else a mutation result protobuf.
355403 """
356404 mutation = self .mutation ()
357405
@@ -365,4 +413,22 @@ def delete_entities(self, dataset_id, key_pbs):
365413 return self .commit (dataset_id , mutation )
366414
367415 def delete_entity (self , dataset_id , key_pb ):
416+ """Delete a single key from a dataset in the Cloud Datastore.
417+
418+ This method deals only with
419+ :class:`gcloud.datastore.datastore_v1_pb2.Key` protobufs
420+ and not with any of the other abstractions.
421+ For example, it's used under the hood in the
422+ :func:`gcloud.datastore.entity.Entity.delete` method.
423+
424+ :type dataset_id: string
425+ :param dataset_id: The dataset from which to delete the key.
426+
427+ :type key_pb: :class:`gcloud.datastore.datastore_v1_pb2.Key`
428+ :param key_pb: The key to delete from the datastore.
429+
430+ :rtype: boolean (if in a transaction) or else
431+ :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
432+ :returns: True (if in a transaction) or else a mutation result protobuf.
433+ """
368434 return self .delete_entities (dataset_id , [key_pb ])
0 commit comments