Skip to content

Commit 375c8e8

Browse files
committed
Remove six from awscli codebase
1 parent c164ea2 commit 375c8e8

24 files changed

+93
-179
lines changed

awscli/argparser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# language governing permissions and limitations under the License.
1313
import argparse
1414
import sys
15-
from awscli.compat import six
1615
from difflib import get_close_matches
1716

1817

@@ -106,12 +105,12 @@ def parse_known_args(self, args, namespace=None):
106105
# default to utf-8.
107106
terminal_encoding = 'utf-8'
108107
for arg, value in vars(parsed).items():
109-
if isinstance(value, six.binary_type):
108+
if isinstance(value, bytes):
110109
setattr(parsed, arg, value.decode(terminal_encoding))
111110
elif isinstance(value, list):
112111
encoded = []
113112
for v in value:
114-
if isinstance(v, six.binary_type):
113+
if isinstance(v, bytes):
115114
encoded.append(v.decode(terminal_encoding))
116115
else:
117116
encoded.append(v)

awscli/argprocess.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""Module for processing CLI args."""
1414
import os
1515
import logging
16-
from awscli.compat import six
1716

1817
from botocore.compat import OrderedDict, json
1918

@@ -166,7 +165,7 @@ def _unpack_cli_arg(argument_model, value, cli_name):
166165
return _unpack_complex_cli_arg(
167166
argument_model, value, cli_name)
168167
else:
169-
return six.text_type(value)
168+
return str(value)
170169

171170

172171
def _unpack_json_cli_arg(argument_model, value, cli_name):
@@ -185,7 +184,7 @@ def _unpack_complex_cli_arg(argument_model, value, cli_name):
185184
return _unpack_json_cli_arg(argument_model, value, cli_name)
186185
raise ParamError(cli_name, "Invalid JSON:\n%s" % value)
187186
elif type_name == 'list':
188-
if isinstance(value, six.string_types):
187+
if isinstance(value, str):
189188
if value.lstrip()[0] == '[':
190189
return _unpack_json_cli_arg(argument_model, value, cli_name)
191190
elif isinstance(value, list) and len(value) == 1:
@@ -226,7 +225,7 @@ def unpack_scalar_cli_arg(argument_model, value, cli_name=''):
226225
raise ParamError(cli_name, msg)
227226
return open(file_path, 'rb')
228227
elif argument_model.type_name == 'boolean':
229-
if isinstance(value, six.string_types) and value.lower() == 'false':
228+
if isinstance(value, str) and value.lower() == 'false':
230229
return False
231230
return bool(value)
232231
else:
@@ -401,7 +400,7 @@ def _should_parse_as_shorthand(self, cli_argument, value):
401400
check_val = value[0]
402401
else:
403402
check_val = value
404-
if isinstance(check_val, six.string_types) and check_val.strip().startswith(
403+
if isinstance(check_val, str) and check_val.strip().startswith(
405404
('[', '{')):
406405
LOG.debug("Param %s looks like JSON, not considered for "
407406
"param shorthand.", cli_argument.py_name)

awscli/bcdoc/docstringparser.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
from botocore.compat import six
13+
from html.parser import HTMLParser
1414

1515

16-
class DocStringParser(six.moves.html_parser.HTMLParser):
16+
class DocStringParser(HTMLParser):
1717
"""
1818
A simple HTML parser. Focused on converting the subset of HTML
1919
that appears in the documentation strings of the JSON models into
@@ -23,20 +23,20 @@ class DocStringParser(six.moves.html_parser.HTMLParser):
2323
def __init__(self, doc):
2424
self.tree = None
2525
self.doc = doc
26-
six.moves.html_parser.HTMLParser.__init__(self)
26+
HTMLParser.__init__(self)
2727

2828
def reset(self):
29-
six.moves.html_parser.HTMLParser.reset(self)
29+
HTMLParser.reset(self)
3030
self.tree = HTMLTree(self.doc)
3131

3232
def feed(self, data):
3333
# HTMLParser is an old style class, so the super() method will not work.
34-
six.moves.html_parser.HTMLParser.feed(self, data)
34+
HTMLParser.feed(self, data)
3535
self.tree.write()
3636
self.tree = HTMLTree(self.doc)
3737

3838
def close(self):
39-
six.moves.html_parser.HTMLParser.close(self)
39+
HTMLParser.close(self)
4040
# Write if there is anything remaining.
4141
self.tree.write()
4242
self.tree = HTMLTree(self.doc)
@@ -176,7 +176,7 @@ class DataNode(Node):
176176
"""
177177
def __init__(self, data, parent=None):
178178
super(DataNode, self).__init__(parent)
179-
if not isinstance(data, six.string_types):
179+
if not isinstance(data, str):
180180
raise ValueError("Expecting string type, %s given." % type(data))
181181
self.data = data
182182

awscli/clidriver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from awscli.formatter import get_formatter
3030
from awscli.plugin import load_plugins
3131
from awscli.commands import CLICommand
32-
from awscli.compat import six
3332
from awscli.argparser import MainArgParser
3433
from awscli.argparser import ServiceArgParser
3534
from awscli.argparser import ArgTableArgParser

awscli/compat.py

Lines changed: 38 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,29 @@
1919
import zipfile
2020
import signal
2121
import contextlib
22+
import queue
23+
import io
24+
import collections.abc as collections_abc
25+
import locale
26+
import urllib.parse as urlparse
27+
from urllib.error import URLError
28+
from urllib.request import urlopen
2229
from configparser import RawConfigParser
2330
from functools import partial
2431

25-
from botocore.compat import six
26-
#import botocore.compat
32+
from urllib.error import URLError
2733

34+
from botocore.compat import six
2835
from botocore.compat import OrderedDict
2936

30-
# If you ever want to import from the vendored six. Add it here and then
31-
# import from awscli.compat. Also try to keep it in alphabetical order.
32-
# This may get large.
33-
advance_iterator = six.advance_iterator
34-
PY3 = six.PY3
35-
queue = six.moves.queue
36-
shlex_quote = six.moves.shlex_quote
37-
StringIO = six.StringIO
38-
BytesIO = six.BytesIO
39-
urlopen = six.moves.urllib.request.urlopen
40-
binary_type = six.binary_type
37+
# Backwards compatible definitions from six
38+
PY3 = sys.version_info[0] == 3
39+
advance_iterator = next
40+
shlex_quote = shlex.quote
41+
StringIO = io.StringIO
42+
BytesIO = io.BytesIO
43+
binary_type = bytes
44+
raw_input = input
4145

4246

4347
# Most, but not all, python installations will have zlib. This is required to
@@ -104,89 +108,33 @@ def ensure_text_type(s):
104108
raise ValueError("Expected str, unicode or bytes, received %s." % type(s))
105109

106110

107-
if six.PY3:
108-
import collections.abc as collections_abc
109-
import locale
110-
import urllib.parse as urlparse
111-
112-
from urllib.error import URLError
113-
114-
raw_input = input
115-
116-
def get_binary_stdin():
117-
if sys.stdin is None:
118-
raise StdinMissingError()
119-
return sys.stdin.buffer
120-
121-
def get_binary_stdout():
122-
return sys.stdout.buffer
123-
124-
def _get_text_writer(stream, errors):
125-
return stream
126-
127-
def bytes_print(statement, stdout=None):
128-
"""
129-
This function is used to write raw bytes to stdout.
130-
"""
131-
if stdout is None:
132-
stdout = sys.stdout
133-
134-
if getattr(stdout, 'buffer', None):
135-
stdout.buffer.write(statement)
136-
else:
137-
# If it is not possible to write to the standard out buffer.
138-
# The next best option is to decode and write to standard out.
139-
stdout.write(statement.decode('utf-8'))
140-
141-
else:
142-
import codecs
143-
import collections as collections_abc
144-
import locale
145-
import io
146-
import urlparse
147-
148-
from urllib2 import URLError
111+
def get_binary_stdin():
112+
if sys.stdin is None:
113+
raise StdinMissingError()
114+
return sys.stdin.buffer
149115

150-
raw_input = raw_input
151116

152-
def get_binary_stdin():
153-
if sys.stdin is None:
154-
raise StdinMissingError()
155-
return sys.stdin
117+
def get_binary_stdout():
118+
return sys.stdout.buffer
156119

157-
def get_binary_stdout():
158-
return sys.stdout
159120

160-
def _get_text_writer(stream, errors):
161-
# In python3, all the sys.stdout/sys.stderr streams are in text
162-
# mode. This means they expect unicode, and will encode the
163-
# unicode automatically before actually writing to stdout/stderr.
164-
# In python2, that's not the case. In order to provide a consistent
165-
# interface, we can create a wrapper around sys.stdout that will take
166-
# unicode, and automatically encode it to the preferred encoding.
167-
# That way consumers can just call get_text_writer(stream) and write
168-
# unicode to the returned stream. Note that get_text_writer
169-
# just returns the stream in the PY3 section above because python3
170-
# handles this.
171-
172-
# We're going to use the preferred encoding, but in cases that there is
173-
# no preferred encoding we're going to fall back to assuming ASCII is
174-
# what we should use. This will currently break the use of
175-
# PYTHONIOENCODING, which would require checking stream.encoding first,
176-
# however, the existing behavior is to only use
177-
# locale.getpreferredencoding() and so in the hope of not breaking what
178-
# is currently working, we will continue to only use that.
179-
encoding = locale.getpreferredencoding()
180-
if encoding is None:
181-
encoding = "ascii"
121+
def _get_text_writer(stream, errors):
122+
return stream
182123

183-
return codecs.getwriter(encoding)(stream, errors)
184124

185-
def bytes_print(statement, stdout=None):
186-
if stdout is None:
187-
stdout = sys.stdout
125+
def bytes_print(statement, stdout=None):
126+
"""
127+
This function is used to write raw bytes to stdout.
128+
"""
129+
if stdout is None:
130+
stdout = sys.stdout
188131

189-
stdout.write(statement)
132+
if getattr(stdout, 'buffer', None):
133+
stdout.buffer.write(statement)
134+
else:
135+
# If it is not possible to write to the standard out buffer.
136+
# The next best option is to decode and write to standard out.
137+
stdout.write(statement.decode('utf-8'))
190138

191139

192140
def compat_open(filename, mode='r', encoding=None, access_permissions=None):
@@ -252,7 +200,7 @@ def compat_shell_quote(s, platform=None):
252200
if platform == "win32":
253201
return _windows_shell_quote(s)
254202
else:
255-
return shlex_quote(s)
203+
return shlex.quote(s)
256204

257205

258206
def _windows_shell_quote(s):

awscli/customizations/awslambda.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
import copy
1515
from contextlib import closing
1616

17-
from botocore.vendored import six
18-
1917
from awscli.arguments import CustomArgument, CLIArgument
18+
from awscli.compat import BytesIO
2019

2120

2221
ERROR_MSG = (
@@ -90,7 +89,7 @@ def _should_contain_zip_content(value):
9089
# still try to load the contents as a zip file
9190
# to be absolutely sure.
9291
value = value.encode('utf-8')
93-
fileobj = six.BytesIO(value)
92+
fileobj = BytesIO(value)
9493
try:
9594
with closing(zipfile.ZipFile(fileobj)) as f:
9695
f.infolist()

awscli/customizations/cloudformation/artifact_exporter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import contextlib
1919
import uuid
2020
import shutil
21-
from awscli.compat import six
2221
from botocore.utils import set_value_from_jmespath
2322

2423
from awscli.compat import urlparse
@@ -33,7 +32,7 @@
3332

3433

3534
def is_path_value_valid(path):
36-
return isinstance(path, six.string_types)
35+
return isinstance(path, str)
3736

3837

3938
def make_abs_path(directory, path):
@@ -70,7 +69,7 @@ def parse_s3_url(url,
7069
object_key_property="Key",
7170
version_property=None):
7271

73-
if isinstance(url, six.string_types) \
72+
if isinstance(url, str) \
7473
and url.startswith("s3://"):
7574

7675
# Python < 2.7.10 don't parse query parameters from URI with custom

awscli/customizations/cloudformation/yamlhelper.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import yaml
1717
from yaml.resolver import ScalarNode, SequenceNode
1818

19-
from awscli.compat import six
20-
2119

2220
def intrinsics_multi_constructor(loader, tag_prefix, node):
2321
"""
@@ -35,7 +33,7 @@ def intrinsics_multi_constructor(loader, tag_prefix, node):
3533

3634
cfntag = prefix + tag
3735

38-
if tag == "GetAtt" and isinstance(node.value, six.string_types):
36+
if tag == "GetAtt" and isinstance(node.value, str):
3937
# ShortHand notation for !GetAtt accepts Resource.Attribute format
4038
# while the standard notation is to use an array
4139
# [Resource, Attribute]. Convert shorthand to standard format

awscli/customizations/codedeploy/push.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121
from botocore.exceptions import ClientError
2222

23-
from awscli.compat import six
2423
from awscli.customizations.codedeploy.utils import validate_s3_location
2524
from awscli.customizations.commands import BasicCommand
26-
from awscli.compat import ZIP_COMPRESSION_MODE
25+
from awscli.compat import BytesIO, ZIP_COMPRESSION_MODE
2726

2827

2928
ONE_MB = 1 << 20
@@ -246,7 +245,7 @@ def _multipart_upload_to_s3(self, params, bundle, size_remaining):
246245
Key=params.key,
247246
UploadId=upload_id,
248247
PartNumber=part_num,
249-
Body=six.BytesIO(data)
248+
Body=BytesIO(data)
250249
)
251250
multipart_list.append({
252251
'PartNumber': part_num,

awscli/customizations/configure/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
import string
14-
from botocore.vendored.six.moves import shlex_quote
14+
from awscli.compat import shlex
1515

1616
NOT_SET = '<not set>'
1717
PREDEFINED_SECTION_NAMES = ('preview', 'plugins')
@@ -45,5 +45,5 @@ def mask_value(current_value):
4545
def profile_to_section(profile_name):
4646
"""Converts a profile name to a section header to be used in the config."""
4747
if any(c in _WHITESPACE for c in profile_name):
48-
profile_name = shlex_quote(profile_name)
48+
profile_name = shlex.quote(profile_name)
4949
return 'profile %s' % profile_name

0 commit comments

Comments
 (0)