Skip to content

Commit c0919c2

Browse files
authored
bpo-26439: Convert %s in Lib/ctypes/_aix.py to f-strings. (GH-4986)
1 parent d11e8e0 commit c0919c2

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

Lib/ctypes/_aix.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_ld_headers(file):
105105
# 2. If "INDEX" in occurs in a following line - return ld_header
106106
# 3. get info (lines starting with [0-9])
107107
ldr_headers = []
108-
p = Popen(["/usr/bin/dump", "-X%s" % AIX_ABI, "-H", file],
108+
p = Popen(["/usr/bin/dump", f"-X{AIX_ABI}", "-H", file],
109109
universal_newlines=True, stdout=PIPE, stderr=DEVNULL)
110110
# be sure to read to the end-of-file - getting all entries
111111
while True:
@@ -140,7 +140,7 @@ def get_one_match(expr, lines):
140140
When there is a match, strip leading "[" and trailing "]"
141141
"""
142142
# member names in the ld_headers output are between square brackets
143-
expr = r'\[(%s)\]' % expr
143+
expr = rf'\[({expr})\]'
144144
matches = list(filter(None, (re.search(expr, line) for line in lines)))
145145
if len(matches) == 1:
146146
return matches[0].group(1)
@@ -197,8 +197,8 @@ def get_version(name, members):
197197
# any combination of additional 'dot' digits pairs are accepted
198198
# anything more than libFOO.so.digits.digits.digits
199199
# should be seen as a member name outside normal expectations
200-
exprs = [r'lib%s\.so\.[0-9]+[0-9.]*' % name,
201-
r'lib%s_?64\.so\.[0-9]+[0-9.]*' % name]
200+
exprs = [rf'lib{name}\.so\.[0-9]+[0-9.]*',
201+
rf'lib{name}_?64\.so\.[0-9]+[0-9.]*']
202202
for expr in exprs:
203203
versions = []
204204
for line in members:
@@ -219,12 +219,12 @@ def get_member(name, members):
219219
and finally, legacy AIX naming scheme.
220220
"""
221221
# look first for a generic match - prepend lib and append .so
222-
expr = r'lib%s\.so' % name
222+
expr = rf'lib{name}\.so'
223223
member = get_one_match(expr, members)
224224
if member:
225225
return member
226226
elif AIX_ABI == 64:
227-
expr = r'lib%s64\.so' % name
227+
expr = rf'lib{name}64\.so'
228228
member = get_one_match(expr, members)
229229
if member:
230230
return member
@@ -277,7 +277,7 @@ def find_shared(paths, name):
277277
continue
278278
# "lib" is prefixed to emulate compiler name resolution,
279279
# e.g., -lc to libc
280-
base = 'lib%s.a' % name
280+
base = f'lib{name}.a'
281281
archive = path.join(dir, base)
282282
if path.exists(archive):
283283
members = get_shared(get_ld_headers(archive))
@@ -308,7 +308,7 @@ def find_library(name):
308308
libpaths = get_libpaths()
309309
(base, member) = find_shared(libpaths, name)
310310
if base != None:
311-
return "%s(%s)" % (base, member)
311+
return f"{base}({member})"
312312

313313
# To get here, a member in an archive has not been found
314314
# In other words, either:
@@ -319,7 +319,7 @@ def find_library(name):
319319
# Note, the installation must prepare a link from a .so
320320
# to a versioned file
321321
# This is common practice by GNU libtool on other platforms
322-
soname = "lib%s.so" % name
322+
soname = f"lib{name}.so"
323323
for dir in libpaths:
324324
# /lib is a symbolic link to /usr/lib, skip it
325325
if dir == "/lib":

Lib/ctypes/util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,18 @@ def test():
337337
elif sys.platform.startswith("aix"):
338338
from ctypes import CDLL
339339
if sys.maxsize < 2**32:
340-
print("Using CDLL(name, os.RTLD_MEMBER): %s" % CDLL("libc.a(shr.o)", os.RTLD_MEMBER))
341-
print("Using cdll.LoadLibrary(): %s" % cdll.LoadLibrary("libc.a(shr.o)"))
340+
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}")
341+
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}")
342342
# librpm.so is only available as 32-bit shared library
343343
print(find_library("rpm"))
344344
print(cdll.LoadLibrary("librpm.so"))
345345
else:
346-
print("Using CDLL(name, os.RTLD_MEMBER): %s" % CDLL("libc.a(shr_64.o)", os.RTLD_MEMBER))
347-
print("Using cdll.LoadLibrary(): %s" % cdll.LoadLibrary("libc.a(shr_64.o)"))
348-
print("crypt\t:: %s" % find_library("crypt"))
349-
print("crypt\t:: %s" % cdll.LoadLibrary(find_library("crypt")))
350-
print("crypto\t:: %s" % find_library("crypto"))
351-
print("crypto\t:: %s" % cdll.LoadLibrary(find_library("crypto")))
346+
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}")
347+
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}")
348+
print(f"crypt\t:: {find_library('crypt')}")
349+
print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}")
350+
print(f"crypto\t:: {find_library('crypto')}")
351+
print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}")
352352
else:
353353
print(cdll.LoadLibrary("libm.so"))
354354
print(cdll.LoadLibrary("libcrypt.so"))

0 commit comments

Comments
 (0)