Skip to content

Commit 2acf1e6

Browse files
committed
Fix flake8 issues
1 parent 12af573 commit 2acf1e6

File tree

133 files changed

+2257
-2004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+2257
-2004
lines changed

Diff for: CHANGELOG.rst

-1
Original file line numberDiff line numberDiff line change
@@ -10098,4 +10098,3 @@ CHANGELOG
1009810098
* feature:``EMR``: Added support for adding EBS storage to EMR instances.
1009910099
* bugfix:pagination: Refactored pagination to handle non-string service tokens.
1010010100
* bugfix:credentials: Fix race condition in credential provider.
10101-

Diff for: CODE_OF_CONDUCT.md

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
33
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
44
[email protected] with any additional questions or comments.
5-

Diff for: CONTRIBUTING.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ contributions as well:
3333
fixed upstream.
3434
* Changes to paginators, waiters, and endpoints are also generated upstream based on our internal knowledge of the AWS services.
3535
These include any of the following files in ``botocore/data/``:
36-
36+
3737
* ``_endpoints.json``
3838
* ``*.paginators-1.json``
3939
* ``*.waiters-2.json``

Diff for: README.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ Assuming that you have Python and ``virtualenv`` installed, set up your environm
3838
.. code-block:: sh
3939
4040
$ pip install botocore
41-
41+
4242
Using Botocore
4343
~~~~~~~~~~~~~~
44-
After installing botocore
44+
After installing botocore
4545

4646
Next, set up credentials (in e.g. ``~/.aws/credentials``):
4747

@@ -57,7 +57,7 @@ Then, set up a default region (in e.g. ``~/.aws/config``):
5757
5858
[default]
5959
region=us-east-1
60-
60+
6161
Other credentials configuration method can be found `here <https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html>`__
6262

6363
Then, from a Python interpreter:
@@ -87,7 +87,7 @@ applicable for ``botocore``:
8787
Contributing
8888
------------
8989

90-
We value feedback and contributions from our community. Whether it's a bug report, new feature, correction, or additional documentation, we welcome your issues and pull requests. Please read through this `CONTRIBUTING <https://github.com/boto/botocore/blob/develop/CONTRIBUTING.rst>`__ document before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your contribution.
90+
We value feedback and contributions from our community. Whether it's a bug report, new feature, correction, or additional documentation, we welcome your issues and pull requests. Please read through this `CONTRIBUTING <https://github.com/boto/botocore/blob/develop/CONTRIBUTING.rst>`__ document before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your contribution.
9191

9292

9393
Maintenance and Support for SDK Major Versions
@@ -107,4 +107,3 @@ More Resources
107107
* `NOTICE <https://github.com/boto/botocore/blob/develop/NOTICE>`__
108108
* `Changelog <https://github.com/boto/botocore/blob/develop/CHANGELOG.rst>`__
109109
* `License <https://github.com/boto/botocore/blob/develop/LICENSE.txt>`__
110-

Diff for: botocore/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class NullHandler(logging.Handler):
2323
def emit(self, record):
2424
pass
2525

26+
2627
# Configure default logger to do nothing
2728
log = logging.getLogger('botocore')
2829
log.addHandler(NullHandler())

Diff for: botocore/args.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_client_args(self, service_model, region_name, is_secure,
7272
service_model, client_config, endpoint_bridge, region_name,
7373
endpoint_url, is_secure, scoped_config)
7474

75-
service_name = final_args['service_name']
75+
service_name = final_args['service_name'] # noqa
7676
parameter_validation = final_args['parameter_validation']
7777
endpoint_config = final_args['endpoint_config']
7878
protocol = final_args['protocol']

Diff for: botocore/auth.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@
1818
from email.utils import formatdate
1919
from hashlib import sha1, sha256
2020
import hmac
21-
from io import BytesIO
2221
import logging
2322
from operator import itemgetter
2423
import time
2524

26-
from botocore.compat import(
25+
from botocore.compat import (
2726
encodebytes, ensure_unicode, HTTPHeaders, json, parse_qs, quote,
28-
six, unquote, urlsplit, urlunsplit, HAS_CRT, MD5_AVAILABLE
27+
six, unquote, urlsplit, urlunsplit, HAS_CRT
2928
)
3029
from botocore.exceptions import NoCredentialsError
3130
from botocore.utils import normalize_url_path, percent_encode_sequence
3231

32+
# Imports for backwards compatibility
33+
from botocore.compat import MD5_AVAILABLE # noqa
34+
35+
3336
logger = logging.getLogger(__name__)
3437

3538

@@ -113,8 +116,9 @@ def calc_signature(self, request, params):
113116
if key == 'Signature':
114117
continue
115118
value = six.text_type(params[key])
116-
pairs.append(quote(key.encode('utf-8'), safe='') + '=' +
117-
quote(value.encode('utf-8'), safe='-_~'))
119+
quoted_key = quote(key.encode('utf-8'), safe='')
120+
quoted_value = quote(value.encode('utf-8'), safe='-_~')
121+
pairs.append(f'{quoted_key}={quoted_value}')
118122
qs = '&'.join(pairs)
119123
string_to_sign += qs
120124
logger.debug('String to sign: %s', string_to_sign)
@@ -275,9 +279,10 @@ def _header_value(self, value):
275279
return ' '.join(value.split())
276280

277281
def signed_headers(self, headers_to_sign):
278-
l = ['%s' % n.lower().strip() for n in set(headers_to_sign)]
279-
l = sorted(l)
280-
return ';'.join(l)
282+
headers = sorted(
283+
[n.lower().strip() for n in set(headers_to_sign)]
284+
)
285+
return ';'.join(headers)
281286

282287
def payload(self, request):
283288
if not self._should_sha256_sign_payload(request):
@@ -387,11 +392,11 @@ def add_auth(self, request):
387392
self._inject_signature_to_request(request, signature)
388393

389394
def _inject_signature_to_request(self, request, signature):
390-
l = ['AWS4-HMAC-SHA256 Credential=%s' % self.scope(request)]
395+
auth_str = ['AWS4-HMAC-SHA256 Credential=%s' % self.scope(request)]
391396
headers_to_sign = self.headers_to_sign(request)
392-
l.append('SignedHeaders=%s' % self.signed_headers(headers_to_sign))
393-
l.append('Signature=%s' % signature)
394-
request.headers['Authorization'] = ', '.join(l)
397+
auth_str.append('SignedHeaders=%s' % self.signed_headers(headers_to_sign))
398+
auth_str.append('Signature=%s' % signature)
399+
request.headers['Authorization'] = ', '.join(auth_str)
395400
return request
396401

397402
def _modify_request_before_signing(self, request):

Diff for: botocore/awsrequest.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
# ANY KIND, either express or implied. See the License for the specific
1313
# language governing permissions and limitations under the License.
1414
import io
15-
import sys
1615
import logging
1716
import functools
18-
import socket
1917

2018
import urllib3.util
2119
from urllib3.connection import VerifiedHTTPSConnection
@@ -25,8 +23,10 @@
2523

2624
import botocore.utils
2725
from botocore.compat import six
28-
from botocore.compat import HTTPHeaders, HTTPResponse, urlunsplit, urlsplit, \
29-
urlencode, MutableMapping
26+
from botocore.compat import (
27+
HTTPHeaders, HTTPResponse, urlunsplit, urlsplit,
28+
urlencode, MutableMapping
29+
)
3030
from botocore.exceptions import UnseekableStreamError
3131

3232

@@ -207,8 +207,10 @@ def _is_100_continue_status(self, maybe_status_line):
207207
parts = maybe_status_line.split(None, 2)
208208
# Check for HTTP/<version> 100 Continue\r\n
209209
return (
210-
len(parts) >= 3 and parts[0].startswith(b'HTTP/') and
211-
parts[1] == b'100')
210+
len(parts) >= 3
211+
and parts[0].startswith(b'HTTP/')
212+
and parts[1] == b'100'
213+
)
212214

213215

214216
class AWSHTTPConnection(AWSConnection, HTTPConnection):
@@ -400,7 +402,7 @@ def _determine_content_length(self, body):
400402
# Try asking the body for it's length
401403
try:
402404
return len(body)
403-
except (AttributeError, TypeError) as e:
405+
except (AttributeError, TypeError):
404406
pass
405407

406408
# Try getting the length from a seekable stream

Diff for: botocore/client.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
import logging
14-
import functools
1514

1615
from botocore import waiter, xform_name
1716
from botocore.args import ClientArgsCreator
@@ -20,9 +19,8 @@
2019
from botocore.docs.docstring import ClientMethodDocstring
2120
from botocore.docs.docstring import PaginatorDocstring
2221
from botocore.exceptions import (
23-
ClientError, DataNotFoundError, OperationNotPageableError,
24-
UnknownSignatureVersionError, InvalidEndpointDiscoveryConfigurationError,
25-
UnknownFIPSEndpointError,
22+
DataNotFoundError, OperationNotPageableError, UnknownSignatureVersionError,
23+
InvalidEndpointDiscoveryConfigurationError, UnknownFIPSEndpointError,
2624
)
2725
from botocore.hooks import first_non_none_response
2826
from botocore.model import ServiceModel
@@ -32,11 +30,6 @@
3230
S3ArnParamHandler, S3EndpointSetter, ensure_boolean,
3331
S3ControlArnParamHandler, S3ControlEndpointSetter,
3432
)
35-
from botocore.args import ClientArgsCreator
36-
from botocore import UNSIGNED
37-
# Keep this imported. There's pre-existing code that uses
38-
# "from botocore.client import Config".
39-
from botocore.config import Config
4033
from botocore.history import get_global_history_recorder
4134
from botocore.discovery import (
4235
EndpointDiscoveryHandler, EndpointDiscoveryManager,
@@ -45,6 +38,15 @@
4538
from botocore.retries import standard
4639
from botocore.retries import adaptive
4740

41+
# Keep these imported. There's pre-existing code that uses:
42+
# "from botocore.client import Config"
43+
# "from botocore.client import ClientError"
44+
# etc.
45+
from botocore.config import Config # noqa
46+
from botocore.exceptions import ClientError # noqa
47+
from botocore.args import ClientArgsCreator # noqa
48+
from botocore import UNSIGNED # noqa
49+
4850

4951
logger = logging.getLogger(__name__)
5052
history_recorder = get_global_history_recorder()
@@ -465,8 +467,9 @@ def _create_endpoint(self, resolved, service_name, region_name,
465467
else:
466468
# Use the sslCommonName over the hostname for Python 2.6 compat.
467469
hostname = resolved.get('sslCommonName', resolved.get('hostname'))
468-
endpoint_url = self._make_url(hostname, is_secure,
469-
resolved.get('protocols', []))
470+
endpoint_url = self._make_url(
471+
hostname, is_secure, resolved.get('protocols', [])
472+
)
470473
signature_version = self._resolve_signature_version(
471474
service_name, resolved)
472475
signing_name = self._resolve_signing_name(service_name, resolved)

Diff for: botocore/configprovider.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
# Note: These configurations are considered internal to botocore.
8989
# Do not use them until publicly documented.
9090
'csm_enabled': (
91-
'csm_enabled', 'AWS_CSM_ENABLED', False, utils.ensure_boolean),
91+
'csm_enabled', 'AWS_CSM_ENABLED', False, utils.ensure_boolean),
9292
'csm_host': ('csm_host', 'AWS_CSM_HOST', '127.0.0.1', None),
9393
'csm_port': ('csm_port', 'AWS_CSM_PORT', 31000, int),
9494
'csm_client_id': ('csm_client_id', 'AWS_CSM_CLIENT_ID', '', None),
@@ -145,6 +145,7 @@
145145
'proxy_use_forwarding_for_https', None, None, utils.normalize_boolean),
146146
}
147147

148+
148149
def create_botocore_default_config_mapping(session):
149150
chain_builder = ConfigChainFactory(session=session)
150151
config_mapping = _create_config_chain_mapping(

Diff for: botocore/credentials.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def _protected_refresh(self, is_mandatory):
529529
# the self._refresh_lock.
530530
try:
531531
metadata = self._refresh_using()
532-
except Exception as e:
532+
except Exception:
533533
period_name = 'mandatory' if is_mandatory else 'advisory'
534534
logger.warning("Refreshing temporary credentials failed "
535535
"during %s refresh period.",
@@ -1486,10 +1486,10 @@ def _get_role_config(self, profile_name):
14861486
}
14871487

14881488
if duration_seconds is not None:
1489-
try:
1490-
role_config['duration_seconds'] = int(duration_seconds)
1491-
except ValueError:
1492-
pass
1489+
try:
1490+
role_config['duration_seconds'] = int(duration_seconds)
1491+
except ValueError:
1492+
pass
14931493

14941494
# Either the credential source or the source profile must be
14951495
# specified, but not both.
@@ -1857,7 +1857,6 @@ def _retrieve_or_fail(self):
18571857
)
18581858

18591859
def _build_headers(self):
1860-
headers = {}
18611860
auth_token = self._environ.get(self.ENV_VAR_AUTH_TOKEN)
18621861
if auth_token is not None:
18631862
return {

Diff for: botocore/crt/auth.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from botocore.utils import percent_encode_sequence
1010
from botocore.exceptions import NoCredentialsError
1111

12+
1213
class CrtSigV4Auth(BaseSigner):
1314
REQUIRES_REGION = True
1415
_PRESIGNED_HEADERS_BLOCKLIST = [
@@ -73,7 +74,7 @@ def add_auth(self, request):
7374
signed_body_value=explicit_payload,
7475
signed_body_header_type=body_header,
7576
expiration_in_seconds=self._expiration_in_seconds,
76-
)
77+
)
7778
crt_request = self._crt_request_from_aws_request(request)
7879
future = awscrt.auth.aws_sign_request(crt_request, signing_config)
7980
future.result()
@@ -256,7 +257,7 @@ def add_auth(self, request):
256257
signed_body_value=explicit_payload,
257258
signed_body_header_type=body_header,
258259
expiration_in_seconds=self._expiration_in_seconds,
259-
)
260+
)
260261
crt_request = self._crt_request_from_aws_request(request)
261262
future = awscrt.auth.aws_sign_request(crt_request, signing_config)
262263
future.result()
@@ -374,6 +375,7 @@ def _should_add_content_sha256_header(self, explicit_payload):
374375
# Always add X-Amz-Content-SHA256 header
375376
return True
376377

378+
377379
class CrtSigV4AsymQueryAuth(CrtSigV4AsymAuth):
378380
DEFAULT_EXPIRES = 3600
379381
_SIGNATURE_TYPE = awscrt.auth.AwsSignatureType.HTTP_REQUEST_QUERY_PARAMS

Diff for: botocore/docs/client.py

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
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-
import inspect
14-
1513
from botocore.docs.utils import get_official_service_name
1614
from botocore.docs.method import document_custom_method
1715
from botocore.docs.method import document_model_driven_method

Diff for: botocore/docs/method.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def document_model_driven_method(section, method_name, operation_model,
180180
if operation_model.deprecated:
181181
method_intro_section.style.start_danger()
182182
method_intro_section.writeln(
183-
'This operation is deprecated and may not function as '
184-
'expected. This operation should not be used going forward '
185-
'and is only kept for the purpose of backwards compatiblity.')
183+
'This operation is deprecated and may not function as '
184+
'expected. This operation should not be used going forward '
185+
'and is only kept for the purpose of backwards compatiblity.')
186186
method_intro_section.style.end_danger()
187187
service_uid = operation_model.service_model.metadata.get('uid')
188188
if service_uid is not None:

Diff for: botocore/docs/service.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
from botocore.exceptions import DataNotFoundError
14-
from botocore.docs.utils import get_official_service_name
1514
from botocore.docs.client import ClientDocumenter
1615
from botocore.docs.client import ClientExceptionsDocumenter
1716
from botocore.docs.waiter import WaiterDocumenter

Diff for: botocore/endpoint.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def _send_request(self, request_dict, operation_model):
150150
'ResponseMetadata' in success_response[1]:
151151
# We want to share num retries, not num attempts.
152152
total_retries = attempts - 1
153-
success_response[1]['ResponseMetadata']['RetryAttempts'] = \
154-
total_retries
153+
success_response[1]['ResponseMetadata']['RetryAttempts'] = total_retries
155154
if exception is not None:
156155
raise exception
157156
else:

Diff for: botocore/eventstream.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def _parse_prelude(self):
464464
prelude = MessagePrelude(*raw_prelude)
465465
self._validate_prelude(prelude)
466466
# The minus 4 removes the prelude crc from the bytes to be checked
467-
_validate_checksum(prelude_bytes[:_PRELUDE_LENGTH-4], prelude.crc)
467+
_validate_checksum(prelude_bytes[:_PRELUDE_LENGTH - 4], prelude.crc)
468468
return prelude
469469

470470
def _parse_headers(self):
@@ -484,7 +484,7 @@ def _parse_message_crc(self):
484484

485485
def _parse_message_bytes(self):
486486
# The minus 4 includes the prelude crc to the bytes to be checked
487-
message_bytes = self._data[_PRELUDE_LENGTH-4:self._prelude.payload_end]
487+
message_bytes = self._data[_PRELUDE_LENGTH - 4:self._prelude.payload_end]
488488
return message_bytes
489489

490490
def _validate_message_crc(self):

0 commit comments

Comments
 (0)