diff --git a/awscrt/s3.py b/awscrt/s3.py index d268594f..a2065024 100644 --- a/awscrt/s3.py +++ b/awscrt/s3.py @@ -237,8 +237,6 @@ def __init__( assert isinstance(credential_provider, AwsCredentialsProvider) or credential_provider is None assert isinstance(tls_connection_options, TlsConnectionOptions) or tls_connection_options is None assert isinstance(part_size, int) or part_size is None - assert isinstance(network_interface_names, list) and all(isinstance(name, str) - for name in network_interface_names) or network_interface_names is None assert isinstance( throughput_target_gbps, diff --git a/source/s3_client.c b/source/s3_client.c index dfbc371e..8708e2b7 100644 --- a/source/s3_client.c +++ b/source/s3_client.c @@ -307,6 +307,9 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) { struct aws_signing_config_aws *signing_config = NULL; struct aws_credentials *anonymous_credentials = NULL; + struct aws_byte_cursor *network_interface_names = NULL; + int num_network_interface_names = 0; + if (signing_config_py != Py_None) { signing_config = aws_py_get_signing_config(signing_config_py); if (!signing_config) { @@ -322,22 +325,9 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) { signing_config = &default_signing_config; } - struct aws_byte_cursor *network_interface_names = NULL; - int num_network_interface_names = 0; - - if (network_interface_names_py != Py_None) { - if (!PyList_Check(network_interface_names_py)) { - PyErr_SetString(PyExc_TypeError, "Expected network_interface_names to be a list"); - return NULL; - } - Py_ssize_t listSize = PyList_Size(network_interface_names_py); - num_network_interface_names = (size_t)listSize; - } - - struct s3_client_binding *s3_client = aws_mem_calloc(allocator, 1, sizeof(struct s3_client_binding)); - /* From hereon, we need to clean up if errors occur */ - int result = AWS_OP_ERR; + bool success = false; + struct s3_client_binding *s3_client = aws_mem_calloc(allocator, 1, sizeof(struct s3_client_binding)); PyObject *capsule = PyCapsule_New(s3_client, s_capsule_name_s3_client, s_s3_client_capsule_destructor); if (!capsule) { @@ -351,7 +341,14 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) { s3_client->py_core = py_core; Py_INCREF(s3_client->py_core); - if (num_network_interface_names > 0) { + + if (network_interface_names_py != Py_None) { + if (!PyList_Check(network_interface_names_py)) { + PyErr_SetString(PyExc_TypeError, "Expected network_interface_names to be a list"); + goto cleanup; + } + Py_ssize_t listSize = PyList_Size(network_interface_names_py); + num_network_interface_names = (size_t)listSize; network_interface_names = aws_mem_calloc(allocator, num_network_interface_names, sizeof(struct aws_byte_cursor)); for (Py_ssize_t i = 0; i < num_network_interface_names; ++i) { @@ -385,12 +382,12 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) { PyErr_SetAwsLastError(); goto cleanup; } - result = AWS_OP_SUCCESS; + success = true; cleanup: aws_credentials_release(anonymous_credentials); aws_mem_release(allocator, network_interface_names); - if (result != AWS_OP_SUCCESS) { + if (!success) { Py_DECREF(capsule); return NULL; } diff --git a/test/test_s3.py b/test/test_s3.py index c8a04817..bc32eee4 100644 --- a/test/test_s3.py +++ b/test/test_s3.py @@ -9,14 +9,19 @@ import math import shutil import time +from sys import stdout + from test import NativeResourceTest from concurrent.futures import Future from multiprocessing import Process from awscrt.http import HttpHeaders, HttpRequest from awscrt.s3 import S3Client, S3RequestType, create_default_s3_signing_config -from awscrt.io import ClientBootstrap, ClientTlsContext, DefaultHostResolver, EventLoopGroup, TlsConnectionOptions, TlsContextOptions +from awscrt.io import ClientBootstrap, ClientTlsContext, DefaultHostResolver, EventLoopGroup, TlsConnectionOptions, \ + TlsContextOptions, LogLevel from awscrt.auth import AwsCredentials, AwsCredentialsProvider, AwsSignatureType, AwsSignedBodyHeaderType, AwsSignedBodyValue, AwsSigningAlgorithm, AwsSigningConfig +from awscrt.io import init_logging + from awscrt.s3 import ( S3ChecksumAlgorithm, S3ChecksumConfig, @@ -224,6 +229,7 @@ def test_sanity_secure(self): self.assertIsNotNone(s3_client) def test_sanity_network_interface_names(self): + init_logging(LogLevel.Debug, "stdout") s3_client = s3_client_new(True, self.region, network_interface_names=["eth0", "eth1"]) self.assertIsNotNone(s3_client)