Skip to content

Commit

Permalink
Use --unsafe-fixes for older formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed Jun 14, 2024
1 parent 5b9a349 commit bddb739
Show file tree
Hide file tree
Showing 77 changed files with 438 additions and 399 deletions.
2 changes: 1 addition & 1 deletion botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _get_sts_regional_endpoints_config(self):

def _set_global_sts_endpoint(self, endpoint_config, is_secure):
scheme = 'https' if is_secure else 'http'
endpoint_config['endpoint_url'] = '%s://sts.amazonaws.com' % scheme
endpoint_config['endpoint_url'] = f'{scheme}://sts.amazonaws.com'
endpoint_config['signing_region'] = 'us-east-1'

def _resolve_endpoint(
Expand Down
12 changes: 6 additions & 6 deletions botocore/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,12 @@ def add_auth(self, request):
self._inject_signature_to_request(request, signature)

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

Expand Down Expand Up @@ -685,7 +685,7 @@ def _inject_signature_to_request(self, request, signature):
# Rather than calculating an "Authorization" header, for the query
# param quth, we just append an 'X-Amz-Signature' param to the end
# of the query string.
request.url += '&X-Amz-Signature=%s' % signature
request.url += f'&X-Amz-Signature={signature}'

def _normalize_url_path(self, path):
# For S3, we do not normalize the path.
Expand Down Expand Up @@ -777,7 +777,7 @@ def _inject_signature_to_request(self, request, signature):
# Rather than calculating an "Authorization" header, for the query
# param quth, we just append an 'X-Amz-Signature' param to the end
# of the query string.
request.url += '&X-Amz-Signature=%s' % signature
request.url += f'&X-Amz-Signature={signature}'


class S3SigV4QueryAuth(SigV4QueryAuth):
Expand Down Expand Up @@ -990,15 +990,15 @@ def get_signature(
string_to_sign = self.canonical_string(
method, split, headers, auth_path=auth_path
)
logger.debug('StringToSign:\n%s', string_to_sign)
logger.debug(f'StringToSign:\n{string_to_sign}')
return self.sign_string(string_to_sign)

def add_auth(self, request):
if self.credentials is None:
raise NoCredentialsError
logger.debug("Calculating signature using hmacv1 auth.")
split = urlsplit(request.url)
logger.debug('HTTP request method: %s', request.method)
logger.debug(f'HTTP request method: {request.method}')
signature = self.get_signature(
request.method, split, request.headers, auth_path=request.auth_path
)
Expand Down
4 changes: 2 additions & 2 deletions botocore/awsrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def prepare_request_dict(
percent_encode_sequence = botocore.utils.percent_encode_sequence
encoded_query_string = percent_encode_sequence(r['query_string'])
if '?' not in url:
url += '?%s' % encoded_query_string
url += f'?{encoded_query_string}'
else:
url += '&%s' % encoded_query_string
url += f'&{encoded_query_string}'
r['url'] = url
r['context'] = context
if context is None:
Expand Down
14 changes: 7 additions & 7 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _create_client_class(self, service_name, service_model):
bases = [BaseClient]
service_id = service_model.service_id.hyphenize()
self._event_emitter.emit(
'creating-client-class.%s' % service_id,
f'creating-client-class.{service_id}',
class_attributes=class_attributes,
base_classes=bases,
)
Expand All @@ -223,10 +223,10 @@ def _normalize_fips_region(self, region_name, client_config):
else:
client_config = config_use_fips_endpoint
logger.warning(
'transforming region from %s to %s and setting '
f'transforming region from {region_name} to '
f'{normalized_region_name} and setting '
'use_fips_endpoint to true. client should not '
'be configured with a fips psuedo region.'
% (region_name, normalized_region_name)
)
region_name = normalized_region_name
return region_name, client_config
Expand Down Expand Up @@ -289,7 +289,7 @@ def _register_legacy_retries(self, client):
handler = self._retry_handler_factory.create_retry_handler(
retry_config, endpoint_prefix
)
unique_id = 'retry-config-%s' % service_event_name
unique_id = f'retry-config-{service_event_name}'
client.meta.events.register(
f"needs-retry.{service_event_name}", handler, unique_id=unique_id
)
Expand Down Expand Up @@ -573,7 +573,7 @@ def _api_call(self, *args, **kwargs):
method_name=operation_name,
event_emitter=self._event_emitter,
method_description=operation_model.documentation,
example_prefix='response = client.%s' % py_operation_name,
example_prefix=f'response = client.{py_operation_name}',
include_signature=False,
)
_api_call.__doc__ = docstring
Expand Down Expand Up @@ -1252,13 +1252,13 @@ def get_waiter(self, waiter_name):
"""
config = self._get_waiter_config()
if not config:
raise ValueError("Waiter does not exist: %s" % waiter_name)
raise ValueError(f"Waiter does not exist: {waiter_name}")
model = waiter.WaiterModel(config)
mapping = {}
for name in model.waiter_names:
mapping[xform_name(name)] = name
if waiter_name not in mapping:
raise ValueError("Waiter does not exist: %s" % waiter_name)
raise ValueError(f"Waiter does not exist: {waiter_name}")

return waiter.create_waiter_with_client(
mapping[waiter_name], model, self
Expand Down
4 changes: 2 additions & 2 deletions botocore/configprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def _convert_type(self, value):
return value

def __repr__(self):
return '[%s]' % ', '.join([str(p) for p in self._providers])
return '[{}]'.format(', '.join([str(p) for p in self._providers]))


class InstanceVarProvider(BaseProvider):
Expand Down Expand Up @@ -873,7 +873,7 @@ def provide(self):
return self._value

def __repr__(self):
return 'ConstantProvider(value=%s)' % self._value
return f'ConstantProvider(value={self._value})'


class ConfiguredEndpointProvider(BaseProvider):
Expand Down
14 changes: 7 additions & 7 deletions botocore/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def __init__(
super().__init__(cache, expiry_window_seconds)

def _generate_assume_role_name(self):
self._role_session_name = 'botocore-session-%s' % (int(time.time()))
self._role_session_name = f'botocore-session-{int(time.time())}'
self._assume_kwargs['RoleSessionName'] = self._role_session_name
self._using_default_session_name = True

Expand Down Expand Up @@ -848,7 +848,7 @@ def _assume_role_kwargs(self):
mfa_serial = assume_role_kwargs.get('SerialNumber')

if mfa_serial is not None:
prompt = 'Enter MFA code for %s: ' % mfa_serial
prompt = f'Enter MFA code for {mfa_serial}: '
token_code = self._mfa_prompter(prompt)
assume_role_kwargs['TokenCode'] = token_code

Expand Down Expand Up @@ -1570,8 +1570,8 @@ def _get_role_config(self, profile_name):
if credential_source is not None and source_profile is not None:
raise InvalidConfigError(
error_msg=(
'The profile "%s" contains both source_profile and '
'credential_source.' % profile_name
f'The profile "{profile_name}" contains both '
'source_profile and credential_source.'
)
)
elif credential_source is None and source_profile is None:
Expand Down Expand Up @@ -1720,7 +1720,7 @@ def _resolve_credentials_from_source(
provider=credential_source,
error_msg=(
'No credentials found in credential_source referenced '
'in profile %s' % profile_name
f'in profile {profile_name}'
),
)
return credentials
Expand Down Expand Up @@ -2242,8 +2242,8 @@ def _load_sso_config(self):
missing = ', '.join(missing_config_vars)
raise InvalidConfigError(
error_msg=(
'The profile "%s" is configured to use SSO but is missing '
'required configuration: %s' % (profile_name, missing)
f'The profile "{profile_name}" is configured to use SSO '
f'but is missing required configuration: {missing}'
)
)
return config
Expand Down
9 changes: 4 additions & 5 deletions botocore/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ def describe_endpoint(self, **kwargs):
if not self._always_discover and not discovery_required:
# Discovery set to only run on required operations
logger.debug(
'Optional discovery disabled. Skipping discovery for Operation: %s'
% operation
f'Optional discovery disabled. Skipping discovery for Operation: {operation}'
)
return None

Expand Down Expand Up @@ -228,12 +227,12 @@ def __init__(self, manager):

def register(self, events, service_id):
events.register(
'before-parameter-build.%s' % service_id, self.gather_identifiers
f'before-parameter-build.{service_id}', self.gather_identifiers
)
events.register_first(
'request-created.%s' % service_id, self.discover_endpoint
f'request-created.{service_id}', self.discover_endpoint
)
events.register('needs-retry.%s' % service_id, self.handle_retries)
events.register(f'needs-retry.{service_id}', self.handle_retries)

def gather_identifiers(self, params, model, context, **kwargs):
endpoint_discovery = model.endpoint_discovery
Expand Down
10 changes: 5 additions & 5 deletions botocore/docs/bcdoc/docstringparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def add_tag(self, tag, attrs=None, is_start=True):

def _doc_has_handler(self, tag, is_start):
if is_start:
handler_name = 'start_%s' % tag
handler_name = f'start_{tag}'
else:
handler_name = 'end_%s' % tag
handler_name = f'end_{tag}'

return hasattr(self.doc.style, handler_name)

Expand Down Expand Up @@ -226,12 +226,12 @@ def collapse_whitespace(self):
child.collapse_whitespace()

def _write_start(self, doc):
handler_name = 'start_%s' % self.tag
handler_name = f'start_{self.tag}'
if hasattr(doc.style, handler_name):
getattr(doc.style, handler_name)(self.attrs)

def _write_end(self, doc, next_child):
handler_name = 'end_%s' % self.tag
handler_name = f'end_{self.tag}'
if hasattr(doc.style, handler_name):
if handler_name == 'end_a':
# We use lookahead to determine if a space is needed after a link node
Expand All @@ -248,7 +248,7 @@ class DataNode(Node):
def __init__(self, data, parent=None):
super().__init__(parent)
if not isinstance(data, str):
raise ValueError("Expecting string type, %s given." % type(data))
raise ValueError(f"Expecting string type, {type(data)} given.")
self._leading_whitespace = ''
self._trailing_whitespace = ''
self._stripped_data = ''
Expand Down
28 changes: 14 additions & 14 deletions botocore/docs/bcdoc/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def indentation(self, value):
self._indent = value

def new_paragraph(self):
return '\n%s' % self.spaces()
return f'\n{self.spaces()}'

def indent(self):
self._indent += 1
Expand Down Expand Up @@ -83,10 +83,10 @@ def __init__(self, doc, indent_width=2):
self.list_depth = 0

def new_paragraph(self):
self.doc.write('\n\n%s' % self.spaces())
self.doc.write(f'\n\n{self.spaces()}')

def new_line(self):
self.doc.write('\n%s' % self.spaces())
self.doc.write(f'\n{self.spaces()}')

def _start_inline(self, markup):
# Insert space between any directly adjacent bold and italic inlines to
Expand Down Expand Up @@ -165,11 +165,11 @@ def italics(self, s):

def start_p(self, attrs=None):
if self.do_p:
self.doc.write('\n\n%s' % self.spaces())
self.doc.write(f'\n\n{self.spaces()}')

def end_p(self):
if self.do_p:
self.doc.write('\n\n%s' % self.spaces())
self.doc.write(f'\n\n{self.spaces()}')

def start_code(self, attrs=None):
self.doc.do_translation = True
Expand Down Expand Up @@ -268,14 +268,14 @@ def end_a(self, next_child=None):
if ':' in last_write:
last_write = last_write.replace(':', r'\:')
self.doc.push_write(last_write)
self.doc.push_write(' <%s>`__' % self.a_href)
self.doc.push_write(f' <{self.a_href}>`__')
elif last_write == '`':
# Look at start_a(). It will do a self.doc.write('`')
# which is the start of the link title. If that is the
# case then there was no link text. We should just
# use an inline link. The syntax of this is
# `<http://url>`_
self.doc.push_write('`<%s>`__' % self.a_href)
self.doc.push_write(f'`<{self.a_href}>`__')
else:
self.doc.push_write(self.a_href)
self.doc.hrefs[self.a_href] = self.a_href
Expand Down Expand Up @@ -375,9 +375,9 @@ def tocitem(self, item, file_name=None):
self.li(item)
else:
if file_name:
self.doc.writeln(' %s' % file_name)
self.doc.writeln(f' {file_name}')
else:
self.doc.writeln(' %s' % item)
self.doc.writeln(f' {item}')

def hidden_toctree(self):
if self.doc.target == 'html':
Expand All @@ -394,11 +394,11 @@ def table_of_contents(self, title=None, depth=None):
if title is not None:
self.doc.writeln(title)
if depth is not None:
self.doc.writeln(' :depth: %s' % depth)
self.doc.writeln(f' :depth: {depth}')

def start_sphinx_py_class(self, class_name):
self.new_paragraph()
self.doc.write('.. py:class:: %s' % class_name)
self.doc.write(f'.. py:class:: {class_name}')
self.indent()
self.new_paragraph()

Expand All @@ -408,9 +408,9 @@ def end_sphinx_py_class(self):

def start_sphinx_py_method(self, method_name, parameters=None):
self.new_paragraph()
content = '.. py:method:: %s' % method_name
content = f'.. py:method:: {method_name}'
if parameters is not None:
content += '(%s)' % parameters
content += f'({parameters})'
self.doc.write(content)
self.indent()
self.new_paragraph()
Expand All @@ -421,7 +421,7 @@ def end_sphinx_py_method(self):

def start_sphinx_py_attr(self, attr_name):
self.new_paragraph()
self.doc.write('.. py:attribute:: %s' % attr_name)
self.doc.write(f'.. py:attribute:: {attr_name}')
self.indent()
self.new_paragraph()

Expand Down
6 changes: 3 additions & 3 deletions botocore/docs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ def _add_method_exceptions_list(self, section, operation_model):
class_name = (
f'{self._client_class_name}.Client.exceptions.{error.name}'
)
error_section.style.li(':py:class:`%s`' % class_name)
error_section.style.li(f':py:class:`{class_name}`')

def _add_model_driven_method(self, section, method_name):
service_model = self._client.meta.service_model
operation_name = self._client.meta.method_to_api_mapping[method_name]
operation_model = service_model.operation_model(operation_name)

example_prefix = 'response = client.%s' % method_name
example_prefix = f'response = client.{method_name}'
full_method_name = (
f"{section.context.get('qualifier', '')}{method_name}"
)
Expand Down Expand Up @@ -342,7 +342,7 @@ def _add_exception_catch_example(self, section, shape):
section.write('...')
section.style.dedent()
section.style.new_line()
section.write('except client.exceptions.%s as e:' % shape.name)
section.write(f'except client.exceptions.{shape.name} as e:')
section.style.indent()
section.style.new_line()
section.write('print(e.response)')
Expand Down
Loading

0 comments on commit bddb739

Please sign in to comment.