diff --git a/boto3/compat.py b/boto3/compat.py index ae495cf7d2..4011393aca 100644 --- a/boto3/compat.py +++ b/boto3/compat.py @@ -16,22 +16,15 @@ import socket import warnings -from botocore.vendored import six from boto3.exceptions import PythonDeprecationWarning -if six.PY3: - # In python3, socket.error is OSError, which is too general - # for what we want (i.e FileNotFoundError is a subclass of OSError). - # In py3 all the socket related errors are in a newly created - # ConnectionError - SOCKET_ERROR = ConnectionError -else: - SOCKET_ERROR = socket.error +# In python3, socket.error is OSError, which is too general +# for what we want (i.e FileNotFoundError is a subclass of OSError). +# In py3 all the socket related errors are in a newly created +# ConnectionError +SOCKET_ERROR = ConnectionError -if six.PY3: - import collections.abc as collections_abc -else: - import collections as collections_abc +import collections.abc as collections_abc if sys.platform.startswith('win'): diff --git a/boto3/dynamodb/types.py b/boto3/dynamodb/types.py index f696a6d4cf..f358b12f55 100644 --- a/boto3/dynamodb/types.py +++ b/boto3/dynamodb/types.py @@ -10,7 +10,6 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -import collections.abc from decimal import ( Clamped, Context, @@ -21,6 +20,8 @@ Underflow, ) +from boto3.compat import collections_abc + STRING = 'S' NUMBER = 'N' BINARY = 'B' @@ -183,7 +184,7 @@ def _is_binary(self, value): return False def _is_set(self, value): - if isinstance(value, collections.abc.Set): + if isinstance(value, collections_abc.Set): return True return False @@ -194,7 +195,7 @@ def _is_type_set(self, value, type_validator): return False def _is_map(self, value): - if isinstance(value, collections.abc.Mapping): + if isinstance(value, collections_abc.Mapping): return True return False diff --git a/tests/functional/test_s3.py b/tests/functional/test_s3.py index 43c978a0ec..0abbc84409 100644 --- a/tests/functional/test_s3.py +++ b/tests/functional/test_s3.py @@ -10,10 +10,11 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +import io + import botocore import botocore.stub import pytest -from botocore.compat import six from botocore.config import Config from botocore.stub import Stubber @@ -244,7 +245,7 @@ def progress_callback(amount): class TestUploadFileobj(BaseTransferTest): def setUp(self): super().setUp() - self.contents = six.BytesIO(b'foo\n') + self.contents = io.BytesIO(b'foo\n') def stub_put_object(self): put_object_response = { @@ -330,7 +331,7 @@ def test_object_upload(self): def test_multipart_upload(self): chunksize = 8 * (1024**2) - contents = six.BytesIO(b'0' * (chunksize * 3)) + contents = io.BytesIO(b'0' * (chunksize * 3)) self.stub_multipart_upload(num_parts=3) transfer_config = TransferConfig( multipart_chunksize=chunksize, @@ -354,7 +355,7 @@ class TestDownloadFileobj(BaseTransferTest): def setUp(self): super().setUp() self.contents = b'foo' - self.fileobj = six.BytesIO() + self.fileobj = io.BytesIO() def stub_single_part_download(self): self.stub_head(content_length=len(self.contents)) @@ -400,7 +401,7 @@ def stub_get_object(self, full_contents, start_byte=0, end_byte=None): "ETag": self.etag, "ContentLength": len(contents), "ContentType": "binary/octet-stream", - "Body": six.BytesIO(contents), + "Body": io.BytesIO(contents), "ResponseMetadata": {"HTTPStatusCode": 200}, } ) diff --git a/tests/integration/test_s3.py b/tests/integration/test_s3.py index 5393bbc0f8..162eaee373 100644 --- a/tests/integration/test_s3.py +++ b/tests/integration/test_s3.py @@ -12,6 +12,7 @@ # language governing permissions and limitations under the License. import datetime import hashlib +import io import logging import math import os @@ -21,13 +22,11 @@ import threading from botocore.client import Config -from botocore.compat import six import boto3.s3.transfer import boto3.session from tests import unique_id, unittest -urlopen = six.moves.urllib.request.urlopen LOG = logging.getLogger('boto3.tests.integration') @@ -338,7 +337,7 @@ def test_copy(self): self.object_exists('bar') def test_upload_fileobj(self): - fileobj = six.BytesIO(b'foo') + fileobj = io.BytesIO(b'foo') self.client.upload_fileobj( Fileobj=fileobj, Bucket=self.bucket_name, Key='foo' ) @@ -356,7 +355,7 @@ def test_upload_fileobj_progress(self): multipart_threshold=chunksize, max_concurrency=1, ) - fileobj = six.BytesIO(b'0' * (chunksize * 3)) + fileobj = io.BytesIO(b'0' * (chunksize * 3)) def progress_callback(amount): self.progress += amount @@ -374,7 +373,7 @@ def progress_callback(amount): self.assertEqual(self.progress, chunksize * 3) def test_download_fileobj(self): - fileobj = six.BytesIO() + fileobj = io.BytesIO() self.client.put_object( Bucket=self.bucket_name, Key='foo', Body=b'beach' ) @@ -692,7 +691,7 @@ def test_transfer_methods_do_not_use_threads(self): self.addCleanup(self.delete_object, key) self.assertTrue(self.object_exists(key)) - fileobj = six.BytesIO() + fileobj = io.BytesIO() self.client.download_fileobj( Bucket=self.bucket_name, Key='foo', Fileobj=fileobj, Config=config ) diff --git a/tests/unit/docs/test_docstring.py b/tests/unit/docs/test_docstring.py index f67d3ff5b8..68fe9559f5 100644 --- a/tests/unit/docs/test_docstring.py +++ b/tests/unit/docs/test_docstring.py @@ -10,7 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -from botocore.compat import six +import io from tests import mock from tests.unit.docs import BaseDocsTest @@ -18,7 +18,7 @@ class TestResourceDocstrings(BaseDocsTest): def test_action_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.sample_operation) action_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -51,7 +51,7 @@ def test_action_help(self): def test_load_help(self): sub_resource = self.resource.Sample('Id') - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(sub_resource.load) load_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -69,7 +69,7 @@ def test_load_help(self): ) def test_sub_resource_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.Sample) sub_resource_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -85,7 +85,7 @@ def test_sub_resource_help(self): ) def test_attribute_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.Sample('id').__class__.foo) attribute_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -93,7 +93,7 @@ def test_attribute_help(self): ) def test_identifier_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.Sample('id').__class__.name) identifier_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -106,7 +106,7 @@ def test_identifier_help(self): def test_reference_help(self): sample_resource = self.resource.Sample('id') - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(sample_resource.__class__.related_sample) reference_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -118,7 +118,7 @@ def test_reference_help(self): ) def test_collection_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.__class__.samples) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -127,7 +127,7 @@ def test_collection_help(self): ) def test_collection_all_method_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.samples.all) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -146,7 +146,7 @@ def test_collection_all_method_help(self): ) def test_collection_filter_method_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.samples.filter) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -168,7 +168,7 @@ def test_collection_filter_method_help(self): ) def test_collection_limit_method_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.samples.limit) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -190,7 +190,7 @@ def test_collection_limit_method_help(self): ) def test_collection_page_size_method_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.samples.page_size) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -213,7 +213,7 @@ def test_collection_page_size_method_help(self): def test_collection_chaining_help(self): collection = self.resource.samples.all() - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(collection.all) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -232,7 +232,7 @@ def test_collection_chaining_help(self): ) def test_batch_action_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.samples.operate) batch_action_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( @@ -264,7 +264,7 @@ def test_batch_action_help(self): ) def test_resource_waiter_help(self): - with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: + with mock.patch('sys.stdout', io.StringIO()) as mock_stdout: help(self.resource.Sample('id').wait_until_complete) resource_waiter_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( diff --git a/tests/unit/s3/test_inject.py b/tests/unit/s3/test_inject.py index b460306504..422db39d91 100644 --- a/tests/unit/s3/test_inject.py +++ b/tests/unit/s3/test_inject.py @@ -10,8 +10,9 @@ # distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +import io + import pytest -from botocore.compat import six from botocore.exceptions import ClientError from boto3.s3 import inject @@ -158,7 +159,7 @@ def test_copy(self): ) def test_upload_fileobj(self): - fileobj = six.BytesIO(b'foo') + fileobj = io.BytesIO(b'foo') inject.bucket_upload_fileobj(self.bucket, Key='key', Fileobj=fileobj) self.bucket.meta.client.upload_fileobj.assert_called_with( Bucket=self.bucket.name, @@ -170,7 +171,7 @@ def test_upload_fileobj(self): ) def test_download_fileobj(self): - obj = six.BytesIO() + obj = io.BytesIO() inject.bucket_download_fileobj(self.bucket, Key='key', Fileobj=obj) self.bucket.meta.client.download_fileobj.assert_called_with( Bucket=self.bucket.name, @@ -222,7 +223,7 @@ def test_copy(self): ) def test_upload_fileobj(self): - fileobj = six.BytesIO(b'foo') + fileobj = io.BytesIO(b'foo') inject.object_upload_fileobj(self.obj, Fileobj=fileobj) self.obj.meta.client.upload_fileobj.assert_called_with( Bucket=self.obj.bucket_name, @@ -234,7 +235,7 @@ def test_upload_fileobj(self): ) def test_download_fileobj(self): - fileobj = six.BytesIO() + fileobj = io.BytesIO() inject.object_download_fileobj(self.obj, Fileobj=fileobj) self.obj.meta.client.download_fileobj.assert_called_with( Bucket=self.obj.bucket_name,