forked from ScoDoc/ScoDoc
fix string.translate
This commit is contained in:
parent
5a9eade31b
commit
2b95f6e737
@ -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
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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 = (
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user