Skip to content

Commit

Permalink
Fix remaining f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed Mar 23, 2022
1 parent bd78cb7 commit a929241
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 26 deletions.
9 changes: 4 additions & 5 deletions requests/adapters.py
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions requests/auth.py
Expand Up @@ -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")
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions requests/cookies.py
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions requests/help.py
Expand Up @@ -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__", ""),
Expand All @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions requests/models.py
Expand Up @@ -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)
Expand Down Expand Up @@ -293,7 +291,7 @@ def __init__(
self.cookies = cookies

def __repr__(self):
return "<Request [%s]>" % (self.method)
return f"<Request [{self.method}]>"

def prepare(self):
"""Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it."""
Expand Down Expand Up @@ -380,7 +378,7 @@ def prepare(
self.prepare_hooks(hooks)

def __repr__(self):
return "<PreparedRequest [%s]>" % (self.method)
return f"<PreparedRequest [{self.method}]>"

def copy(self):
p = PreparedRequest()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -730,7 +728,7 @@ def __setstate__(self, state):
setattr(self, "raw", None)

def __repr__(self):
return "<Response [%s]>" % (self.status_code)
return f"<Response [{self.status_code}]>"

def __bool__(self):
"""Returns True if :attr:`status_code` is less than 400.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion requests/status_codes.py
Expand Up @@ -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__
Expand Down
2 changes: 1 addition & 1 deletion requests/structures.py
Expand Up @@ -88,7 +88,7 @@ def __init__(self, name=None):
super().__init__()

def __repr__(self):
return "<lookup '%s'>" % (self.name)
return f"<lookup '{self.name}'>"

def __getitem__(self, key):
# We allow fall-through here, so values default to None
Expand Down
4 changes: 2 additions & 2 deletions requests/utils.py
Expand Up @@ -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:]
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a929241

Please sign in to comment.