From 2bf7a76d97acbd0d74bc240f567c3e15fbcacfc5 Mon Sep 17 00:00:00 2001 From: Jonathan Mahrt Guyou Date: Sun, 13 Apr 2025 19:52:49 -0400 Subject: [PATCH] Refactor: Convert string concatenation to f-strings --- update/cn_loc.py | 4 ++-- update/iban.py | 2 +- update/imsi.py | 17 +++-------------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/update/cn_loc.py b/update/cn_loc.py index e8debf74..7d0805a2 100755 --- a/update/cn_loc.py +++ b/update/cn_loc.py @@ -76,8 +76,8 @@ def group_data(data_collection): for code, name in sorted(data_collection.items()): if code.endswith('00'): continue # county only - province_code = code[:2] + '0000' - prefecture_code = code[:4] + '00' + province_code = f"{code[:2]}0000" + prefecture_code = f"{code[:4]}00" province_name = data_collection[province_code] prefecture_name = data_collection[prefecture_code] yield code, name, prefecture_name, province_name diff --git a/update/iban.py b/update/iban.py index 3e954e6c..fd58a1ec 100755 --- a/update/iban.py +++ b/update/iban.py @@ -64,7 +64,7 @@ def get_country_codes(line): bban = bban.replace(' ', '') cc = data['IBAN prefix country code (ISO 3166)'][:2] cname = data['Name of country'] - if bban.startswith(cc + '2!n'): + if bban.startswith(f"{cc}2!n"): bban = bban[5:] # print country line print('%s country="%s" bban="%s"' % (cc, cname, bban)) diff --git a/update/imsi.py b/update/imsi.py index f070a5eb..503828ec 100755 --- a/update/imsi.py +++ b/update/imsi.py @@ -106,11 +106,7 @@ remove_ref_re = re.compile(r'.*?') remove_comment_re = re.compile(r'{{.*?}}') quotes = u'\xab\xbb\u201c\u201d\u2018\u2019' -remove_href_re = re.compile(r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+' + - r'[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|' + - r'(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|' + - r'(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>' + - r'?' + quotes + ']))') +remove_href_re = re.compile("(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|"+|'}(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|"+|'}(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>"<>'}?"'?' + quotes}]))") def cleanup_value(val): @@ -138,14 +134,7 @@ def cleanup_value(val): # This matches a line containing a MCC/MNC, e.g. # | 232 || 02 || || A1 Telekom Austria || Reserved || || _mnc_line_re = re.compile( - r'^\|\s*(?P[0-9]+)' + - r'\s*\\\\\s*(?P[0-9]+)' + - r'(\s*\\\\\s*(?P[^\\]*)' + - r'(\s*\\\\\s*(?P[^\\]*)' + - r'(\s*\\\\\s*(?P[^\\]*)' + - r'(\s*\\\\\s*(?P[^\\]*)' + - r'(\s*\\\\\s*(?P[^\\]*)' + - r')?)?)?)?)?') + "^\|\s*(?P[0-9]+)\s*\\\\\s*(?P[0-9]+)"+)'}(\s*\\\\\s*(?P[^\\]*)"*)'}(\s*\\\\\s*(?P[^\\]*)"*)'}(\s*\\\\\s*(?P[^\\]*)"*)'}(\s*\\\\\s*(?P[^\\]*)"*)'}(\s*\\\\\s*(?P[^\\]*)"*)'})?)?)?)?)?") def get_mncs_from_wikipedia(): @@ -187,7 +176,7 @@ def str2range(x): for part in x.split(','): if '-' in part: a, b = part.split('-') - f = '%0' + str(len(b)) + 'd' + f = f'%0{str(len(b))}'b))}d" a, b = int(a), int(b) for i in range(a, b + 1): result.append(f % (i))