On Mon, 11 Mar 2024 19:34:33 +0100 Heinrich Schuchardt <heinrich.schucha...@canonical.com> wrote:
> Many escape sequences are only valid in raw string. Use these when > invoking re.match() and re.search() to avoid syntax warnings. There's quite a few unnecessary changes (regex strings with no escapes). But I'm okay with it and this seems like a reasonable change overall. Reviewed-by: Glenn Washburn <developm...@efficientek.com> Glenn > > Signed-off-by: Heinrich Schuchardt <heinrich.schucha...@canonical.com> > --- > util/import_gcry.py | 100 ++++++++++++++++++++++---------------------- > 1 file changed, 50 insertions(+), 50 deletions(-) > > diff --git a/util/import_gcry.py b/util/import_gcry.py > index 2b3322d3a..c80aa3b3d 100644 > --- a/util/import_gcry.py > +++ b/util/import_gcry.py > @@ -105,15 +105,15 @@ for cipher_file in cipher_files: > if cipher_file == "ChangeLog" or cipher_file == "ChangeLog-2011": > continue > chlognew = " * %s" % cipher_file > - if re.match > ("(Manifest|Makefile\.am|ac\.c|cipher\.c|hash-common\.c|hmac-tests\.c|md\.c|pubkey\.c)$", > cipher_file) or cipher_file == "kdf.c" or cipher_file == "elgamal.c" or > cipher_file == "primegen.c" or cipher_file == "ecc.c" or cipher_file == > "test-getrusage.c": > + if re.match > (r"(Manifest|Makefile\.am|ac\.c|cipher\.c|hash-common\.c|hmac-tests\.c|md\.c|pubkey\.c)$", > cipher_file) or cipher_file == "kdf.c" or cipher_file == "elgamal.c" or > cipher_file == "primegen.c" or cipher_file == "ecc.c" or cipher_file == > "test-getrusage.c": > chlog = "%s%s: Removed\n" % (chlog, chlognew) > continue > # Autogenerated files. Not even worth mentionning in ChangeLog > - if re.match ("Makefile\.in$", cipher_file): > + if re.match (r"Makefile\.in$", cipher_file): > continue > nch = False > - if re.match (".*\.[ch]$", cipher_file): > - isc = re.match (".*\.c$", cipher_file) > + if re.match (r".*\.[ch]$", cipher_file): > + isc = re.match (r".*\.c$", cipher_file) > f = codecs.open (infile, "r", "utf-8") > fw = codecs.open (outfile, "w", "utf-8") > fw.write ("/* This file was automatically imported with \n") > @@ -152,14 +152,14 @@ for cipher_file in cipher_files: > skip_statement = False > if isc: > modname = cipher_file [0:len(cipher_file) - 2] > - if re.match (".*-glue$", modname): > + if re.match (r".*-glue$", modname): > modname = modname.replace ("-glue", "") > isglue = True > modname = "gcry_%s" % modname > for line in f: > line = line > if skip_statement: > - if not re.search (";", line) is None: > + if not re.search (r";", line) is None: > skip_statement = False > continue > if skip > 0: > @@ -167,11 +167,11 @@ for cipher_file in cipher_files: > skip = skip - 1 > continue > if skip2: > - if not re.search (" *};", line) is None: > + if not re.search (r" *};", line) is None: > skip2 = False > continue > if iscryptostart: > - s = re.search (" *\"([A-Z0-9_a-z]*)\"", line) > + s = re.search (r" *\"([A-Z0-9_a-z]*)\"", line) > if not s is None: > sg = s.groups()[0] > cryptolist.write (("%s: %s\n") % (sg, modname)) > @@ -182,7 +182,7 @@ for cipher_file in cipher_files: > mdctxsizes.append (spl[9-mdarg].lstrip ().rstrip()) > mdarg = mdarg + len (spl) - 1 > if ismd or iscipher or ispk: > - if not re.search (" *};", line) is None: > + if not re.search (r" *};", line) is None: > if not iscomma: > fw.write (" ,\n") > fw.write ("#ifdef GRUB_UTIL\n"); > @@ -199,9 +199,9 @@ for cipher_file in cipher_files: > mdarg = 0 > iscipher = False > ispk = False > - iscomma = not re.search (",$", line) is None > + iscomma = not re.search (r",$", line) is None > # Used only for selftests. > - m = re.match ("(static byte|static unsigned char) > (weak_keys_chksum)\[[0-9]*\] =", line) > + m = re.match (r"(static byte|static unsigned char) > (weak_keys_chksum)\[[0-9]*\] =", line) > if not m is None: > skip = 1 > fname = m.groups ()[1] > @@ -216,29 +216,29 @@ for cipher_file in cipher_files: > hold = False > # We're optimising for size and exclude anything needing good > # randomness. > - if not re.match > ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer|tripledes_set2keys|do_tripledes_set_extra_info|_gcry_rmd160_mixblock|serpent_test|dsa_generate_ext|test_keys|gen_k|sign|gen_x931_parm_xp|generate_x931|generate_key|dsa_generate|dsa_sign|ecc_sign|generate|generate_fips186|_gcry_register_pk_dsa_progress|_gcry_register_pk_ecc_progress|progress|scanval|ec2os|ecc_generate_ext|ecc_generate|compute_keygrip|ecc_get_param|_gcry_register_pk_dsa_progress|gen_x931_parm_xp|gen_x931_parm_xi|rsa_decrypt|rsa_sign|rsa_generate_ext|rsa_generate|secret|check_exponent|rsa_blind|rsa_unblind|extract_a_from_sexp|curve_free|curve_copy|point_set)", > line) is None: > + if not re.match > (r"(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer|tripledes_set2keys|do_tripledes_set_extra_info|_gcry_rmd160_mixblock|serpent_test|dsa_generate_ext|test_keys|gen_k|sign|gen_x931_parm_xp|generate_x931|generate_key|dsa_generate|dsa_sign|ecc_sign|generate|generate_fips186|_gcry_register_pk_dsa_progress|_gcry_register_pk_ecc_progress|progress|scanval|ec2os|ecc_generate_ext|ecc_generate|compute_keygrip|ecc_get_param|_gcry_register_pk_dsa_progress|gen_x931_parm_xp|gen_x931_parm_xi|rsa_decrypt|rsa_sign|rsa_generate_ext|rsa_generate|secret|check_exponent|rsa_blind|rsa_unblind|extract_a_from_sexp|curve_free|curve_copy|point_set)", > line) is None: > > skip = 1 > - if not re.match ("selftest", line) is None and > cipher_file == "idea.c": > + if not re.match (r"selftest", line) is None and > cipher_file == "idea.c": > skip = 3 > > - if not re.match ("serpent_test", line) is None: > + if not re.match (r"serpent_test", line) is None: > fw.write ("static const char *serpent_test (void) { > return 0; }\n"); > - if not re.match ("dsa_generate", line) is None: > + if not re.match (r"dsa_generate", line) is None: > fw.write ("#define dsa_generate 0"); > - if not re.match ("ecc_generate", line) is None: > + if not re.match (r"ecc_generate", line) is None: > fw.write ("#define ecc_generate 0"); > - if not re.match ("rsa_generate ", line) is None: > + if not re.match (r"rsa_generate ", line) is None: > fw.write ("#define rsa_generate 0"); > - if not re.match ("rsa_sign", line) is None: > + if not re.match (r"rsa_sign", line) is None: > fw.write ("#define rsa_sign 0"); > - if not re.match ("rsa_decrypt", line) is None: > + if not re.match (r"rsa_decrypt", line) is None: > fw.write ("#define rsa_decrypt 0"); > - if not re.match ("dsa_sign", line) is None: > + if not re.match (r"dsa_sign", line) is None: > fw.write ("#define dsa_sign 0"); > - if not re.match ("ecc_sign", line) is None: > + if not re.match (r"ecc_sign", line) is None: > fw.write ("#define ecc_sign 0"); > - fname = re.match ("[a-zA-Z0-9_]*", line).group () > + fname = re.match (r"[a-zA-Z0-9_]*", line).group () > chmsg = "(%s): Removed." % fname > if nch: > chlognew = "%s\n %s" % (chlognew, chmsg) > @@ -248,7 +248,7 @@ for cipher_file in cipher_files: > continue > else: > fw.write (holdline) > - m = re.match ("# *include <(.*)>", line) > + m = re.match (r"# *include <(.*)>", line) > if not m is None: > chmsg = "Removed including of %s" % m.groups ()[0] > if nch: > @@ -257,7 +257,7 @@ for cipher_file in cipher_files: > chlognew = "%s: %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("gcry_cipher_spec_t", line) > + m = re.match (r"gcry_cipher_spec_t", line) > if isc and not m is None: > assert (not ismd) > assert (not ispk) > @@ -269,7 +269,7 @@ for cipher_file in cipher_files: > iscipher = True > iscryptostart = True > > - m = re.match ("gcry_pk_spec_t", line) > + m = re.match (r"gcry_pk_spec_t", line) > if isc and not m is None: > assert (not ismd) > assert (not ispk) > @@ -281,7 +281,7 @@ for cipher_file in cipher_files: > ispk = True > iscryptostart = True > > - m = re.match ("gcry_md_spec_t", line) > + m = re.match (r"gcry_md_spec_t", line) > if isc and not m is None: > assert (not ismd) > assert (not ispk) > @@ -293,10 +293,10 @@ for cipher_file in cipher_files: > ismd = True > mdarg = 0 > iscryptostart = True > - m = re.match ("static const char \*selftest.*;$", line) > + m = re.match (r"static const char \*selftest.*;$", line) > if not m is None: > fname = line[len ("static const char \*"):] > - fname = re.match ("[a-zA-Z0-9_]*", fname).group () > + fname = re.match (r"[a-zA-Z0-9_]*", fname).group () > chmsg = "(%s): Removed declaration." % fname > if nch: > chlognew = "%s\n %s" % (chlognew, chmsg) > @@ -304,7 +304,7 @@ for cipher_file in cipher_files: > chlognew = "%s %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("static gcry_mpi_t gen_k .*;$", line) > + m = re.match (r"static gcry_mpi_t gen_k .*;$", line) > if not m is None: > chmsg = "(gen_k): Removed declaration." > if nch: > @@ -313,7 +313,7 @@ for cipher_file in cipher_files: > chlognew = "%s %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("static (int|void) test_keys .*;$", line) > + m = re.match (r"static (int|void) test_keys .*;$", line) > if not m is None: > chmsg = "(test_keys): Removed declaration." > if nch: > @@ -322,7 +322,7 @@ for cipher_file in cipher_files: > chlognew = "%s %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("static void secret .*;$", line) > + m = re.match (r"static void secret .*;$", line) > if not m is None: > chmsg = "(secret): Removed declaration." > if nch: > @@ -331,7 +331,7 @@ for cipher_file in cipher_files: > chlognew = "%s %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("static void \(\*progress_cb\).*;$", line) > + m = re.match (r"static void \(\*progress_cb\).*;$", line) > if not m is None: > chmsg = "(progress_cb): Removed declaration." > if nch: > @@ -340,7 +340,7 @@ for cipher_file in cipher_files: > chlognew = "%s %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("static void \*progress_cb_data.*;$", line) > + m = re.match (r"static void \*progress_cb_data.*;$", line) > if not m is None: > chmsg = "(progress_cb): Removed declaration." > if nch: > @@ -350,44 +350,44 @@ for cipher_file in cipher_files: > nch = True > continue > > - m = re.match ("(static const char( |)\*|static > gpg_err_code_t|void|static int|static gcry_err_code_t|static > gcry_mpi_t|static void|void|static elliptic_curve_t) *$", line) > + m = re.match (r"(static const char( |)\*|static > gpg_err_code_t|void|static int|static gcry_err_code_t|static > gcry_mpi_t|static void|void|static elliptic_curve_t) *$", line) > if not m is None: > hold = True > holdline = line > continue > - m = re.match ("static int tripledes_set2keys \(.*\);", line) > + m = re.match (r"static int tripledes_set2keys \(.*\);", line) > if not m is None: > continue > - m = re.match ("static int tripledes_set3keys \(.*\);", line) > + m = re.match (r"static int tripledes_set3keys \(.*\);", line) > if not m is None: > continue > - m = re.match ("static int tripledes_set2keys \(", line) > + m = re.match (r"static int tripledes_set2keys \(", line) > if not m is None: > skip_statement = True > continue > - m = re.match ("static int tripledes_set3keys \(", line) > + m = re.match (r"static int tripledes_set3keys \(", line) > if not m is None: > skip_statement = True > continue > - m = re.match ("static const char sample_secret_key", line) > + m = re.match (r"static const char sample_secret_key", line) > if not m is None: > skip_statement = True > continue > - m = re.match ("static const char sample_public_key", line) > + m = re.match (r"static const char sample_public_key", line) > if not m is None: > skip_statement = True > continue > - m = re.match ("static void sign|static gpg_err_code_t > sign|static gpg_err_code_t generate", > + m = re.match (r"static void sign|static gpg_err_code_t > sign|static gpg_err_code_t generate", > line) > if not m is None: > skip_statement = True > continue > > - m = re.match ("cipher_extra_spec_t", line) > + m = re.match (r"cipher_extra_spec_t", line) > if isc and not m is None: > skip2 = True > fname = line[len ("cipher_extra_spec_t "):] > - fname = re.match ("[a-zA-Z0-9_]*", fname).group () > + fname = re.match (r"[a-zA-Z0-9_]*", fname).group () > chmsg = "(%s): Removed." % fname > if nch: > chlognew = "%s\n %s" % (chlognew, chmsg) > @@ -395,11 +395,11 @@ for cipher_file in cipher_files: > chlognew = "%s %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("pk_extra_spec_t", line) > + m = re.match (r"pk_extra_spec_t", line) > if isc and not m is None: > skip2 = True > fname = line[len ("pk_extra_spec_t "):] > - fname = re.match ("[a-zA-Z0-9_]*", fname).group () > + fname = re.match (r"[a-zA-Z0-9_]*", fname).group () > chmsg = "(%s): Removed." % fname > if nch: > chlognew = "%s\n %s" % (chlognew, chmsg) > @@ -407,11 +407,11 @@ for cipher_file in cipher_files: > chlognew = "%s %s" % (chlognew, chmsg) > nch = True > continue > - m = re.match ("md_extra_spec_t", line) > + m = re.match (r"md_extra_spec_t", line) > if isc and not m is None: > skip2 = True > fname = line[len ("md_extra_spec_t "):] > - fname = re.match ("[a-zA-Z0-9_]*", fname).group () > + fname = re.match (r"[a-zA-Z0-9_]*", fname).group () > chmsg = "(%s): Removed." % fname > if nch: > chlognew = "%s\n %s" % (chlognew, chmsg) > @@ -568,17 +568,17 @@ for src in sorted (os.listdir (os.path.join (indir, > "mpi"))): > hold = False > # We're optimising for size and exclude anything needing good > # randomness. > - if not re.match ("(_gcry_mpi_get_hw_config|gcry_mpi_randomize)", > line) is None: > + if not re.match > (r"(_gcry_mpi_get_hw_config|gcry_mpi_randomize)", line) is None: > skip = 1 > continue > else: > fw.write (holdline) > - m = re.match ("(const char( |)\*|void) *$", line) > + m = re.match (r"(const char( |)\*|void) *$", line) > if not m is None: > hold = True > holdline = line > continue > - m = re.match ("#include \"mod-source-info\.h\"", line) > + m = re.match (r"#include \"mod-source-info\.h\"", line) > if not m is None: > continue > fw.write (line) _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel