diff --git a/app/scodoc/notesdb.py b/app/scodoc/notesdb.py index 767921262c..8226c1e2fc 100644 --- a/app/scodoc/notesdb.py +++ b/app/scodoc/notesdb.py @@ -117,6 +117,9 @@ def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1): return oid +_SQL_REMOVE_BAD_CHARS = str.maketrans("", "", '%*()+=&|[]"`') + + def DBSelectArgs( cnx, table, @@ -168,7 +171,7 @@ def DBSelectArgs( # n'autorise pas d'expressions if test == "~": for k in vals.keys(): - vals[k] = vals[k].translate(string.maketrans("", ""), '%*()+=&|[]"`') + vals[k] = vals[k].translate(_SQL_REMOVE_BAD_CHARS) if vals: if aux_tables: # paren diff --git a/app/scodoc/sco_entreprises.py b/app/scodoc/sco_entreprises.py index 00c19a4f8e..8fb076a7b1 100644 --- a/app/scodoc/sco_entreprises.py +++ b/app/scodoc/sco_entreprises.py @@ -290,7 +290,7 @@ def do_entreprise_check_etudiant(context, etudiant): Sinon, retourne (0, 'message explicatif') """ etudiant = etudiant.strip().translate( - None, "'()" + str.maketrans("", "", "'()") ) # suppress parens and quote from name if not etudiant: return 1, None diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index a35b163198..d4e2b65f97 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -1093,8 +1093,11 @@ def do_formsemestre_clone( pvalue = prefs[pname] try: prefs.base_prefs.set(formsemestre_id, pname, pvalue) - except: - log("do_formsemestre_clone: ignoring old preference %s" % pname) + except ValueError: + log( + "do_formsemestre_clone: ignoring old preference %s=%s for %s" + % (pname, pvalue, formsemestre_id) + ) # 5- Copy formules utilisateur objs = sco_compute_moy.formsemestre_ue_computation_expr_list( diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 3c218fb12d..08c4c5276e 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -405,7 +405,7 @@ class DisplayedGroupsInfos(object): self.groups_titles = ", ".join(groups_titles) self.groups_filename = "_".join(groups_titles).replace(" ", "_") # Sanitize filename: - self.groups_filename = self.groups_filename.translate(None, ":/\\") + self.groups_filename = scu.make_filename(self.groups_filename) # colonnes pour affichages nom des groupes: # gère le cas où les étudiants appartiennent à des semestres différents diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 637bbf7517..819a37e9fd 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -480,16 +480,19 @@ def sanitize_string(s): For ids and some filenames """ - return ( - suppress_accents(s.translate(None, "'`\"<>!&\\ ")) - .replace(" ", "_") - .replace("\t", "_") - ) + # Table suppressing some chars: + trans = str.maketrans("", "", "'`\"<>!&\\ ") + return suppress_accents(s.translate(trans)).replace(" ", "_").replace("\t", "_") + + +_BAD_FILENAME_CHARS = str.maketrans("", "", ":/\\") def make_filename(name): - """Try to convert name to a reasonnable filename""" - return suppress_accents(name).replace(" ", "_") + """Try to convert name to a reasonable filename + without spaces, (back)slashes, : and without accents + """ + return suppress_accents(name.translate(_BAD_FILENAME_CHARS)).replace(" ", "_") VALID_CARS = ( diff --git a/misc/extract_code_strings.py b/misc/extract_code_strings.py index ad16304d69..651900d733 100755 --- a/misc/extract_code_strings.py +++ b/misc/extract_code_strings.py @@ -31,7 +31,7 @@ for srcfilename in sys.argv[1:]: else: s = x.s.encode("UTF-8") # remove tabs and cr - s = s.translate(None, "\t\n") + s = s.replace("\t", "").replace("\n", "") if len(s): print("%s\t%s" % (srcfilename, s))