def _s3op_with_retries(self, mode, **options):
    cmdline = [sys.executable, os.path.abspath(s3op.__file__), mode]
    for (key, value) in options.items():
        key = key.replace('_', '-')
        if isinstance(value, bool):
            if value:
                cmdline.append(('--%s' % key))
            else:
                cmdline.append(('--no-%s' % key))
        else:
            cmdline.extend((('--%s' % key), value))
    for i in range(NUM_S3OP_RETRIES):
        with NamedTemporaryFile(dir=self._tmpdir, mode='wb+', delete=(not debug.s3client), prefix='metaflow.s3op.stderr') as stderr:
            try:
                debug.s3client_exec(cmdline)
                stdout = subprocess.check_output(cmdline, cwd=self._tmpdir, stderr=stderr.file)
                return (stdout, None)
            except subprocess.CalledProcessError as ex:
                stderr.seek(0)
                err_out = stderr.read().decode('utf-8', errors='replace')
                stderr.seek(0)
                if (ex.returncode == s3op.ERROR_URL_NOT_FOUND):
                    raise MetaflowS3NotFound(err_out)
                elif (ex.returncode == s3op.ERROR_URL_ACCESS_DENIED):
                    raise MetaflowS3AccessDenied(err_out)
                time.sleep(((2 ** i) + random.randint(0, 10)))
    return (None, err_out)
def _s3op_with_retries(self, mode, **options):
    cmdline = [sys.executable, os.path.abspath(s3op.__file__), mode]
    for (key, value) in options.items():
        key = key.replace('_', '-')
        if isinstance(value, bool):
            if value:
                cmdline.append(('--%s' % key))
            else:
                cmdline.append(('--no-%s' % key))
        else:
            cmdline.extend((('--%s' % key), value))
    for i in range(NUM_S3OP_RETRIES):
        with NamedTemporaryFile(dir=self._tmpdir, mode='wb+', delete=(not debug.s3client), prefix='metaflow.s3op.stderr') as stderr:
            try:
                debug.s3client_exec(cmdline)
                stdout = subprocess.check_output(cmdline, cwd=self._tmpdir, stderr=stderr.file)
                return (stdout, None)
            except subprocess.CalledProcessError as ex:
                stderr.seek(0)
                err_out = stderr.read().decode('utf-8', errors='replace')
                stderr.seek(0)
                if (ex.returncode == s3op.ERROR_URL_NOT_FOUND):
                    raise MetaflowS3NotFound(err_out)
                elif (ex.returncode == s3op.ERROR_URL_ACCESS_DENIED):
                    raise MetaflowS3AccessDenied(err_out)
                time.sleep(((2 ** i) + random.randint(0, 10)))
    return (None, err_out)