Fix unicode strings for Python3

This commit is contained in:
Emmanuel Viennet 2021-07-12 15:13:10 +02:00
parent 99279a96bd
commit 0ec41c48f3
22 changed files with 88 additions and 134 deletions

View File

@ -41,32 +41,28 @@ class ZRequest(object):
"Emulating Zope 2 REQUEST" "Emulating Zope 2 REQUEST"
def __init__(self): def __init__(self):
self.URL = ( self.URL = request.base_url
request.base_url
) # .encode("utf-8") # necessaire pour ScoDoc 8 en Python 2 #sco8
self.URL0 = self.URL self.URL0 = self.URL
self.BASE0 = request.url_root # .encode("utf-8") self.BASE0 = request.url_root
self.QUERY_STRING = request.query_string # .encode("utf-8") self.QUERY_STRING = request.query_string.decode(
self.REQUEST_METHOD = request.method # .encode("utf-8") "utf-8"
) # query_string is bytes
self.REQUEST_METHOD = request.method
self.AUTHENTICATED_USER = current_user self.AUTHENTICATED_USER = current_user
self.REMOTE_ADDR = request.remote_addr self.REMOTE_ADDR = request.remote_addr
if request.method == "POST": if request.method == "POST":
self.form = request.form # xxx encode en utf-8 !
# Encode en utf-8 pour ScoDoc8 #sco8
# self.form = {k: v.encode("utf-8") for (k, v) in request.form.items()}
if request.files:
# Add files in form: must copy to get a mutable version
# request.form is a werkzeug.datastructures.ImmutableMultiDict # request.form is a werkzeug.datastructures.ImmutableMultiDict
# self.form = self.form.copy() # must copy to get a mutable version (needed by TrivialFormulator)
self.form = request.form.copy()
if request.files:
# Add files in form:
self.form.update(request.files) self.form.update(request.files)
# self.cf = request.form.copy()
for k in request.form: for k in request.form:
if k.endswith(":list"): if k.endswith(":list"):
self.form[k[:-5]] = request.form.getlist(k) self.form[k[:-5]] = request.form.getlist(k)
elif request.method == "GET": elif request.method == "GET":
self.form = {k: v for (k, v) in request.args.items()} # forme python3 self.form = {k: v for (k, v) in request.args.items()}
# Encode en utf-8 pour ScoDoc8 #sco8
# self.form = {k: v.encode("utf-8") for (k, v) in request.args.items()}
self.RESPONSE = ZResponse() self.RESPONSE = ZResponse()
def __str__(self): def __str__(self):
@ -89,7 +85,7 @@ class ZResponse(object):
def redirect(self, url): def redirect(self, url):
current_app.logger.debug("ZResponse redirect to:" + str(url)) current_app.logger.debug("ZResponse redirect to:" + str(url))
return flask.redirect(url) # .decode("utf-8")) # http 302 # #sco8 unicode return flask.redirect(url) # http 302
def setHeader(self, header, value): def setHeader(self, header, value):
self.headers[header.lower()] = value self.headers[header.lower()] = value
@ -100,7 +96,7 @@ def permission_required(permission):
@wraps(f) @wraps(f)
def decorated_function(*args, **kwargs): def decorated_function(*args, **kwargs):
if "scodoc_dept" in kwargs: if "scodoc_dept" in kwargs:
g.scodoc_dept = kwargs["scodoc_dept"] # .encode("utf-8") # sco8 g.scodoc_dept = kwargs["scodoc_dept"]
del kwargs["scodoc_dept"] del kwargs["scodoc_dept"]
# current_app.logger.info( # current_app.logger.info(
# "permission_required: %s in %s" % (permission, g.scodoc_dept) # "permission_required: %s in %s" % (permission, g.scodoc_dept)
@ -148,7 +144,7 @@ def scodoc7func(context):
return func(*args, **kwargs) return func(*args, **kwargs)
# #
if "scodoc_dept" in kwargs: if "scodoc_dept" in kwargs:
g.scodoc_dept = kwargs["scodoc_dept"] # .encode("utf-8") # sco8 g.scodoc_dept = kwargs["scodoc_dept"]
del kwargs["scodoc_dept"] del kwargs["scodoc_dept"]
elif not hasattr(g, "scodoc_dept"): elif not hasattr(g, "scodoc_dept"):
g.scodoc_dept = None g.scodoc_dept = None
@ -174,12 +170,9 @@ def scodoc7func(context):
elif arg_name == "context": elif arg_name == "context":
pos_arg_values.append(context) pos_arg_values.append(context)
else: else:
# XXX Convert to regular string for ScoDoc8/Python 2 #py3
# if isinstance(req_args[arg_name], str):
# pos_arg_values.append(req_args[arg_name].encode("utf-8"))
# else:
pos_arg_values.append(req_args[arg_name]) pos_arg_values.append(req_args[arg_name])
current_app.logger.info("pos_arg_values=%s" % pos_arg_values) current_app.logger.info("pos_arg_values=%s" % pos_arg_values)
current_app.logger.info("req_args=%s" % req_args)
# Add keyword arguments # Add keyword arguments
if nb_default_args: if nb_default_args:
for arg_name in argspec.args[-nb_default_args:]: for arg_name in argspec.args[-nb_default_args:]:
@ -187,10 +180,6 @@ def scodoc7func(context):
kwargs[arg_name] = REQUEST kwargs[arg_name] = REQUEST
elif arg_name in req_args: elif arg_name in req_args:
# set argument kw optionnel # set argument kw optionnel
# XXX Convert to regular string for ScoDoc8/Python 2 #py3
# if isinstance(req_args[arg_name], str):
# kwargs[arg_name] = req_args[arg_name].encode("utf-8")
# else:
kwargs[arg_name] = req_args[arg_name] kwargs[arg_name] = req_args[arg_name]
current_app.logger.info( current_app.logger.info(
"scodoc7func_decorator: top_level=%s, pos_arg_values=%s, kwargs=%s" "scodoc7func_decorator: top_level=%s, pos_arg_values=%s, kwargs=%s"

View File

@ -332,7 +332,7 @@ def sco_header(
# div pour affichage messages temporaires # div pour affichage messages temporaires
H.append('<div id="sco_msg" class="head_message"></div>') H.append('<div id="sco_msg" class="head_message"></div>')
# #
return scu.sco8_join(H, sep="") return "".join(H)
def sco_footer(context, REQUEST=None): def sco_footer(context, REQUEST=None):

View File

@ -103,7 +103,7 @@ def make_menu(title, items, css_class="", alone=False):
args = item.get("args", {}) args = item.get("args", {})
item["urlq"] = url_for( item["urlq"] = url_for(
item["endpoint"], scodoc_dept=g.scodoc_dept, **args item["endpoint"], scodoc_dept=g.scodoc_dept, **args
).encode(scu.SCO_ENCODING) )
else: else:
item["urlq"] = "#" item["urlq"] = "#"
item["attr"] = item.get("attr", "") item["attr"] = item.get("attr", "")

View File

@ -9,10 +9,11 @@ import traceback
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.header import Header from email.header import Header
from flask import current_app
# Simple & stupid file logguer, used only to debug """Simple & stupid file logguer, used only to debug
# (logging to SQL is done in scolog) (logging to SQL is done in scolog)
"""
LOG_FILENAME = "notes.log" # empty to disable logging LOG_FILENAME = "notes.log" # empty to disable logging
DEFAULT_LOG_DIR = "/tmp" # clients should call set_log_directory to change this DEFAULT_LOG_DIR = "/tmp" # clients should call set_log_directory to change this
@ -48,12 +49,10 @@ class _logguer(object):
dept = retreive_dept() dept = retreive_dept()
if dept: if dept:
dept = " (%s)" % dept dept = " (%s)" % dept
self.file.write( msg = dept + " " + msg
"[%s]%s %s\n" % (time.strftime("%a %b %d %H:%M:%S %Y"), dept, msg) self.file.write("[%s]%s\n" % (time.strftime("%a %b %d %H:%M:%S %Y"), msg))
) if current_app:
# if not dept: current_app.logger.info(msg)
# import traceback
# traceback.print_stack(file=self.file) # hunt missing REQUESTS
self.file.flush() self.file.flush()

View File

@ -390,10 +390,7 @@ class NotesTable(object):
return ( return (
scu.strupper(etud["nom_usuel"] or etud["nom"]) scu.strupper(etud["nom_usuel"] or etud["nom"])
+ " " + " "
+ etud["prenom"] + etud["prenom"].capitalize()[:2]
.decode(scu.SCO_ENCODING)
.capitalize()[:2]
.encode(scu.SCO_ENCODING)
+ "." + "."
) )

View File

@ -1,8 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import html
import string
import traceback import traceback
import psycopg2 import psycopg2
import psycopg2.pool import psycopg2.pool
@ -13,10 +12,9 @@ from flask import g
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
from app.scodoc.notes_log import log from app.scodoc.notes_log import log
from app.scodoc.sco_exceptions import ScoException, ScoValueError, NoteProcessError from app.scodoc.sco_exceptions import ScoException, ScoValueError, NoteProcessError
from cgi import escape
import datetime import datetime
quote_html = escape quote_html = html.escape
def quote_dict(d): def quote_dict(d):

View File

@ -74,13 +74,8 @@ def get_code_latex_from_scodoc_preference(
et s'assure qu'il est renvoyé au format unicode et s'assure qu'il est renvoyé au format unicode
""" """
template_latex = sco_preferences.get_preference(context, champ, formsemestre_id) template_latex = sco_preferences.get_preference(context, champ, formsemestre_id)
# Conversion du template en unicode:
if template_latex:
template_latex = template_latex.decode(scu.SCO_ENCODING)
else:
template_latex = u"" # EV: preference non définie (None)
return template_latex return template_latex or ""
# ---------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------
@ -123,15 +118,9 @@ def comp_latex_parcourstimeline(etudiant, promo, taille=17):
\\end{parcourstimeline} \\end{parcourstimeline}
""" """
reslatex = codelatexDebut reslatex = codelatexDebut
reslatex = reslatex.replace( reslatex = reslatex.replace("**debut**", etudiant["entree"])
"**debut**", etudiant["entree"].decode(scu.SCO_ENCODING) reslatex = reslatex.replace("**fin**", str(etudiant["promo"]))
) reslatex = reslatex.replace("**nbreSemestres**", str(etudiant["nbSemestres"]))
reslatex = reslatex.replace(
"**fin**", str(etudiant["promo"]).decode(scu.SCO_ENCODING)
)
reslatex = reslatex.replace(
"**nbreSemestres**", str(etudiant["nbSemestres"]).decode(scu.SCO_ENCODING)
)
# Tri du parcours par ordre croissant : de la forme descr, nom sem date-date # Tri du parcours par ordre croissant : de la forme descr, nom sem date-date
parcours = etudiant["parcours"][::-1] # EV: XXX je ne comprend pas ce commentaire ? parcours = etudiant["parcours"][::-1] # EV: XXX je ne comprend pas ce commentaire ?
@ -218,11 +207,9 @@ def get_code_latex_avis_etudiant(
# Les tags "simples": par ex. nom, prenom, civilite, ... # Les tags "simples": par ex. nom, prenom, civilite, ...
else: else:
if tag_latex in donnees_etudiant: if tag_latex in donnees_etudiant:
valeur = donnees_etudiant[tag_latex].decode(scu.SCO_ENCODING) valeur = donnees_etudiant[tag_latex]
elif tag_latex in prefs: # les champs **NomResponsablePE**, ... elif tag_latex in prefs: # les champs **NomResponsablePE**, ...
valeur = pe_tools.escape_for_latex(prefs[tag_latex]).decode( valeur = pe_tools.escape_for_latex(prefs[tag_latex])
scu.SCO_ENCODING
)
# Vérification des pb d'encodage (debug) # Vérification des pb d'encodage (debug)
# assert isinstance(tag_latex, unicode) # assert isinstance(tag_latex, unicode)
@ -251,7 +238,7 @@ def get_annotation_PE(context, etudid, tag_annotation_pe):
exp = re.compile(r"^" + tag_annotation_pe) exp = re.compile(r"^" + tag_annotation_pe)
for a in annotations: for a in annotations:
commentaire = scu.unescape_html(a["comment"]).decode(scu.SCO_ENCODING) commentaire = scu.unescape_html(a["comment"])
if exp.match(commentaire): # tag en début de commentaire ? if exp.match(commentaire): # tag en début de commentaire ?
a["comment_u"] = commentaire # unicode, HTML non quoté a["comment_u"] = commentaire # unicode, HTML non quoté
annotationsPE.append( annotationsPE.append(
@ -383,11 +370,7 @@ def get_bilanParTag(donnees_etudiant, groupe="groupe"):
for (i, ligne_val) in enumerate(valeurs["note"]): for (i, ligne_val) in enumerate(valeurs["note"]):
titre = lignes[i] # règle le pb d'encodage titre = lignes[i] # règle le pb d'encodage
code_latex += ( code_latex += (
u"\\textbf{" u"\\textbf{" + titre + u"} & " + " & ".join(ligne_val) + u"\\\\ \n"
+ titre.decode(scu.SCO_ENCODING)
+ u"} & "
+ " & ".join(ligne_val)
+ u"\\\\ \n"
) )
code_latex += ( code_latex += (
u" & " u" & "
@ -412,11 +395,9 @@ def get_avis_poursuite_par_etudiant(
if pe_tools.PE_DEBUG: if pe_tools.PE_DEBUG:
pe_tools.pe_print(jury.syntheseJury[etudid]["nom"] + " " + etudid) pe_tools.pe_print(jury.syntheseJury[etudid]["nom"] + " " + etudid)
civilite_str = jury.syntheseJury[etudid]["civilite_str"].decode(scu.SCO_ENCODING) civilite_str = jury.syntheseJury[etudid]["civilite_str"]
nom = jury.syntheseJury[etudid]["nom"].replace(" ", "-").decode(scu.SCO_ENCODING) nom = jury.syntheseJury[etudid]["nom"].replace(" ", "-")
prenom = ( prenom = jury.syntheseJury[etudid]["prenom"].replace(" ", "-")
jury.syntheseJury[etudid]["prenom"].replace(" ", "-").decode(scu.SCO_ENCODING)
)
nom_fichier = ( nom_fichier = (
u"avis_poursuite_" u"avis_poursuite_"
@ -538,9 +519,7 @@ def table_syntheseAnnotationPE(context, syntheseJury, tag_annotation_pe):
annotationPE = get_annotation_PE( annotationPE = get_annotation_PE(
context, etudid, tag_annotation_pe=tag_annotation_pe context, etudid, tag_annotation_pe=tag_annotation_pe
) )
row["Annotation PE"] = ( row["Annotation PE"] = annotationPE if annotationPE else ""
annotationPE.encode(scu.SCO_ENCODING) if annotationPE else ""
)
rows.append(row) rows.append(row)
T = GenTable( T = GenTable(

View File

@ -106,7 +106,7 @@ def pe_view_sem_recap(
# template fourni via le formulaire Web # template fourni via le formulaire Web
if avis_tmpl_file: if avis_tmpl_file:
template_latex = avis_tmpl_file.read() template_latex = avis_tmpl_file.read()
template_latex = template_latex.decode(scu.SCO_ENCODING) template_latex = template_latex
else: else:
# template indiqué dans préférences ScoDoc ? # template indiqué dans préférences ScoDoc ?
template_latex = pe_avislatex.get_code_latex_from_scodoc_preference( template_latex = pe_avislatex.get_code_latex_from_scodoc_preference(
@ -123,7 +123,7 @@ def pe_view_sem_recap(
# template fourni via le formulaire Web # template fourni via le formulaire Web
if footer_tmpl_file: if footer_tmpl_file:
footer_latex = footer_tmpl_file.read() footer_latex = footer_tmpl_file.read()
footer_latex = footer_latex.decode(scu.SCO_ENCODING) footer_latex = footer_latex
else: else:
footer_latex = pe_avislatex.get_code_latex_from_scodoc_preference( footer_latex = pe_avislatex.get_code_latex_from_scodoc_preference(
context, formsemestre_id, champ="pe_avis_latex_footer" context, formsemestre_id, champ="pe_avis_latex_footer"

View File

@ -93,15 +93,15 @@ class ddmmyyyy(object):
return return
try: try:
if fmt == "ddmmyyyy": if fmt == "ddmmyyyy":
self.day, self.month, self.year = string.split(date, "/") self.day, self.month, self.year = date.split("/")
elif fmt == "iso": elif fmt == "iso":
self.year, self.month, self.day = string.split(date, "-") self.year, self.month, self.day = date.split("-")
else: else:
raise ValueError("invalid format spec. (%s)" % fmt) raise ValueError("invalid format spec. (%s)" % fmt)
self.year = string.atoi(self.year) self.year = int(self.year)
self.month = string.atoi(self.month) self.month = int(self.month)
self.day = string.atoi(self.day) self.day = int(self.day)
except: except ValueError:
raise ScoValueError("date invalide: %s" % date) raise ScoValueError("date invalide: %s" % date)
# accept years YYYY or YY, uses 1970 as pivot # accept years YYYY or YY, uses 1970 as pivot
if self.year < 1970: if self.year < 1970:
@ -297,7 +297,7 @@ def YearTable(
month = 1 month = 1
year = year + 1 year = year + 1
T.append("</table>") T.append("</table>")
return string.join(T, "\n") return "\n".join(T)
def list_abs_in_range( def list_abs_in_range(
@ -876,7 +876,7 @@ def MonthTableBody(
if href or descr: if href or descr:
cc.append("</a>") cc.append("</a>")
cc.append("</td>") cc.append("</td>")
cell = string.join(cc, "") cell = "".join(cc)
if day == "D": if day == "D":
monday = monday.next_day(7) monday = monday.next_day(7)
if ( if (
@ -968,8 +968,8 @@ def MonthTableBody(
if href or descr: if href or descr:
cc.append("</a>") cc.append("</a>")
cc.append("</td>\n") cc.append("</td>\n")
T.append(string.join(cc, "") + "</tr>") T.append("".join(cc) + "</tr>")
return string.join(T, "\n") return "\n".join(T)
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -194,14 +194,16 @@ def fix_data_encoding(
default_source_encoding, default_source_encoding,
dest_encoding, dest_encoding,
) )
text = text.decode(default_source_encoding).encode(dest_encoding) text = text.decode(default_source_encoding).encode(
dest_encoding
) # XXX #py3 #sco8 à tester
else: else:
if detected_encoding != dest_encoding: if detected_encoding != dest_encoding:
message = "converting from detected %s to %s" % ( message = "converting from detected %s to %s" % (
detected_encoding, detected_encoding,
dest_encoding, dest_encoding,
) )
text = text.decode(detected_encoding).encode(dest_encoding) text = text.decode(detected_encoding).encode(dest_encoding) # XXX
return text, message return text, message
@ -782,7 +784,9 @@ class ApoData(object):
if not data: if not data:
raise FormatError("Fichier Apogée vide !") raise FormatError("Fichier Apogée vide !")
data_utf8 = data.decode(APO_INPUT_ENCODING).encode(scu.SCO_ENCODING) data_utf8 = data.decode(APO_INPUT_ENCODING).encode(
scu.SCO_ENCODING
) # XXX #sco8
f = StringIOFileLineWrapper(data_utf8) # pour traiter comme un fichier f = StringIOFileLineWrapper(data_utf8) # pour traiter comme un fichier
# check that we are at the begining of Apogee CSV # check that we are at the begining of Apogee CSV
line = f.readline().strip() line = f.readline().strip()
@ -1316,7 +1320,7 @@ def export_csv_to_apogee(
) )
log(logf.getvalue()) # sortie aussi sur le log ScoDoc log(logf.getvalue()) # sortie aussi sur le log ScoDoc
csv_data = f.getvalue().decode(scu.SCO_ENCODING).encode(APO_OUTPUT_ENCODING) csv_data = f.getvalue().decode(scu.SCO_ENCODING).encode(APO_OUTPUT_ENCODING) # XXX
# Write data to ZIP # Write data to ZIP
dest_zip.writestr(csv_filename, csv_data) dest_zip.writestr(csv_filename, csv_data)

View File

@ -124,7 +124,7 @@ class BaseArchiver(object):
base base
+ "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]" + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"
) )
dirs = [os.path.join(base, d).encode(scu.SCO_ENCODING) for d in dirs] # sco8 dirs = [os.path.join(base, d) for d in dirs]
dirs = [d for d in dirs if os.path.isdir(d) and os.listdir(d)] # non empty dirs dirs = [d for d in dirs if os.path.isdir(d) and os.listdir(d)] # non empty dirs
dirs.sort() dirs.sort()
return dirs return dirs
@ -150,7 +150,9 @@ class BaseArchiver(object):
finally: finally:
scu.GSL.release() scu.GSL.release()
files.sort() files.sort()
return [f.encode(scu.SCO_ENCODING) for f in files if f and f[0] != "_"] # sco8 return [
f.encode(scu.SCO_ENCODING) for f in files if f and f[0] != "_"
] # sco8 XXX
def get_archive_name(self, archive_id): def get_archive_name(self, archive_id):
"""name identifying archive, to be used in web URLs""" """name identifying archive, to be used in web URLs"""

View File

@ -84,7 +84,7 @@ class CacheNotesTable(object):
raise NoteProcessError("problem with notes cache") raise NoteProcessError("problem with notes cache")
def get_NotesTable(self, context, formsemestre_id): # > def get_NotesTable(self, context, formsemestre_id): # >
import notes_table from app.scodoc import notes_table
try: try:
self.acquire() self.acquire()

View File

@ -354,7 +354,7 @@ def itemsuivi_tag_list(context, itemsuivi_id):
def itemsuivi_tag_search(context, term, REQUEST=None): def itemsuivi_tag_search(context, term, REQUEST=None):
"""List all used tag names (for auto-completion)""" """List all used tag names (for auto-completion)"""
# restrict charset to avoid injections # restrict charset to avoid injections
if not scu.ALPHANUM_EXP.match(term.decode(scu.SCO_ENCODING)): if not scu.ALPHANUM_EXP.match(term):
data = [] data = []
else: else:
r = ndb.SimpleDictFetch( r = ndb.SimpleDictFetch(

View File

@ -142,12 +142,10 @@ def group_edt_json(context, group_id, start="", end="", REQUEST=None):
events = [e for e in cal.walk() if e.name == "VEVENT"] events = [e for e in cal.walk() if e.name == "VEVENT"]
J = [] J = []
for e in events: for e in events:
# if e['X-GROUP-ID'].encode('utf-8').strip() == edt_group_name: # if e['X-GROUP-ID'].strip() == edt_group_name:
if "DESCRIPTION" in e: if "DESCRIPTION" in e:
d = { d = {
"title": e.decoded( "title": e.decoded("DESCRIPTION"), # + '/' + e['X-GROUP-ID'],
"DESCRIPTION"
), # + '/' + e['X-GROUP-ID'].encode('utf-8'),
"start": e.decoded("dtstart").isoformat(), "start": e.decoded("dtstart").isoformat(),
"end": e.decoded("dtend").isoformat(), "end": e.decoded("dtend").isoformat(),
} }
@ -159,7 +157,7 @@ def group_edt_json(context, group_id, start="", end="", REQUEST=None):
"""XXX """XXX
for e in events: for e in events:
if 'DESCRIPTION' in e: if 'DESCRIPTION' in e:
print e.decoded('DESCRIPTION').encode('utf-8') print e.decoded('DESCRIPTION')
""" """

View File

@ -33,15 +33,14 @@ from operator import itemgetter
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
from notesdb import ScoDocCursor, EditableTable, DateISOtoDMY, DateDMYtoISO from app.scodoc.notesdb import ScoDocCursor, EditableTable, DateISOtoDMY, DateDMYtoISO
def _format_nom(nom): def _format_nom(nom):
"formatte nom (filtre en entree db) d'une entreprise" "formatte nom (filtre en entree db) d'une entreprise"
if not nom: if not nom:
return nom return nom
nom = nom.decode(scu.SCO_ENCODING) return nom[0].upper() + nom[1:]
return (nom[0].upper() + nom[1:]).encode(scu.SCO_ENCODING)
class EntreprisesEditor(EditableTable): class EntreprisesEditor(EditableTable):

View File

@ -667,7 +667,7 @@ def view_apo_csv_download_and_store(context, etape_apo="", semset_id="", REQUEST
) )
# here, data is utf8 # here, data is utf8
# but we store and generate latin1 files, to ease further import in Apogée # but we store and generate latin1 files, to ease further import in Apogée
data = data.decode(APO_PORTAL_ENCODING).encode(APO_INPUT_ENCODING) data = data.decode(APO_PORTAL_ENCODING).encode(APO_INPUT_ENCODING) # XXX #py3
return view_apo_csv_store( return view_apo_csv_store(
context, semset_id, data=data, autodetect=False, REQUEST=REQUEST context, semset_id, data=data, autodetect=False, REQUEST=REQUEST
) )

View File

@ -299,9 +299,9 @@ def check_nom_prenom(cnx, nom="", prenom="", etudid=None):
""" """
if not nom or (not prenom and not scu.CONFIG.ALLOW_NULL_PRENOM): if not nom or (not prenom and not scu.CONFIG.ALLOW_NULL_PRENOM):
return False, 0 return False, 0
nom = nom.decode(SCO_ENCODING).lower().strip().encode(SCO_ENCODING) nom = nom.lower().strip()
if prenom: if prenom:
prenom = prenom.decode(SCO_ENCODING).lower().strip().encode(SCO_ENCODING) prenom = prenom.lower().strip()
# Don't allow some special cars (eg used in sql regexps) # Don't allow some special cars (eg used in sql regexps)
if scu.FORBIDDEN_CHARS_EXP.search(nom) or scu.FORBIDDEN_CHARS_EXP.search(prenom): if scu.FORBIDDEN_CHARS_EXP.search(nom) or scu.FORBIDDEN_CHARS_EXP.search(prenom):
return False, 0 return False, 0

View File

@ -217,9 +217,7 @@ def search_etud_by_name(context, term, REQUEST=None):
# term = scu.strupper(term) # conserve les accents # term = scu.strupper(term) # conserve les accents
term = term.upper() term = term.upper()
if ( if (
not scu.ALPHANUM_EXP.match( not scu.ALPHANUM_EXP.match(term) # n'autorise pas les caractères spéciaux
term.decode(scu.SCO_ENCODING)
) # n'autorise pas les caractères spéciaux
and not may_be_nip and not may_be_nip
): ):
data = [] data = []

View File

@ -144,6 +144,7 @@ def _menuScolarite(context, authuser, sem, etudid):
def ficheEtud(context, etudid=None, REQUEST=None): def ficheEtud(context, etudid=None, REQUEST=None):
"fiche d'informations sur un etudiant" "fiche d'informations sur un etudiant"
log("XXX ficheEtud etudid=%s" % etudid)
authuser = REQUEST.AUTHENTICATED_USER authuser = REQUEST.AUTHENTICATED_USER
cnx = ndb.GetDBConnexion() cnx = ndb.GetDBConnexion()
if etudid and REQUEST: if etudid and REQUEST:

View File

@ -203,7 +203,7 @@ class ModuleTag(ScoTag):
def module_tag_search(context, term, REQUEST=None): def module_tag_search(context, term, REQUEST=None):
"""List all used tag names (for auto-completion)""" """List all used tag names (for auto-completion)"""
# restrict charset to avoid injections # restrict charset to avoid injections
if not scu.ALPHANUM_EXP.match(term.decode(scu.SCO_ENCODING)): if not scu.ALPHANUM_EXP.match(term):
data = [] data = []
else: else:
r = ndb.SimpleDictFetch( r = ndb.SimpleDictFetch(

View File

@ -375,7 +375,7 @@ def user_info_page(context, user_name=None, REQUEST=None):
'<p><a class="stdlink" href="%s">Liste de tous les utilisateurs</a></p>' '<p><a class="stdlink" href="%s">Liste de tous les utilisateurs</a></p>'
% url_for("users.index_html", scodoc_dept=g.scodoc_dept) % url_for("users.index_html", scodoc_dept=g.scodoc_dept)
) )
return scu.sco8_join(H) + F return "\n".join(H) + F
def check_modif_user(edit, user_name="", nom="", prenom="", email="", roles=[]): def check_modif_user(edit, user_name="", nom="", prenom="", email="", roles=[]):

View File

@ -65,10 +65,6 @@ from app.scodoc import sco_exceptions
from app.scodoc import sco_xml from app.scodoc import sco_xml
from app.scodoc import VERSION from app.scodoc import VERSION
# ----- TEMPORAIRE POUR MIGRATION SCODOC7 -> SCODOC8 avant python3
def sco8_join(L, sep="\n"): # sco8
return sep.join([x if not isinstance(x, str) else x.encode("utf-8") for x in L])
# ----- CALCUL ET PRESENTATION DES NOTES # ----- CALCUL ET PRESENTATION DES NOTES
NOTES_PRECISION = 1e-4 # evite eventuelles erreurs d'arrondis NOTES_PRECISION = 1e-4 # evite eventuelles erreurs d'arrondis
@ -344,7 +340,7 @@ def ScoURL():
""" """
return url_for("scolar.index_html", scodoc_dept=g.scodoc_dept)[ return url_for("scolar.index_html", scodoc_dept=g.scodoc_dept)[
: -len("/index_html") : -len("/index_html")
].encode(SCO_ENCODING) ]
def NotesURL(): def NotesURL():
@ -353,9 +349,7 @@ def NotesURL():
= url de base des méthodes de notes = url de base des méthodes de notes
(page accueil programmes). (page accueil programmes).
""" """
return url_for("notes.index_html", scodoc_dept=g.scodoc_dept)[ return url_for("notes.index_html", scodoc_dept=g.scodoc_dept)[: -len("/index_html")]
: -len("/index_html")
].encode(SCO_ENCODING)
def EntreprisesURL(): def EntreprisesURL():
@ -364,7 +358,7 @@ def EntreprisesURL():
= url de base des requêtes de ZEntreprises = url de base des requêtes de ZEntreprises
et page accueil Entreprises et page accueil Entreprises
""" """
return "NotImplemented".encode(SCO_ENCODING) return "NotImplemented"
# url_for("entreprises.index_html", scodoc_dept=g.scodoc_dept)[ # url_for("entreprises.index_html", scodoc_dept=g.scodoc_dept)[
# : -len("/index_html") # : -len("/index_html")
# ] # ]
@ -374,7 +368,7 @@ def AbsencesURL():
"""URL of Absences""" """URL of Absences"""
return url_for("absences.index_html", scodoc_dept=g.scodoc_dept)[ return url_for("absences.index_html", scodoc_dept=g.scodoc_dept)[
: -len("/index_html") : -len("/index_html")
].encode(SCO_ENCODING) ]
def UsersURL(): def UsersURL():
@ -383,11 +377,7 @@ def UsersURL():
= url de base des requêtes ZScoUsers = url de base des requêtes ZScoUsers
et page accueil users et page accueil users
""" """
return url_for("users.index_html", scodoc_dept=g.scodoc_dept)[ return url_for("users.index_html", scodoc_dept=g.scodoc_dept)[: -len("/index_html")]
: -len("/index_html")
].encode(
SCO_ENCODING
) # sco8
def get_current_user_name(REQUEST): def get_current_user_name(REQUEST):
@ -614,13 +604,13 @@ def strupper(s):
# return s.decode(SCO_ENCODING).upper().encode(SCO_ENCODING) # return s.decode(SCO_ENCODING).upper().encode(SCO_ENCODING)
# XXX fonctions inutiles en Python3 !
def strlower(s): def strlower(s):
return s.lower() return s.lower()
# return s.decode(SCO_ENCODING).lower().encode(SCO_ENCODING)
def strcapitalize(s): def strcapitalize(s):
return s.decode(SCO_ENCODING).capitalize().encode(SCO_ENCODING) return s.capitalize()
def abbrev_prenom(prenom): def abbrev_prenom(prenom):
@ -630,7 +620,7 @@ def abbrev_prenom(prenom):
# Charles -> Ch. # Charles -> Ch.
# Jean-Christophe -> J.-C. # Jean-Christophe -> J.-C.
# Marie Odile -> M. O. # Marie Odile -> M. O.
prenom = prenom.decode(SCO_ENCODING).replace(".", " ").strip() prenom = prenom.replace(".", " ").strip()
if not prenom: if not prenom:
return "" return ""
d = prenom[:3].upper() d = prenom[:3].upper()
@ -654,7 +644,7 @@ def abbrev_prenom(prenom):
if i < n: if i < n:
abrv += sep + prenom[i].upper() + "." abrv += sep + prenom[i].upper() + "."
i += 1 i += 1
return abrv.encode(SCO_ENCODING) return abrv
# #