'Set the current transaction on a request.
This calls _get_transaction() (see below).  The transaction object
returned is both set as the transaction field on the request
object and returned.
Args:
request: A protobuf with a transaction field.
Returns:
An object representing a transaction or None.
Raises:
ValueError: if called with a non-Cloud Datastore request when using
Cloud Datastore.'

def _set_request_transaction(self, request):

    if self.__finished:
        raise datastore_errors.BadRequestError('Cannot    start    a    new    operation    in    a    finished    transaction.')
    transaction = self.transaction
    if (self._api_version == _CLOUD_DATASTORE_V1):
        if isinstance(request, (googledatastore.CommitRequest, googledatastore.RollbackRequest)):
            request.transaction = transaction
        elif isinstance(request, (googledatastore.LookupRequest, googledatastore.RunQueryRequest)):
            request.read_options.transaction = transaction
        else:
            raise ValueError(('Cannot    use    Cloud    Datastore    V1    transactions    with    %s.' % type(request)))
        request.read_options.transaction = transaction
    else:
        request.mutable_transaction().CopyFrom(transaction)
    return transaction
