'Finish the current transaction.
This blocks waiting for all pending RPCs to complete, and then
marks the connection as finished.  After that no more operations
can be started using this connection.
Returns:
An object representing a transaction or None.
Raises:
datastore_errors.BadRequestError if the transaction is already
finished.'

def _end_transaction(self):

    if self.__finished:
        raise datastore_errors.BadRequestError('The    transaction    is    already    finished.')
    self.wait_for_all_pending_rpcs()
    assert (not self.get_pending_rpcs())
    transaction = self.transaction
    self.__finished = True
    self.__transaction = None
    return transaction
