Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the dependency on six. #2806

Merged
merged 7 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion botocore/awsrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _send_request(self, method, url, body, headers, *args, **kwargs):
def _convert_to_bytes(self, mixed_buffer):
# Take a list of mixed str/bytes and convert it
# all into a single bytestring.
# Any six.text_types will be encoded as utf-8.
# Any str will be encoded as utf-8.
bytes_buffer = []
for chunk in mixed_buffer:
if isinstance(chunk, str):
Expand Down
6 changes: 2 additions & 4 deletions botocore/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import inspect
import warnings
import hashlib
from http.client import HTTPMessage
import logging
import shlex
import re
Expand All @@ -25,17 +26,14 @@
from collections.abc import MutableMapping
from math import floor

from botocore.vendored import six
from botocore.exceptions import MD5UnavailableError
from dateutil.tz import tzlocal
from urllib3 import exceptions

logger = logging.getLogger(__name__)


from botocore.vendored.six.moves import http_client

class HTTPHeaders(http_client.HTTPMessage):
class HTTPHeaders(HTTPMessage):
pass

from urllib.parse import (
Expand Down
6 changes: 3 additions & 3 deletions botocore/configloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
# 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 configparser
import copy
import os
import shlex
import sys

import botocore.exceptions
from botocore.compat import six


def multi_file_load_config(*filenames):
Expand Down Expand Up @@ -143,10 +143,10 @@ def raw_config_parse(config_filename, parse_subsections=True):
path = os.path.expanduser(path)
if not os.path.isfile(path):
raise botocore.exceptions.ConfigNotFound(path=_unicode_path(path))
cp = six.moves.configparser.RawConfigParser()
cp = configparser.RawConfigParser()
try:
cp.read([path])
except (six.moves.configparser.Error, UnicodeDecodeError) as e:
except (configparser.Error, UnicodeDecodeError) as e:
raise botocore.exceptions.ConfigParseError(
path=_unicode_path(path), error=e
) from None
Expand Down
12 changes: 6 additions & 6 deletions botocore/docs/bcdoc/docstringparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
# 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
from html.parser import HTMLParser


class DocStringParser(six.moves.html_parser.HTMLParser):
class DocStringParser(HTMLParser):
"""
A simple HTML parser. Focused on converting the subset of HTML
that appears in the documentation strings of the JSON models into
Expand All @@ -23,20 +23,20 @@ class DocStringParser(six.moves.html_parser.HTMLParser):
def __init__(self, doc):
self.tree = None
self.doc = doc
six.moves.html_parser.HTMLParser.__init__(self)
HTMLParser.__init__(self)

def reset(self):
six.moves.html_parser.HTMLParser.reset(self)
HTMLParser.reset(self)
self.tree = HTMLTree(self.doc)

def feed(self, data):
# HTMLParser is an old style class, so the super() method will not work.
six.moves.html_parser.HTMLParser.feed(self, data)
HTMLParser.feed(self, data)
self.tree.write()
self.tree = HTMLTree(self.doc)

def close(self):
six.moves.html_parser.HTMLParser.close(self)
HTMLParser.close(self)
# Write if there is anything remaining.
self.tree.write()
self.tree = HTMLTree(self.doc)
Expand Down
2 changes: 1 addition & 1 deletion botocore/httpsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
IPV6_ADDRZ_RE,
ensure_bytes,
filter_ssl_warnings,
unquote,
urlparse,
)
from botocore.exceptions import (
Expand All @@ -66,7 +67,6 @@
ReadTimeoutError,
SSLError,
)
from botocore.vendored.six.moves.urllib_parse import unquote

filter_ssl_warnings()
logger = logging.getLogger(__name__)
Expand Down
7 changes: 4 additions & 3 deletions botocore/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@

"""
import base64
import http.client
import json
import logging
import re

from botocore.compat import ETree, XMLParseError, six
from botocore.compat import ETree, XMLParseError
from botocore.eventstream import EventStream, NoInitialResponseError
from botocore.utils import (
is_json_value_header,
Expand Down Expand Up @@ -306,7 +307,7 @@ def _do_generic_error_parse(self, response):
return {
'Error': {
'Code': str(response['status_code']),
'Message': six.moves.http_client.responses.get(
'Message': http.client.responses.get(
response['status_code'], ''
),
},
Expand Down Expand Up @@ -1062,7 +1063,7 @@ def _parse_error_from_http_status(self, response):
return {
'Error': {
'Code': str(response['status_code']),
'Message': six.moves.http_client.responses.get(
'Message': http.client.responses.get(
response['status_code'], ''
),
},
Expand Down
2 changes: 1 addition & 1 deletion botocore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import warnings
import weakref
from pathlib import Path
from urllib.request import getproxies, proxy_bypass

import dateutil.parser
from dateutil.tz import tzutc
Expand Down Expand Up @@ -84,7 +85,6 @@
UnsupportedS3ControlArnError,
UnsupportedS3ControlConfigurationError,
)
from botocore.vendored.six.moves.urllib.request import getproxies, proxy_bypass

logger = logging.getLogger(__name__)
DEFAULT_METADATA_SERVICE_TIMEOUT = 1
Expand Down
9 changes: 5 additions & 4 deletions tests/integration/test_client_http.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import contextlib
import select
import socket
import socketserver
import threading
from contextlib import contextmanager
from http.server import BaseHTTPRequestHandler

import botocore.session
from botocore.config import Config
Expand All @@ -15,7 +17,6 @@
ReadTimeoutError,
)
from botocore.vendored.requests import exceptions as requests_exceptions
from botocore.vendored.six.moves import BaseHTTPServer, socketserver
from tests import mock, unittest


Expand Down Expand Up @@ -182,7 +183,7 @@ def test_bad_status_line(self):
'ec2', endpoint_url=self.localhost, config=config
)

class BadStatusHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class BadStatusHandler(BaseHTTPRequestHandler):
event = threading.Event()

def do_POST(self):
Expand All @@ -200,7 +201,7 @@ def unused_port():
return sock.getsockname()[1]


class SimpleHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class SimpleHandler(BaseHTTPRequestHandler):
status = 200

def get_length(self):
Expand All @@ -219,7 +220,7 @@ def do_GET(self):
do_POST = do_PUT = do_GET


class ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class ProxyHandler(BaseHTTPRequestHandler):
tunnel_chunk_size = 1024
poll_limit = 10**4

Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_glacier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# 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.session
from botocore.exceptions import ClientError
from botocore.vendored import six
from tests import unittest


Expand Down Expand Up @@ -44,7 +45,7 @@ def test_can_handle_error_responses(self):
self.client.list_vaults(accountId='asdf')

def test_can_upload_archive(self):
body = six.BytesIO(b"bytes content")
body = io.BytesIO(b"bytes content")
response = self.client.upload_archive(
vaultName=self.VAULT_NAME,
archiveDescription='test upload',
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/auth/test_signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
# language governing permissions and limitations under the License.
import base64
import datetime
import io
import json
import time

import botocore.auth
import botocore.credentials
from botocore.awsrequest import AWSRequest
from botocore.compat import HTTPHeaders, parse_qs, six, urlsplit
from botocore.compat import HTTPHeaders, parse_qs, urlsplit
from tests import mock, unittest


Expand Down Expand Up @@ -325,7 +326,7 @@ def setUp(self):
access_key='foo', secret_key='bar', token='baz'
)
self.auth = self.AuthClass(self.credentials, 'ec2', 'eu-central-1')
self.request = AWSRequest(data=six.BytesIO(b"foo bar baz"))
self.request = AWSRequest(data=io.BytesIO(b"foo bar baz"))
self.request.method = 'PUT'
self.request.url = 'https://s3.eu-central-1.amazonaws.com/'

Expand Down Expand Up @@ -551,7 +552,7 @@ def test_thread_safe_timestamp(self):

def test_payload_is_binary_file(self):
request = AWSRequest()
request.data = six.BytesIO('\u2713'.encode())
request.data = io.BytesIO('\u2713'.encode())
request.url = 'https://amazonaws.com'
auth = self.create_signer()
payload = auth.payload(request)
Expand Down Expand Up @@ -582,7 +583,7 @@ def test_payload_not_signed_if_disabled_in_context(self):

def test_content_sha256_set_if_payload_signing_disabled(self):
request = AWSRequest()
request.data = six.BytesIO('\u2713'.encode())
request.data = io.BytesIO('\u2713'.encode())
request.url = 'https://amazonaws.com'
request.context['payload_signing_enabled'] = False
request.method = 'PUT'
Expand Down
14 changes: 5 additions & 9 deletions tests/unit/auth/test_sigv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@

"""
import datetime
import io
import logging
import os
import re
from http.server import BaseHTTPRequestHandler

import pytest

import botocore.auth
from botocore.awsrequest import AWSRequest
from botocore.compat import parse_qsl, six, urlsplit
from botocore.compat import parse_qsl, urlsplit
from botocore.credentials import Credentials
from tests import FreezeTime

Expand All @@ -55,21 +57,15 @@
'get-vanilla-query-order-key',
'get-vanilla-query-order-value',
]
if not six.PY3:
TESTS_TO_IGNORE += [
# NO support
'get-header-key-duplicate',
'get-header-value-order',
]

log = logging.getLogger(__name__)


class RawHTTPRequest(six.moves.BaseHTTPServer.BaseHTTPRequestHandler):
class RawHTTPRequest(BaseHTTPRequestHandler):
def __init__(self, raw_request):
if isinstance(raw_request, str):
raw_request = raw_request.encode('utf-8')
self.rfile = six.BytesIO(raw_request)
self.rfile = io.BytesIO(raw_request)
self.raw_requestline = self.rfile.readline()
self.error_code = None
self.error_message = None
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/docs/bcdoc/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
from botocore.compat import six
from botocore.docs.bcdoc.restdoc import ReSTDocument
from botocore.docs.bcdoc.style import ReSTStyle
from tests import unittest
Expand Down Expand Up @@ -151,9 +150,9 @@ def test_toctree_html(self):
style.tocitem('bar')
self.assertEqual(
style.doc.getvalue(),
six.b(
'\n.. toctree::\n :maxdepth: 1'
'\n :titlesonly:\n\n foo\n bar\n'
(
b'\n.. toctree::\n :maxdepth: 1'
b'\n :titlesonly:\n\n foo\n bar\n'
),
)

Expand All @@ -173,9 +172,9 @@ def test_hidden_toctree_html(self):
style.hidden_tocitem('bar')
self.assertEqual(
style.doc.getvalue(),
six.b(
'\n.. toctree::\n :maxdepth: 1'
'\n :hidden:\n\n foo\n bar\n'
(
b'\n.. toctree::\n :maxdepth: 1'
b'\n :hidden:\n\n foo\n bar\n'
),
)

Expand Down Expand Up @@ -294,7 +293,9 @@ def test_write_py_doc_string(self):
'returns: None'
)
style.write_py_doc_string(docstring)
self.assertEqual(style.doc.getvalue(), six.b(docstring + '\n'))
self.assertEqual(
style.doc.getvalue(), (docstring + '\n').encode('latin-1')
)

def test_new_line(self):
style = ReSTStyle(ReSTDocument())
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_awsrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
create_request_object,
prepare_request_dict,
)
from botocore.compat import file_type, six
from botocore.compat import file_type
from botocore.exceptions import UnseekableStreamError
from tests import mock, unittest

Expand Down Expand Up @@ -62,7 +62,7 @@ def settimeout(self, value):
pass


class BytesIOWithLen(six.BytesIO):
class BytesIOWithLen(io.BytesIO):
def __len__(self):
return len(self.getvalue())

Expand Down Expand Up @@ -403,7 +403,7 @@ def test_handles_expect_100_with_different_reason_phrase(self):
conn.request(
'GET',
'/bucket/foo',
six.BytesIO(b'body'),
io.BytesIO(b'body'),
{'Expect': b'100-continue', 'Content-Length': b'4'},
)
response = conn.getresponse()
Expand Down
Loading