forked from ScoDoc/ScoDoc
modernized type checking
This commit is contained in:
parent
def8b1e6a2
commit
e08f35cb80
@ -174,7 +174,7 @@ 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 type(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])
|
||||||
@ -187,7 +187,7 @@ 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 type(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]
|
||||||
@ -236,7 +236,7 @@ class ScoDoc7Context(object):
|
|||||||
logging.getLogger(__name__).info("populating context %s" % self)
|
logging.getLogger(__name__).info("populating context %s" % self)
|
||||||
for k in globals_dict:
|
for k in globals_dict:
|
||||||
if (not k.startswith("_")) and (
|
if (not k.startswith("_")) and (
|
||||||
type(globals_dict[k]) == types.FunctionType
|
isinstance(globals_dict[k], types.FunctionType)
|
||||||
):
|
):
|
||||||
setattr(self, k, globals_dict[k].__get__(self))
|
setattr(self, k, globals_dict[k].__get__(self))
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
"""Calculs sur les notes et cache des resultats
|
"""Calculs sur les notes et cache des resultats
|
||||||
"""
|
"""
|
||||||
from types import FloatType
|
|
||||||
import time
|
import time
|
||||||
import pdb
|
import pdb
|
||||||
import inspect
|
import inspect
|
||||||
@ -349,7 +348,7 @@ class NotesTable(object):
|
|||||||
(self.moy_ue[ue_id][etudid], etudid) for etudid in self.moy_ue[ue_id]
|
(self.moy_ue[ue_id][etudid], etudid) for etudid in self.moy_ue[ue_id]
|
||||||
]
|
]
|
||||||
ue_eff = len(
|
ue_eff = len(
|
||||||
[x for x in val_ids if type(x[0]) == FloatType]
|
[x for x in val_ids if isinstance(x[0], float)]
|
||||||
) # nombre d'étudiants avec une note dans l'UE
|
) # nombre d'étudiants avec une note dans l'UE
|
||||||
val_ids.sort(key=row_key)
|
val_ids.sort(key=row_key)
|
||||||
ue_rangs[ue_id] = (
|
ue_rangs[ue_id] = (
|
||||||
@ -845,7 +844,7 @@ class NotesTable(object):
|
|||||||
mu["event_date"] = event_date
|
mu["event_date"] = event_date
|
||||||
# - ECTS ? ("pot" pour "potentiels" car les ECTS ne seront acquises qu'apres validation du jury
|
# - ECTS ? ("pot" pour "potentiels" car les ECTS ne seront acquises qu'apres validation du jury
|
||||||
if (
|
if (
|
||||||
type(mu["moy"]) == FloatType
|
isinstance(mu["moy"], float)
|
||||||
and mu["moy"] >= self.parcours.NOTES_BARRE_VALID_UE
|
and mu["moy"] >= self.parcours.NOTES_BARRE_VALID_UE
|
||||||
):
|
):
|
||||||
mu["ects_pot"] = ue["ects"] or 0.0
|
mu["ects_pot"] = ue["ects"] or 0.0
|
||||||
@ -1182,7 +1181,7 @@ class NotesTable(object):
|
|||||||
]
|
]
|
||||||
ue_cap["moy_ue"] = moy_ue_cap
|
ue_cap["moy_ue"] = moy_ue_cap
|
||||||
if (
|
if (
|
||||||
type(moy_ue_cap) == FloatType
|
isinstance(moy_ue_cap, float)
|
||||||
and moy_ue_cap >= self.parcours.NOTES_BARRE_VALID_UE
|
and moy_ue_cap >= self.parcours.NOTES_BARRE_VALID_UE
|
||||||
):
|
):
|
||||||
if not cnx:
|
if not cnx:
|
||||||
|
@ -81,7 +81,6 @@ XXX A vérifier:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
from types import FloatType
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
@ -154,7 +153,7 @@ def code_scodoc_to_apo(code):
|
|||||||
|
|
||||||
def _apo_fmt_note(note):
|
def _apo_fmt_note(note):
|
||||||
"Formatte une note pour Apogée (séparateur décimal: ',')"
|
"Formatte une note pour Apogée (séparateur décimal: ',')"
|
||||||
if not note and type(note) != FloatType:
|
if not note and isinstance(note, float):
|
||||||
return ""
|
return ""
|
||||||
try:
|
try:
|
||||||
val = float(note)
|
val = float(note)
|
||||||
|
@ -238,7 +238,7 @@ class TypeParcours(object):
|
|||||||
ue_status
|
ue_status
|
||||||
for ue_status in ues_status
|
for ue_status in ues_status
|
||||||
if ue_status["coef_ue"] > 0
|
if ue_status["coef_ue"] > 0
|
||||||
and type(ue_status["moy"]) == float
|
and isinstance(ue_status["moy"], float)
|
||||||
and ue_status["moy"] < self.get_barre_ue(ue_status["ue"]["type"])
|
and ue_status["moy"] < self.get_barre_ue(ue_status["ue"]["type"])
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import pprint
|
import pprint
|
||||||
from types import FloatType
|
|
||||||
|
|
||||||
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
|
||||||
@ -355,7 +354,7 @@ def do_moduleimpl_moyennes(context, nt, mod):
|
|||||||
if etudid in eval_rattr["notes"]:
|
if etudid in eval_rattr["notes"]:
|
||||||
note = eval_rattr["notes"][etudid]["value"]
|
note = eval_rattr["notes"][etudid]["value"]
|
||||||
if note != None and note != NOTES_NEUTRALISE and note != NOTES_ATTENTE:
|
if note != None and note != NOTES_NEUTRALISE and note != NOTES_ATTENTE:
|
||||||
if type(R[etudid]) != FloatType:
|
if isinstance(R[etudid], float):
|
||||||
R[etudid] = note
|
R[etudid] = note
|
||||||
else:
|
else:
|
||||||
note_sur_20 = note * 20.0 / eval_rattr["note_max"]
|
note_sur_20 = note * 20.0 / eval_rattr["note_max"]
|
||||||
|
@ -29,9 +29,9 @@
|
|||||||
""" Excel file handling
|
""" Excel file handling
|
||||||
"""
|
"""
|
||||||
import time, datetime
|
import time, datetime
|
||||||
from types import IntType, FloatType, LongType
|
|
||||||
|
|
||||||
from pyExcelerator import *
|
# #sco8 #py3 XXX TODO A revoir utiliser d'autres modules
|
||||||
|
# from pyExcelerator import *
|
||||||
|
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
from app.scodoc import notesdb
|
from app.scodoc import notesdb
|
||||||
@ -226,10 +226,9 @@ class ScoExcelSheet(object):
|
|||||||
co = 0
|
co = 0
|
||||||
for c in l:
|
for c in l:
|
||||||
# safety net: allow only str, int and float
|
# safety net: allow only str, int and float
|
||||||
if type(c) == LongType:
|
# #py3 #sco8 A revoir lors de la ré-écriture de ce module
|
||||||
c = int(c) # assume all ScoDoc longs fits in int !
|
# XXX if type(c) not in (IntType, FloatType):
|
||||||
elif type(c) not in (IntType, FloatType):
|
# c = str(c).decode(scu.SCO_ENCODING)
|
||||||
c = str(c).decode(scu.SCO_ENCODING)
|
|
||||||
|
|
||||||
ws0.write(li, co, c, self.get_cell_style(li, co))
|
ws0.write(li, co, c, self.get_cell_style(li, co))
|
||||||
co += 1
|
co += 1
|
||||||
@ -263,9 +262,9 @@ def Excel_SimpleTable(titles=[], lines=[[]], SheetName="feuille", titlesStyles=[
|
|||||||
for it in l:
|
for it in l:
|
||||||
cell_style = default_style
|
cell_style = default_style
|
||||||
# safety net: allow only str, int and float
|
# safety net: allow only str, int and float
|
||||||
if type(it) == LongType:
|
if isinstance(it, LongType): # XXX
|
||||||
it = int(it) # assume all ScoDoc longs fits in int !
|
it = int(it) # assume all ScoDoc longs fits in int !
|
||||||
elif type(it) not in (IntType, FloatType):
|
elif type(it) not in (IntType, FloatType): # XXX A REVOIR
|
||||||
it = str(it).decode(scu.SCO_ENCODING)
|
it = str(it).decode(scu.SCO_ENCODING)
|
||||||
cell_style = text_style
|
cell_style = text_style
|
||||||
ws0.write(li, col, it, cell_style)
|
ws0.write(li, col, it, cell_style)
|
||||||
|
@ -508,7 +508,7 @@ def retreive_formsemestre_from_request(context, REQUEST):
|
|||||||
formsemestre_id = group["formsemestre_id"]
|
formsemestre_id = group["formsemestre_id"]
|
||||||
elif group_ids:
|
elif group_ids:
|
||||||
if group_ids:
|
if group_ids:
|
||||||
if type(group_ids) == str:
|
if isinstance(group_ids, str):
|
||||||
group_id = group_ids
|
group_id = group_ids
|
||||||
else:
|
else:
|
||||||
# prend le semestre du 1er groupe de la liste:
|
# prend le semestre du 1er groupe de la liste:
|
||||||
@ -781,7 +781,10 @@ def _make_listes_sem(context, sem, REQUEST=None, with_absences=True):
|
|||||||
query_args = cgi.parse_qs(REQUEST.QUERY_STRING)
|
query_args = cgi.parse_qs(REQUEST.QUERY_STRING)
|
||||||
if "head_message" in query_args:
|
if "head_message" in query_args:
|
||||||
del query_args["head_message"]
|
del query_args["head_message"]
|
||||||
destination = "%s?%s" % (REQUEST.URL, six.moves.urllib.parse.urlencode(query_args, True))
|
destination = "%s?%s" % (
|
||||||
|
REQUEST.URL,
|
||||||
|
six.moves.urllib.parse.urlencode(query_args, True),
|
||||||
|
)
|
||||||
destination = destination.replace(
|
destination = destination.replace(
|
||||||
"%", "%%"
|
"%", "%%"
|
||||||
) # car ici utilisee dans un format string !
|
) # car ici utilisee dans un format string !
|
||||||
|
@ -991,7 +991,7 @@ def formsemestre_fix_validation_ues(context, formsemestre_id, REQUEST=None):
|
|||||||
moy_ue = ue_status["moy"]
|
moy_ue = ue_status["moy"]
|
||||||
if valid_semestre:
|
if valid_semestre:
|
||||||
if (
|
if (
|
||||||
type(moy_ue) == FloatType
|
isinstance(moy_ue, float)
|
||||||
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
|
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
|
||||||
):
|
):
|
||||||
code_ue = ADM
|
code_ue = ADM
|
||||||
@ -1001,7 +1001,7 @@ def formsemestre_fix_validation_ues(context, formsemestre_id, REQUEST=None):
|
|||||||
if not decision_sem["assidu"]:
|
if not decision_sem["assidu"]:
|
||||||
code_ue = AJ
|
code_ue = AJ
|
||||||
elif (
|
elif (
|
||||||
type(moy_ue) == FloatType
|
isinstance(moy_ue, float)
|
||||||
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
|
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
|
||||||
):
|
):
|
||||||
code_ue = ADM
|
code_ue = ADM
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
from types import FloatType, IntType, LongType
|
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
|
|
||||||
@ -125,17 +124,17 @@ class NoteVector(object):
|
|||||||
return binary_op(x, self.v, operator.floordiv)
|
return binary_op(x, self.v, operator.floordiv)
|
||||||
|
|
||||||
|
|
||||||
def isScalar(x):
|
def is_scalar(x):
|
||||||
return isinstance(x, FloatType) or isinstance(x, IntType) or isinstance(x, LongType)
|
return isinstance(x, (float, int))
|
||||||
|
|
||||||
|
|
||||||
def binary_op(x, y, op):
|
def binary_op(x, y, op):
|
||||||
if isScalar(x):
|
if is_scalar(x):
|
||||||
if isScalar(y):
|
if is_scalar(y):
|
||||||
x, y = [x], [y]
|
x, y = [x], [y]
|
||||||
else:
|
else:
|
||||||
x = [x] * len(y)
|
x = [x] * len(y)
|
||||||
if isScalar(y):
|
if is_scalar(y):
|
||||||
y = [y] * len(x)
|
y = [y] * len(x)
|
||||||
|
|
||||||
if len(x) != len(y):
|
if len(x) != len(y):
|
||||||
|
@ -317,7 +317,7 @@ class DisplayedGroupsInfos(object):
|
|||||||
REQUEST=None,
|
REQUEST=None,
|
||||||
):
|
):
|
||||||
# log('DisplayedGroupsInfos %s' % group_ids)
|
# log('DisplayedGroupsInfos %s' % group_ids)
|
||||||
if type(group_ids) == str:
|
if isinstance(group_ids, str):
|
||||||
if group_ids:
|
if group_ids:
|
||||||
group_ids = [group_ids] # cas ou un seul parametre, pas de liste
|
group_ids = [group_ids] # cas ou un seul parametre, pas de liste
|
||||||
else:
|
else:
|
||||||
|
@ -779,7 +779,7 @@ def adm_get_fields(titles, formsemestre_id):
|
|||||||
|
|
||||||
|
|
||||||
def adm_convert_text(v):
|
def adm_convert_text(v):
|
||||||
if type(v) == float:
|
if isinstance(v, float):
|
||||||
return "{:g}".format(v) # evite "1.0"
|
return "{:g}".format(v) # evite "1.0"
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
"""Semestres: gestion parcours DUT (Arreté du 13 août 2005)
|
"""Semestres: gestion parcours DUT (Arreté du 13 août 2005)
|
||||||
"""
|
"""
|
||||||
from types import FloatType
|
|
||||||
|
|
||||||
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
|
||||||
@ -417,7 +416,7 @@ class SituationEtudParcoursGeneric(object):
|
|||||||
self.etudid
|
self.etudid
|
||||||
)
|
)
|
||||||
self.moy_gen = self.nt.get_etud_moy_gen(self.etudid)
|
self.moy_gen = self.nt.get_etud_moy_gen(self.etudid)
|
||||||
self.barre_moy_ok = (type(self.moy_gen) == FloatType) and (
|
self.barre_moy_ok = (isinstance(self.moy_gen, float)) and (
|
||||||
self.moy_gen >= (self.parcours.BARRE_MOY - scu.NOTES_TOLERANCE)
|
self.moy_gen >= (self.parcours.BARRE_MOY - scu.NOTES_TOLERANCE)
|
||||||
)
|
)
|
||||||
# conserve etat UEs
|
# conserve etat UEs
|
||||||
@ -921,11 +920,11 @@ def formsemestre_validate_ues(
|
|||||||
else:
|
else:
|
||||||
# log('%s: %s: ue_status=%s' % (formsemestre_id,ue_id,ue_status))
|
# log('%s: %s: ue_status=%s' % (formsemestre_id,ue_id,ue_status))
|
||||||
if (
|
if (
|
||||||
type(ue_status["moy"]) == FloatType
|
isinstance(ue_status["moy"], float)
|
||||||
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
|
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
|
||||||
):
|
):
|
||||||
code_ue = ADM
|
code_ue = ADM
|
||||||
elif type(ue_status["moy"]) != FloatType:
|
elif isinstance(ue_status["moy"], float):
|
||||||
# aucune note (pas de moyenne) dans l'UE: ne la valide pas
|
# aucune note (pas de moyenne) dans l'UE: ne la valide pas
|
||||||
code_ue = None
|
code_ue = None
|
||||||
elif valid_semestre:
|
elif valid_semestre:
|
||||||
|
@ -835,7 +835,7 @@ def _pvjury_pdf_type(
|
|||||||
|
|
||||||
def _format_pv_cell(x):
|
def _format_pv_cell(x):
|
||||||
"""convert string to paragraph"""
|
"""convert string to paragraph"""
|
||||||
if type(x) == bytes:
|
if isinstance(x, bytes):
|
||||||
return Paragraph(SU(x), cell_style)
|
return Paragraph(SU(x), cell_style)
|
||||||
else:
|
else:
|
||||||
return x
|
return x
|
||||||
|
@ -246,7 +246,7 @@ def module_tag_set(context, module_id="", taglist=[], REQUEST=None):
|
|||||||
#
|
#
|
||||||
if not taglist:
|
if not taglist:
|
||||||
taglist = []
|
taglist = []
|
||||||
elif type(taglist) == bytes:
|
elif isinstance(taglist, bytes):
|
||||||
taglist = taglist.split(",")
|
taglist = taglist.split(",")
|
||||||
taglist = [t.strip() for t in taglist]
|
taglist = [t.strip() for t in taglist]
|
||||||
log("module_tag_set: module_id=%s taglist=%s" % (module_id, taglist))
|
log("module_tag_set: module_id=%s taglist=%s" % (module_id, taglist))
|
||||||
|
@ -132,7 +132,7 @@ def fmt_note(val, note_max=None, keep_numeric=False):
|
|||||||
return "EXC" # excuse, note neutralise
|
return "EXC" # excuse, note neutralise
|
||||||
if val == NOTES_ATTENTE:
|
if val == NOTES_ATTENTE:
|
||||||
return "ATT" # attente, note neutralisee
|
return "ATT" # attente, note neutralisee
|
||||||
if type(val) == float or type(val) == int:
|
if isinstance(val, float) or isinstance(val, int):
|
||||||
if note_max != None and note_max > 0:
|
if note_max != None and note_max > 0:
|
||||||
val = val * 20.0 / note_max
|
val = val * 20.0 / note_max
|
||||||
if keep_numeric:
|
if keep_numeric:
|
||||||
@ -434,7 +434,7 @@ def unescape_html_dict(d):
|
|||||||
indices = list(range(len(d)))
|
indices = list(range(len(d)))
|
||||||
for k in indices:
|
for k in indices:
|
||||||
v = d[k]
|
v = d[k]
|
||||||
if type(v) == bytes:
|
if isinstance(v, bytes):
|
||||||
d[k] = unescape_html(v)
|
d[k] = unescape_html(v)
|
||||||
elif isiterable(v):
|
elif isiterable(v):
|
||||||
unescape_html_dict(v)
|
unescape_html_dict(v)
|
||||||
|
@ -63,7 +63,7 @@ class ApoEtapeVDI(object):
|
|||||||
"""
|
"""
|
||||||
if other is None:
|
if other is None:
|
||||||
return -1
|
return -1
|
||||||
if type(other) == str:
|
if isinstance(other, str):
|
||||||
other = ApoEtapeVDI(other)
|
other = ApoEtapeVDI(other)
|
||||||
|
|
||||||
if self.vdi and other.vdi:
|
if self.vdi and other.vdi:
|
||||||
|
Loading…
Reference in New Issue
Block a user