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"
def __init__(self):
self.URL = request.base_url.encode(
"utf-8"
) # necessaire pour ScoDoc 8 en Python 2 #sco8
self.URL = (
request.base_url
) # .encode("utf-8") # necessaire pour ScoDoc 8 en Python 2 #sco8
self.URL0 = self.URL
self.BASE0 = request.url_root.encode("utf-8")
self.QUERY_STRING = request.query_string.encode("utf-8")
self.REQUEST_METHOD = request.method.encode("utf-8")
self.BASE0 = request.url_root # .encode("utf-8")
self.QUERY_STRING = request.query_string # .encode("utf-8")
self.REQUEST_METHOD = request.method # .encode("utf-8")
self.AUTHENTICATED_USER = current_user
self.REMOTE_ADDR = request.remote_addr
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
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:
# Add files in form: must copy to get a mutable version
# request.form is a werkzeug.datastructures.ImmutableMultiDict
@ -64,8 +64,9 @@ class ZRequest(object):
if k.endswith(":list"):
self.form[k[:-5]] = request.form.getlist(k)
elif request.method == "GET":
self.form = {k: v for (k, v) in request.args.items()} # forme python3
# 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()
def __str__(self):
@ -88,7 +89,7 @@ class ZResponse(object):
def redirect(self, 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):
self.headers[header.lower()] = value
@ -99,7 +100,7 @@ def permission_required(permission):
@wraps(f)
def decorated_function(*args, **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"]
# current_app.logger.info(
# "permission_required: %s in %s" % (permission, g.scodoc_dept)
@ -147,7 +148,7 @@ def scodoc7func(context):
return func(*args, **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"]
elif not hasattr(g, "scodoc_dept"):
g.scodoc_dept = None
@ -159,7 +160,7 @@ def scodoc7func(context):
req_args = REQUEST.form # args from query string (get) or form (post)
# --- Add positional arguments
pos_arg_values = []
# PY3 à remplacer par inspect.getfullargspec en py3:
# PY3 à remplacer par inspect.getfullargspec en py3: TODO
argspec = inspect.getargspec(func)
current_app.logger.info("argspec=%s" % str(argspec))
nb_default_args = len(argspec.defaults) if argspec.defaults else 0
@ -174,10 +175,10 @@ def scodoc7func(context):
pos_arg_values.append(context)
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])
# 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])
current_app.logger.info("pos_arg_values=%s" % pos_arg_values)
# Add keyword arguments
if nb_default_args:
@ -187,10 +188,10 @@ def scodoc7func(context):
elif arg_name in req_args:
# 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]
# 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]
current_app.logger.info(
"scodoc7func_decorator: top_level=%s, pos_arg_values=%s, kwargs=%s"
% (top_level, pos_arg_values, kwargs)

View File

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

View File

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

View File

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

View File

@ -128,8 +128,8 @@ def do_formsemestre_list(context, *a, **kw):
def formsemestre_enrich(context, sem):
"""Ajoute champs souvent utiles: titre + annee et dateord (pour tris)"""
# imports ici pour eviter refs circulaires
import sco_formsemestre_edit
import sco_etud
from app.scodoc import sco_formsemestre_edit
from app.scodoc import sco_etud
from app.views import notes
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)
# news
import sco_news
from app.scodoc import sco_news
sco_news.add(
context,

View File

@ -603,14 +603,15 @@ def check_scodoc7_password(scodoc7_hash, password):
# Simple string manipulations
# on utf-8 encoded python strings
# (yes, we should only use unicode strings, but... we use only strings)
# not necessary anymore in Python 3 ! TODO remove
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):
return s.decode(SCO_ENCODING).lower().encode(SCO_ENCODING)
return s.lower()
# return s.decode(SCO_ENCODING).lower().encode(SCO_ENCODING)
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)"
# uses default in sco_utils
# 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