Skip to content

Commit

Permalink
move back to list api
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Jul 10, 2024
1 parent 461d5e0 commit 7cf9110
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
11 changes: 7 additions & 4 deletions awscrt/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
from awscrt import NativeResource
from awscrt.http import HttpRequest
from awscrt.io import ClientBootstrap, TlsConnectionOptions
from awscrt.auth import AwsCredentials, AwsCredentialsProvider, AwsSignatureType, AwsSignedBodyHeaderType, AwsSignedBodyValue, AwsSigningAlgorithm, AwsSigningConfig
from awscrt.auth import AwsCredentialsProvider, AwsSignatureType, AwsSignedBodyHeaderType, AwsSignedBodyValue, \
AwsSigningAlgorithm, AwsSigningConfig
import awscrt.exceptions
import threading
from dataclasses import dataclass
from typing import List, Optional, Tuple
from typing import List, Optional, Tuple, Sequence
from enum import IntEnum


Expand Down Expand Up @@ -230,7 +229,7 @@ def __init__(
throughput_target_gbps=None,
enable_s3express=False,
memory_limit=None,
network_interface_names=None):
network_interface_names: Optional[Sequence[str]] = None):
assert isinstance(bootstrap, ClientBootstrap) or bootstrap is None
assert isinstance(region, str)
assert isinstance(signing_config, AwsSigningConfig) or signing_config is None
Expand All @@ -243,7 +242,7 @@ def __init__(
throughput_target_gbps,
float) or throughput_target_gbps is None
assert isinstance(enable_s3express, bool) or enable_s3express is None

assert isinstance(network_interface_names, Sequence) or network_interface_names is None
if credential_provider and signing_config:
raise ValueError("'credential_provider' has been deprecated in favor of 'signing_config'. "
"Both parameters may not be set.")
Expand Down Expand Up @@ -278,6 +277,10 @@ def on_shutdown():
throughput_target_gbps = 0
if memory_limit is None:
memory_limit = 0
if network_interface_names is not None:
# ensure this is a list, so it's simpler to process in C
if not isinstance(network_interface_names, list):
network_interface_names = list(network_interface_names)

self._binding = _awscrt.s3_client_new(
bootstrap,
Expand Down
7 changes: 3 additions & 4 deletions source/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,23 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) {
Py_INCREF(s3_client->py_core);

if (network_interface_names_py != Py_None) {
if (!PySequence_Check(network_interface_names_py)) {
if (!PyList_Check(network_interface_names_py)) {
PyErr_SetString(PyExc_TypeError, "Expected network_interface_names to be a sequence.");
goto cleanup;
}
Py_ssize_t list_size = PySequence_Size(network_interface_names_py);
Py_ssize_t list_size = PyList_Size(network_interface_names_py);
if (list_size < 0) {
goto cleanup;
}
num_network_interface_names = (size_t)list_size;
network_interface_names =
aws_mem_calloc(allocator, num_network_interface_names, sizeof(struct aws_byte_cursor));
for (size_t i = 0; i < num_network_interface_names; ++i) {
PyObject *str_obj = PySequence_GetItem(network_interface_names_py, i); /* New reference */
PyObject *str_obj = PyList_GetItem(network_interface_names_py, i); /* Borrowed reference */
if (!str_obj) {
goto cleanup;
}
network_interface_names[i] = aws_byte_cursor_from_pyunicode(str_obj);
Py_DECREF(str_obj);
if (network_interface_names[i].ptr == NULL) {
PyErr_SetString(PyExc_TypeError, "Expected all network_interface_names elements to be strings.");
goto cleanup;
Expand Down
6 changes: 2 additions & 4 deletions test/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
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.auth import AwsCredentials, AwsCredentialsProvider, AwsSignatureType, AwsSignedBodyHeaderType, AwsSignedBodyValue, AwsSigningAlgorithm, AwsSigningConfig
from awscrt.auth import AwsCredentials
from awscrt.s3 import (
S3ChecksumAlgorithm,
S3ChecksumConfig,
Expand Down Expand Up @@ -224,7 +222,7 @@ def test_sanity_secure(self):
self.assertIsNotNone(s3_client)

def test_sanity_network_interface_names(self):
s3_client = s3_client_new(True, self.region, network_interface_names=["eth0", "eth1"])
s3_client = s3_client_new(True, self.region, network_interface_names=("eth0", "eth1"))
self.assertIsNotNone(s3_client)

def test_wait_shutdown(self):
Expand Down

0 comments on commit 7cf9110

Please sign in to comment.