1
0
forked from ScoDoc/ScoDoc

fixed some string ops

This commit is contained in:
Emmanuel Viennet 2021-07-12 00:25:23 +02:00
parent 7d7b4df103
commit 5a9eade31b
8 changed files with 42 additions and 38 deletions

View File

@ -41,19 +41,19 @@ class ZRequest(object):
"Emulating Zope 2 REQUEST" "Emulating Zope 2 REQUEST"
def __init__(self): def __init__(self):
self.URL = request.base_url.encode( self.URL = (
"utf-8" request.base_url
) # necessaire pour ScoDoc 8 en Python 2 #sco8 ) # .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 # .encode("utf-8")
self.QUERY_STRING = request.query_string.encode("utf-8") self.QUERY_STRING = request.query_string # .encode("utf-8")
self.REQUEST_METHOD = request.method.encode("utf-8") self.REQUEST_METHOD = request.method # .encode("utf-8")
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 ! self.form = request.form # xxx encode en utf-8 !
# Encode en utf-8 pour ScoDoc8 #sco8 # Encode en utf-8 pour ScoDoc8 #sco8
self.form = {k: v.encode("utf-8") for (k, v) in request.form.items()} # self.form = {k: v.encode("utf-8") for (k, v) in request.form.items()}
if request.files: if request.files:
# Add files in form: must copy to get a mutable version # 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
@ -64,8 +64,9 @@ class ZRequest(object):
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
# Encode en utf-8 pour ScoDoc8 #sco8 # Encode en utf-8 pour ScoDoc8 #sco8
self.form = {k: v.encode("utf-8") for (k, v) in request.args.items()} # 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):
@ -88,7 +89,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) # .decode("utf-8")) # http 302 # #sco8 unicode
def setHeader(self, header, value): def setHeader(self, header, value):
self.headers[header.lower()] = value self.headers[header.lower()] = value
@ -99,7 +100,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"] # .encode("utf-8") # sco8
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)
@ -147,7 +148,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"] # .encode("utf-8") # sco8
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
@ -159,7 +160,7 @@ def scodoc7func(context):
req_args = REQUEST.form # args from query string (get) or form (post) req_args = REQUEST.form # args from query string (get) or form (post)
# --- Add positional arguments # --- Add positional arguments
pos_arg_values = [] pos_arg_values = []
# PY3 à remplacer par inspect.getfullargspec en py3: # PY3 à remplacer par inspect.getfullargspec en py3: TODO
argspec = inspect.getargspec(func) argspec = inspect.getargspec(func)
current_app.logger.info("argspec=%s" % str(argspec)) current_app.logger.info("argspec=%s" % str(argspec))
nb_default_args = len(argspec.defaults) if argspec.defaults else 0 nb_default_args = len(argspec.defaults) if argspec.defaults else 0
@ -174,9 +175,9 @@ def scodoc7func(context):
pos_arg_values.append(context) pos_arg_values.append(context)
else: else:
# XXX Convert to regular string for ScoDoc8/Python 2 #py3 # XXX Convert to regular string for ScoDoc8/Python 2 #py3
if isinstance(req_args[arg_name], str): # if isinstance(req_args[arg_name], str):
pos_arg_values.append(req_args[arg_name].encode("utf-8")) # pos_arg_values.append(req_args[arg_name].encode("utf-8"))
else: # 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)
# Add keyword arguments # Add keyword arguments
@ -187,9 +188,9 @@ def scodoc7func(context):
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 # XXX Convert to regular string for ScoDoc8/Python 2 #py3
if isinstance(req_args[arg_name], str): # if isinstance(req_args[arg_name], str):
kwargs[arg_name] = req_args[arg_name].encode("utf-8") # kwargs[arg_name] = req_args[arg_name].encode("utf-8")
else: # 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

@ -1,4 +1,5 @@
alembic==1.6.5 alembic==1.6.5
astroid==2.6.2
Babel==2.9.1 Babel==2.9.1
blinker==1.4 blinker==1.4
certifi==2021.5.30 certifi==2021.5.30
@ -22,14 +23,19 @@ html2text==2020.1.16
icalendar==4.0.7 icalendar==4.0.7
idna==2.10 idna==2.10
importlib-metadata==4.6.1 importlib-metadata==4.6.1
isort==5.9.2
itsdangerous==2.0.1 itsdangerous==2.0.1
Jinja2==3.0.1 Jinja2==3.0.1
lazy-object-proxy==1.6.0
Mako==1.1.4 Mako==1.1.4
MarkupSafe==2.0.1 MarkupSafe==2.0.1
mccabe==0.6.1
Pillow==8.3.1 Pillow==8.3.1
pkg-resources==0.0.0 pkg-resources==0.0.0
psycopg2==2.9.1 psycopg2==2.9.1
PyJWT==2.1.0 PyJWT==2.1.0
pylint==2.9.3
pylint-flask-sqlalchemy==0.2.0
PyRSS2Gen==1.1 PyRSS2Gen==1.1
python-dateutil==2.8.1 python-dateutil==2.8.1
python-dotenv==0.18.0 python-dotenv==0.18.0
@ -39,9 +45,12 @@ reportlab==3.5.68
requests==2.25.1 requests==2.25.1
six==1.16.0 six==1.16.0
SQLAlchemy==1.4.20 SQLAlchemy==1.4.20
toml==0.10.2
typed-ast==1.4.3
typing-extensions==3.10.0.0 typing-extensions==3.10.0.0
urllib3==1.26.6 urllib3==1.26.6
visitor==0.1.3 visitor==0.1.3
Werkzeug==2.0.1 Werkzeug==2.0.1
wrapt==1.12.1
WTForms==2.3.3 WTForms==2.3.3
zipp==3.5.0 zipp==3.5.0

View File

@ -1060,7 +1060,7 @@ def invalidateAbsEtudDate(context, etudid, date):
Invalide cache absence et PDF bulletins si nécessaire. Invalide cache absence et PDF bulletins si nécessaire.
date: date au format ISO date: date au format ISO
""" """
import sco_compute_moy from app.scodoc import sco_compute_moy
# Semestres a cette date: # Semestres a cette date:
etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0] etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0]

View File

@ -143,14 +143,7 @@ def format_prenom(s):
r = [] r = []
for frag in frags: for frag in frags:
fs = frag.split("-") fs = frag.split("-")
r.append( r.append("-".join([x.lower().capitalize() for x in fs]))
"-".join(
[
x.decode(SCO_ENCODING).lower().capitalize().encode(SCO_ENCODING)
for x in fs
]
)
)
return " ".join(r) return " ".join(r)

View File

@ -128,8 +128,8 @@ def do_formsemestre_list(context, *a, **kw):
def formsemestre_enrich(context, sem): def formsemestre_enrich(context, sem):
"""Ajoute champs souvent utiles: titre + annee et dateord (pour tris)""" """Ajoute champs souvent utiles: titre + annee et dateord (pour tris)"""
# imports ici pour eviter refs circulaires # imports ici pour eviter refs circulaires
import sco_formsemestre_edit from app.scodoc import sco_formsemestre_edit
import sco_etud from app.scodoc import sco_etud
from app.views import notes from app.views import notes
F = notes.formation_list(context, args={"formation_id": sem["formation_id"]})[0] F = notes.formation_list(context, args={"formation_id": sem["formation_id"]})[0]

View File

@ -1444,7 +1444,7 @@ def do_formsemestre_delete(context, formsemestre_id, REQUEST):
sco_formsemestre._formsemestreEditor.delete(cnx, formsemestre_id) sco_formsemestre._formsemestreEditor.delete(cnx, formsemestre_id)
# news # news
import sco_news from app.scodoc import sco_news
sco_news.add( sco_news.add(
context, context,

View File

@ -603,14 +603,15 @@ def check_scodoc7_password(scodoc7_hash, password):
# Simple string manipulations # Simple string manipulations
# on utf-8 encoded python strings # not necessary anymore in Python 3 ! TODO remove
# (yes, we should only use unicode strings, but... we use only strings)
def strupper(s): def strupper(s):
return s.decode(SCO_ENCODING).upper().encode(SCO_ENCODING) return s.upper()
# return s.decode(SCO_ENCODING).upper().encode(SCO_ENCODING)
def strlower(s): def strlower(s):
return s.decode(SCO_ENCODING).lower().encode(SCO_ENCODING) return s.lower()
# return s.decode(SCO_ENCODING).lower().encode(SCO_ENCODING)
def strcapitalize(s): def strcapitalize(s):

View File

@ -53,7 +53,7 @@ def get_users_cnx_str():
"db cnx string for users database (used only during upgrades to modify db schema)" "db cnx string for users database (used only during upgrades to modify db schema)"
# uses default in sco_utils # uses default in sco_utils
# For customized installs, define the value here (used only during upgrades) # For customized installs, define the value here (used only during upgrades)
import sco_utils from app.scodoc import sco_utils
return sco_utils.SCO_DEFAULT_SQL_USERS_CNX return sco_utils.SCO_DEFAULT_SQL_USERS_CNX