Skip to content

Commit

Permalink
Fix flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed Oct 7, 2021
1 parent 12af573 commit 2acf1e6
Show file tree
Hide file tree
Showing 133 changed files with 2,257 additions and 2,004 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10098,4 +10098,3 @@ CHANGELOG
* feature:``EMR``: Added support for adding EBS storage to EMR instances.
* bugfix:pagination: Refactored pagination to handle non-string service tokens.
* bugfix:credentials: Fix race condition in credential provider.

1 change: 0 additions & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
opensource-codeofconduct@amazon.com with any additional questions or comments.

2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contributions as well:
fixed upstream.
* Changes to paginators, waiters, and endpoints are also generated upstream based on our internal knowledge of the AWS services.
These include any of the following files in ``botocore/data/``:

* ``_endpoints.json``
* ``*.paginators-1.json``
* ``*.waiters-2.json``
Expand Down
9 changes: 4 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ Assuming that you have Python and ``virtualenv`` installed, set up your environm
.. code-block:: sh
$ pip install botocore
Using Botocore
~~~~~~~~~~~~~~
After installing botocore
After installing botocore

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

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

Then, from a Python interpreter:
Expand Down Expand Up @@ -87,7 +87,7 @@ applicable for ``botocore``:
Contributing
------------

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.
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.


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

1 change: 1 addition & 0 deletions botocore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class NullHandler(logging.Handler):
def emit(self, record):
pass


# Configure default logger to do nothing
log = logging.getLogger('botocore')
log.addHandler(NullHandler())
Expand Down
2 changes: 1 addition & 1 deletion botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_client_args(self, service_model, region_name, is_secure,
service_model, client_config, endpoint_bridge, region_name,
endpoint_url, is_secure, scoped_config)

service_name = final_args['service_name']
service_name = final_args['service_name'] # noqa
parameter_validation = final_args['parameter_validation']
endpoint_config = final_args['endpoint_config']
protocol = final_args['protocol']
Expand Down
29 changes: 17 additions & 12 deletions botocore/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
from email.utils import formatdate
from hashlib import sha1, sha256
import hmac
from io import BytesIO
import logging
from operator import itemgetter
import time

from botocore.compat import(
from botocore.compat import (
encodebytes, ensure_unicode, HTTPHeaders, json, parse_qs, quote,
six, unquote, urlsplit, urlunsplit, HAS_CRT, MD5_AVAILABLE
six, unquote, urlsplit, urlunsplit, HAS_CRT
)
from botocore.exceptions import NoCredentialsError
from botocore.utils import normalize_url_path, percent_encode_sequence

# Imports for backwards compatibility
from botocore.compat import MD5_AVAILABLE # noqa


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -113,8 +116,9 @@ def calc_signature(self, request, params):
if key == 'Signature':
continue
value = six.text_type(params[key])
pairs.append(quote(key.encode('utf-8'), safe='') + '=' +
quote(value.encode('utf-8'), safe='-_~'))
quoted_key = quote(key.encode('utf-8'), safe='')
quoted_value = quote(value.encode('utf-8'), safe='-_~')
pairs.append(f'{quoted_key}={quoted_value}')
qs = '&'.join(pairs)
string_to_sign += qs
logger.debug('String to sign: %s', string_to_sign)
Expand Down Expand Up @@ -275,9 +279,10 @@ def _header_value(self, value):
return ' '.join(value.split())

def signed_headers(self, headers_to_sign):
l = ['%s' % n.lower().strip() for n in set(headers_to_sign)]
l = sorted(l)
return ';'.join(l)
headers = sorted(
[n.lower().strip() for n in set(headers_to_sign)]
)
return ';'.join(headers)

def payload(self, request):
if not self._should_sha256_sign_payload(request):
Expand Down Expand Up @@ -387,11 +392,11 @@ def add_auth(self, request):
self._inject_signature_to_request(request, signature)

def _inject_signature_to_request(self, request, signature):
l = ['AWS4-HMAC-SHA256 Credential=%s' % self.scope(request)]
auth_str = ['AWS4-HMAC-SHA256 Credential=%s' % self.scope(request)]
headers_to_sign = self.headers_to_sign(request)
l.append('SignedHeaders=%s' % self.signed_headers(headers_to_sign))
l.append('Signature=%s' % signature)
request.headers['Authorization'] = ', '.join(l)
auth_str.append('SignedHeaders=%s' % self.signed_headers(headers_to_sign))
auth_str.append('Signature=%s' % signature)
request.headers['Authorization'] = ', '.join(auth_str)
return request

def _modify_request_before_signing(self, request):
Expand Down
16 changes: 9 additions & 7 deletions botocore/awsrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import io
import sys
import logging
import functools
import socket

import urllib3.util
from urllib3.connection import VerifiedHTTPSConnection
Expand All @@ -25,8 +23,10 @@

import botocore.utils
from botocore.compat import six
from botocore.compat import HTTPHeaders, HTTPResponse, urlunsplit, urlsplit, \
urlencode, MutableMapping
from botocore.compat import (
HTTPHeaders, HTTPResponse, urlunsplit, urlsplit,
urlencode, MutableMapping
)
from botocore.exceptions import UnseekableStreamError


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


class AWSHTTPConnection(AWSConnection, HTTPConnection):
Expand Down Expand Up @@ -400,7 +402,7 @@ def _determine_content_length(self, body):
# Try asking the body for it's length
try:
return len(body)
except (AttributeError, TypeError) as e:
except (AttributeError, TypeError):
pass

# Try getting the length from a seekable stream
Expand Down
25 changes: 14 additions & 11 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import logging
import functools

from botocore import waiter, xform_name
from botocore.args import ClientArgsCreator
Expand All @@ -20,9 +19,8 @@
from botocore.docs.docstring import ClientMethodDocstring
from botocore.docs.docstring import PaginatorDocstring
from botocore.exceptions import (
ClientError, DataNotFoundError, OperationNotPageableError,
UnknownSignatureVersionError, InvalidEndpointDiscoveryConfigurationError,
UnknownFIPSEndpointError,
DataNotFoundError, OperationNotPageableError, UnknownSignatureVersionError,
InvalidEndpointDiscoveryConfigurationError, UnknownFIPSEndpointError,
)
from botocore.hooks import first_non_none_response
from botocore.model import ServiceModel
Expand All @@ -32,11 +30,6 @@
S3ArnParamHandler, S3EndpointSetter, ensure_boolean,
S3ControlArnParamHandler, S3ControlEndpointSetter,
)
from botocore.args import ClientArgsCreator
from botocore import UNSIGNED
# Keep this imported. There's pre-existing code that uses
# "from botocore.client import Config".
from botocore.config import Config
from botocore.history import get_global_history_recorder
from botocore.discovery import (
EndpointDiscoveryHandler, EndpointDiscoveryManager,
Expand All @@ -45,6 +38,15 @@
from botocore.retries import standard
from botocore.retries import adaptive

# Keep these imported. There's pre-existing code that uses:
# "from botocore.client import Config"
# "from botocore.client import ClientError"
# etc.
from botocore.config import Config # noqa
from botocore.exceptions import ClientError # noqa
from botocore.args import ClientArgsCreator # noqa
from botocore import UNSIGNED # noqa


logger = logging.getLogger(__name__)
history_recorder = get_global_history_recorder()
Expand Down Expand Up @@ -465,8 +467,9 @@ def _create_endpoint(self, resolved, service_name, region_name,
else:
# Use the sslCommonName over the hostname for Python 2.6 compat.
hostname = resolved.get('sslCommonName', resolved.get('hostname'))
endpoint_url = self._make_url(hostname, is_secure,
resolved.get('protocols', []))
endpoint_url = self._make_url(
hostname, is_secure, resolved.get('protocols', [])
)
signature_version = self._resolve_signature_version(
service_name, resolved)
signing_name = self._resolve_signing_name(service_name, resolved)
Expand Down
3 changes: 2 additions & 1 deletion botocore/configprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
# Note: These configurations are considered internal to botocore.
# Do not use them until publicly documented.
'csm_enabled': (
'csm_enabled', 'AWS_CSM_ENABLED', False, utils.ensure_boolean),
'csm_enabled', 'AWS_CSM_ENABLED', False, utils.ensure_boolean),
'csm_host': ('csm_host', 'AWS_CSM_HOST', '127.0.0.1', None),
'csm_port': ('csm_port', 'AWS_CSM_PORT', 31000, int),
'csm_client_id': ('csm_client_id', 'AWS_CSM_CLIENT_ID', '', None),
Expand Down Expand Up @@ -145,6 +145,7 @@
'proxy_use_forwarding_for_https', None, None, utils.normalize_boolean),
}


def create_botocore_default_config_mapping(session):
chain_builder = ConfigChainFactory(session=session)
config_mapping = _create_config_chain_mapping(
Expand Down
11 changes: 5 additions & 6 deletions botocore/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def _protected_refresh(self, is_mandatory):
# the self._refresh_lock.
try:
metadata = self._refresh_using()
except Exception as e:
except Exception:
period_name = 'mandatory' if is_mandatory else 'advisory'
logger.warning("Refreshing temporary credentials failed "
"during %s refresh period.",
Expand Down Expand Up @@ -1486,10 +1486,10 @@ def _get_role_config(self, profile_name):
}

if duration_seconds is not None:
try:
role_config['duration_seconds'] = int(duration_seconds)
except ValueError:
pass
try:
role_config['duration_seconds'] = int(duration_seconds)
except ValueError:
pass

# Either the credential source or the source profile must be
# specified, but not both.
Expand Down Expand Up @@ -1857,7 +1857,6 @@ def _retrieve_or_fail(self):
)

def _build_headers(self):
headers = {}
auth_token = self._environ.get(self.ENV_VAR_AUTH_TOKEN)
if auth_token is not None:
return {
Expand Down
6 changes: 4 additions & 2 deletions botocore/crt/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from botocore.utils import percent_encode_sequence
from botocore.exceptions import NoCredentialsError


class CrtSigV4Auth(BaseSigner):
REQUIRES_REGION = True
_PRESIGNED_HEADERS_BLOCKLIST = [
Expand Down Expand Up @@ -73,7 +74,7 @@ def add_auth(self, request):
signed_body_value=explicit_payload,
signed_body_header_type=body_header,
expiration_in_seconds=self._expiration_in_seconds,
)
)
crt_request = self._crt_request_from_aws_request(request)
future = awscrt.auth.aws_sign_request(crt_request, signing_config)
future.result()
Expand Down Expand Up @@ -256,7 +257,7 @@ def add_auth(self, request):
signed_body_value=explicit_payload,
signed_body_header_type=body_header,
expiration_in_seconds=self._expiration_in_seconds,
)
)
crt_request = self._crt_request_from_aws_request(request)
future = awscrt.auth.aws_sign_request(crt_request, signing_config)
future.result()
Expand Down Expand Up @@ -374,6 +375,7 @@ def _should_add_content_sha256_header(self, explicit_payload):
# Always add X-Amz-Content-SHA256 header
return True


class CrtSigV4AsymQueryAuth(CrtSigV4AsymAuth):
DEFAULT_EXPIRES = 3600
_SIGNATURE_TYPE = awscrt.auth.AwsSignatureType.HTTP_REQUEST_QUERY_PARAMS
Expand Down
2 changes: 0 additions & 2 deletions botocore/docs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +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 inspect

from botocore.docs.utils import get_official_service_name
from botocore.docs.method import document_custom_method
from botocore.docs.method import document_model_driven_method
Expand Down
6 changes: 3 additions & 3 deletions botocore/docs/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def document_model_driven_method(section, method_name, operation_model,
if operation_model.deprecated:
method_intro_section.style.start_danger()
method_intro_section.writeln(
'This operation is deprecated and may not function as '
'expected. This operation should not be used going forward '
'and is only kept for the purpose of backwards compatiblity.')
'This operation is deprecated and may not function as '
'expected. This operation should not be used going forward '
'and is only kept for the purpose of backwards compatiblity.')
method_intro_section.style.end_danger()
service_uid = operation_model.service_model.metadata.get('uid')
if service_uid is not None:
Expand Down
1 change: 0 additions & 1 deletion botocore/docs/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from botocore.exceptions import DataNotFoundError
from botocore.docs.utils import get_official_service_name
from botocore.docs.client import ClientDocumenter
from botocore.docs.client import ClientExceptionsDocumenter
from botocore.docs.waiter import WaiterDocumenter
Expand Down
3 changes: 1 addition & 2 deletions botocore/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def _send_request(self, request_dict, operation_model):
'ResponseMetadata' in success_response[1]:
# We want to share num retries, not num attempts.
total_retries = attempts - 1
success_response[1]['ResponseMetadata']['RetryAttempts'] = \
total_retries
success_response[1]['ResponseMetadata']['RetryAttempts'] = total_retries
if exception is not None:
raise exception
else:
Expand Down
4 changes: 2 additions & 2 deletions botocore/eventstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def _parse_prelude(self):
prelude = MessagePrelude(*raw_prelude)
self._validate_prelude(prelude)
# The minus 4 removes the prelude crc from the bytes to be checked
_validate_checksum(prelude_bytes[:_PRELUDE_LENGTH-4], prelude.crc)
_validate_checksum(prelude_bytes[:_PRELUDE_LENGTH - 4], prelude.crc)
return prelude

def _parse_headers(self):
Expand All @@ -484,7 +484,7 @@ def _parse_message_crc(self):

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

def _validate_message_crc(self):
Expand Down
Loading

0 comments on commit 2acf1e6

Please sign in to comment.