From a92924197f0aba0d723df9273986b30af9dd6faa Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Wed, 23 Mar 2022 16:06:25 -0600 Subject: [PATCH] Fix remaining f-strings --- requests/adapters.py | 9 ++++----- requests/auth.py | 10 +++++----- requests/cookies.py | 4 ++-- requests/help.py | 4 ++-- requests/models.py | 14 ++++++-------- requests/status_codes.py | 2 +- requests/structures.py | 2 +- requests/utils.py | 4 ++-- 8 files changed, 23 insertions(+), 26 deletions(-) diff --git a/requests/adapters.py b/requests/adapters.py index 995a37760c..d4420c665c 100644 --- a/requests/adapters.py +++ b/requests/adapters.py @@ -195,7 +195,7 @@ def init_poolmanager( maxsize=maxsize, block=block, strict=True, - **pool_kwargs + **pool_kwargs, ) def proxy_manager_for(self, proxy, **proxy_kwargs): @@ -221,7 +221,7 @@ def proxy_manager_for(self, proxy, **proxy_kwargs): num_pools=self._pool_connections, maxsize=self._pool_maxsize, block=self._pool_block, - **proxy_kwargs + **proxy_kwargs, ) else: proxy_headers = self.proxy_headers(proxy) @@ -231,7 +231,7 @@ def proxy_manager_for(self, proxy, **proxy_kwargs): num_pools=self._pool_connections, maxsize=self._pool_maxsize, block=self._pool_block, - **proxy_kwargs + **proxy_kwargs, ) return manager @@ -290,8 +290,7 @@ def cert_verify(self, conn, url, verify, cert): ) if conn.key_file and not os.path.exists(conn.key_file): raise IOError( - "Could not find the TLS key file, " - "invalid path: {}".format(conn.key_file) + f"Could not find the TLS key file, invalid path: {conn.key_file}" ) def build_response(self, req, resp): diff --git a/requests/auth.py b/requests/auth.py index 526db43819..a0007eb1c3 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -196,7 +196,7 @@ def sha512_utf8(x): self._thread_local.nonce_count += 1 else: self._thread_local.nonce_count = 1 - ncvalue = "%08x" % self._thread_local.nonce_count + ncvalue = f"{self._thread_local.nonce_count:08x}" s = str(self._thread_local.nonce_count).encode("utf-8") s += nonce.encode("utf-8") s += time.ctime().encode("utf-8") @@ -226,15 +226,15 @@ def sha512_utf8(x): respdig, ) if opaque: - base += ', opaque="%s"' % opaque + base += f', opaque="{opaque}"' if algorithm: - base += ', algorithm="%s"' % algorithm + base += f', algorithm="{algorithm}"' if entdig: - base += ', digest="%s"' % entdig + base += f', digest="{entdig}"' if qop: base += f', qop="auth", nc={ncvalue}, cnonce="{cnonce}"' - return "Digest %s" % (base) + return f"Digest {base}" def handle_redirect(self, r, **kwargs): """Reset num_401_calls counter on redirects.""" diff --git a/requests/cookies.py b/requests/cookies.py index 8d4cf799fb..59e71f87fc 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -404,7 +404,7 @@ def _find_no_duplicates(self, name, domain=None, path=None): toReturn is not None ): # if there are multiple cookies that meet passed in criteria raise CookieConflictError( - "There are multiple cookies with name, %r" % (name) + f"There are multiple cookies with name, {name!r}" ) toReturn = ( cookie.value @@ -498,7 +498,7 @@ def morsel_to_cookie(morsel): try: expires = int(time.time() + int(morsel["max-age"])) except ValueError: - raise TypeError("max-age: %s must be integer" % morsel["max-age"]) + raise TypeError(f"max-age: {morsel['max-age']} must be integer") elif morsel["expires"]: time_template = "%a, %d-%b-%Y %H:%M:%S GMT" expires = calendar.timegm(time.strptime(morsel["expires"], time_template)) diff --git a/requests/help.py b/requests/help.py index 809738c83e..363229cc3c 100644 --- a/requests/help.py +++ b/requests/help.py @@ -95,7 +95,7 @@ def info(): if OpenSSL: pyopenssl_info = { "version": OpenSSL.__version__, - "openssl_version": "%x" % OpenSSL.SSL.OPENSSL_VERSION_NUMBER, + "openssl_version": f"{OpenSSL.SSL.OPENSSL_VERSION_NUMBER:x}", } cryptography_info = { "version": getattr(cryptography, "__version__", ""), @@ -105,7 +105,7 @@ def info(): } system_ssl = ssl.OPENSSL_VERSION_NUMBER - system_ssl_info = {"version": "%x" % system_ssl if system_ssl is not None else ""} + system_ssl_info = {"version": f"{system_ssl:x}" if system_ssl is not None else ""} return { "platform": platform_info, diff --git a/requests/models.py b/requests/models.py index b123469052..135a6d413b 100644 --- a/requests/models.py +++ b/requests/models.py @@ -208,9 +208,7 @@ def register_hook(self, event, hook): """Properly register a hook.""" if event not in self.hooks: - raise ValueError( - 'Unsupported event specified, with event name "%s"' % (event) - ) + raise ValueError(f'Unsupported event specified, with event name "{event}"') if isinstance(hook, Callable): self.hooks[event].append(hook) @@ -293,7 +291,7 @@ def __init__( self.cookies = cookies def __repr__(self): - return "" % (self.method) + return f"" def prepare(self): """Constructs a :class:`PreparedRequest ` for transmission and returns it.""" @@ -380,7 +378,7 @@ def prepare( self.prepare_hooks(hooks) def __repr__(self): - return "" % (self.method) + return f"" def copy(self): p = PreparedRequest() @@ -446,7 +444,7 @@ def prepare_url(self, url, params): raise MissingSchema(error) if not host: - raise InvalidURL("Invalid URL %r: No host supplied" % url) + raise InvalidURL(f"Invalid URL {url!r}: No host supplied") # In general, we want to try IDNA encoding the hostname if the string contains # non-ASCII characters. This allows users to automatically get the correct IDNA @@ -730,7 +728,7 @@ def __setstate__(self, state): setattr(self, "raw", None) def __repr__(self): - return "" % (self.status_code) + return f"" def __bool__(self): """Returns True if :attr:`status_code` is less than 400. @@ -841,7 +839,7 @@ def generate(): raise StreamConsumedError() elif chunk_size is not None and not isinstance(chunk_size, int): raise TypeError( - "chunk_size must be an int, it is instead a %s." % type(chunk_size) + f"chunk_size must be an int, it is instead a {type(chunk_size)}." ) # simulate reading small chunks of the content reused_chunks = iter_slices(self._content, chunk_size) diff --git a/requests/status_codes.py b/requests/status_codes.py index e10feeca80..2c7e483a7e 100644 --- a/requests/status_codes.py +++ b/requests/status_codes.py @@ -114,7 +114,7 @@ def _init(): setattr(codes, title.upper(), code) def doc(code): - names = ", ".join("``%s``" % n for n in _codes[code]) + names = ", ".join(f"``{n}``" for n in _codes[code]) return "* %d: %s" % (code, names) global __doc__ diff --git a/requests/structures.py b/requests/structures.py index 0c37ada0a2..188e13e482 100644 --- a/requests/structures.py +++ b/requests/structures.py @@ -88,7 +88,7 @@ def __init__(self, name=None): super().__init__() def __repr__(self): - return "" % (self.name) + return f"" def __getitem__(self, key): # We allow fall-through here, so values default to None diff --git a/requests/utils.py b/requests/utils.py index d122e08729..5a51ab8d34 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -641,7 +641,7 @@ def unquote_unreserved(uri): try: c = chr(int(h, 16)) except ValueError: - raise InvalidURL("Invalid percent-escape sequence: '%s'" % h) + raise InvalidURL(f"Invalid percent-escape sequence: '{h}'") if c in UNRESERVED_SET: parts[i] = c + parts[i][2:] @@ -1045,7 +1045,7 @@ def check_header_validity(header): try: if not pat.match(value): raise InvalidHeader( - "Invalid return character or leading space in header: %s" % name + f"Invalid return character or leading space in header: {name}" ) except TypeError: raise InvalidHeader(