def RunInTransactionCustomRetries(retries, function, *args, **kwargs):

  if _CurrentTransactionKey():
    raise datastore_errors.BadRequestError(
      'Nested transactions are not supported.')

  if retries < 0:
    raise datastore_errors.BadRequestError(
      'Number of retries should be non-negative number.')

  tx_key = None

  try:
    tx_key = _NewTransactionKey()

    for i in range(0, retries + 1):
      try:
        handle = _MakeSyncCall('datastore_v3', 'BeginTransaction',
                               api_base_pb.VoidProto(),
                               datastore_pb.Transaction())
      except apiproxy_errors.ApplicationError, err:
        raise _ToDatastoreError(err)

      tx = _Transaction(handle)
      _txes[tx_key] = tx

      try:
        result = function(*args, **kwargs)
      except:
        original_exception = sys.exc_info()

        try:
          _MakeSyncCall('datastore_v3', 'Rollback',
                        tx.handle, api_base_pb.VoidProto())
        except:
          exc_info = sys.exc_info()
          logging.info('Exception sending Rollback:\n' +
                       ''.join(traceback.format_exception(*exc_info)))

        type, value, trace = original_exception
        if type is datastore_errors.Rollback:
          return
        else:
          raise type, value, trace

      try:
        _MakeSyncCall('datastore_v3', 'Commit',
                      tx.handle, datastore_pb.CommitResponse())
      except apiproxy_errors.ApplicationError, err:
        if (err.application_error ==
            datastore_pb.Error.CONCURRENT_TRANSACTION):
          logging.warning('Transaction collision for entity group with '
                          'key %r. Retrying...', tx.entity_group)
          tx.handle = None
          tx.entity_group = None
          continue
        else:
          raise _ToDatastoreError(err)

      return result

    raise datastore_errors.TransactionFailedError(
      'The transaction could not be committed. Please try again.')

  finally:
    if tx_key in _txes:
      del _txes[tx_key]
    del tx_key
dumps a list into a text file, one line per item
dataset/ETHPy150Open CollabQ/CollabQ/.google_appengine/google/appengine/api/datastore.py/RunInTransactionCustomRetries--crossover with--dataset/ETHPy150Open FredHutch/swift-commander/swift_commander/swsymlinks.py/list2file