1+ """Connections to gcloud datastore API servers."""
12from gcloud import connection
23from gcloud .datastore import datastore_v1_pb2 as datastore_pb
34from gcloud .datastore import _helpers
@@ -59,6 +60,22 @@ def _request(self, dataset_id, method, data):
5960 return content
6061
6162 def _rpc (self , dataset_id , method , request_pb , response_pb_cls ):
63+ """ Make a protobuf RPC request.
64+
65+ :type dataset_id: string
66+ :param dataset_id: The ID of the dataset to connect to. This is
67+ usually your project name in the cloud console.
68+
69+ :type method: string
70+ :param method: The name of the method to invoke.
71+
72+ :type request_pb: :class:`google.protobuf.message.Message` instance
73+ :param method: the protobuf instance representing the request.
74+
75+ :type response_pb_cls: a :class:`google.protobuf.message.Message'
76+ subclass.
77+ :param method: The class used to unmarshall the response protobuf.
78+ """
6279 response = self ._request (dataset_id = dataset_id , method = method ,
6380 data = request_pb .SerializeToString ())
6481 return response_pb_cls .FromString (response )
@@ -94,13 +111,29 @@ def build_api_url(cls, dataset_id, method, base_url=None,
94111 dataset_id = dataset_id , method = method )
95112
96113 def transaction (self , transaction = connection .Connection ._EMPTY ):
114+ """Getter/setter for the connection's transaction object.
115+
116+ :type transaction: :class:`gcloud.datastore.transaction.Transaction`,
117+ (setting), or omitted (getting).
118+ :param transaction: The new transaction (if passed).
119+
120+ :rtype: :class:`gcloud.datastore.transaction.Transaction`, (getting)
121+ or :class:`gcloud.datastore.connection.Connection' (setting)
122+ :returns: the current transaction (getting) or self (setting).
123+ """
97124 if transaction is self ._EMPTY :
98125 return self ._current_transaction
99126 else :
100127 self ._current_transaction = transaction
101128 return self
102129
103130 def mutation (self ):
131+ """Getter for mutation usable with current connection.
132+
133+ :rtype: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
134+ :returns: the mutation instance associated with the current transaction
135+ (if one exists) or or a new mutation instance.
136+ """
104137 if self .transaction ():
105138 return self .transaction ().mutation ()
106139 else :
@@ -278,6 +311,17 @@ def lookup(self, dataset_id, key_pbs):
278311 return results
279312
280313 def commit (self , dataset_id , mutation_pb ):
314+ """Commit dataset mutations in context of current transation (if any).
315+
316+ :type dataset_id: string
317+ :param dataset_id: The dataset in which to perform the changes.
318+
319+ :type mutation_pb: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
320+ :param mutation_pb: The protobuf for the mutations being saved.
321+
322+ :rtype: :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
323+ :returns': the result protobuf for the mutation.
324+ """
281325 request = datastore_pb .CommitRequest ()
282326
283327 if self .transaction ():
@@ -350,8 +394,11 @@ def delete_entities(self, dataset_id, key_pbs):
350394 :param dataset_id: The dataset from which to delete the keys.
351395
352396 :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.
397+ :param key_pbs: The keys to delete from the datastore.
398+
399+ :rtype: boolean (if in a transaction) or else
400+ :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
401+ :returns: True (if in a transaction) or else a mutation result protobuf.
355402 """
356403 mutation = self .mutation ()
357404
@@ -365,4 +412,22 @@ def delete_entities(self, dataset_id, key_pbs):
365412 return self .commit (dataset_id , mutation )
366413
367414 def delete_entity (self , dataset_id , key_pb ):
415+ """Delete a single key from a dataset in the Cloud Datastore.
416+
417+ This method deals only with
418+ :class:`gcloud.datastore.datastore_v1_pb2.Key` protobufs
419+ and not with any of the other abstractions.
420+ For example, it's used under the hood in the
421+ :func:`gcloud.datastore.entity.Entity.delete` method.
422+
423+ :type dataset_id: string
424+ :param dataset_id: The dataset from which to delete the key.
425+
426+ :type key_pb: :class:`gcloud.datastore.datastore_v1_pb2.Key`
427+ :param key_pb: The key to delete from the datastore.
428+
429+ :rtype: boolean (if in a transaction) or else
430+ :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
431+ :returns: True (if in a transaction) or else a mutation result protobuf.
432+ """
368433 return self .delete_entities (dataset_id , [key_pb ])
0 commit comments