From 49e95d0085f5b5e0a0b9b126ca7a0f6407a52d81 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 11 Jul 2021 23:02:35 +0200 Subject: [PATCH] fixed cStringIO uses --- app/scodoc/sco_bulletins_generator.py | 8 ++++++-- app/scodoc/sco_bulletins_pdf.py | 7 +++++-- app/scodoc/sco_groups.py | 3 +-- app/scodoc/sco_pdf.py | 2 +- app/scodoc/sco_pvpdf.py | 13 ++++++++----- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/scodoc/sco_bulletins_generator.py b/app/scodoc/sco_bulletins_generator.py index 6e7539150..70557dfcd 100644 --- a/app/scodoc/sco_bulletins_generator.py +++ b/app/scodoc/sco_bulletins_generator.py @@ -43,9 +43,13 @@ La préférence 'bul_pdf_class_name' est obsolete (inutilisée). """ import time -import cStringIO import collections import traceback + +try: + from io import StringIO # for Python 3 +except ImportError: + from cStringIO import StringIO # for Python 2 import reportlab from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Frame, PageBreak from reportlab.platypus import Table, TableStyle, Image, KeepInFrame @@ -215,7 +219,7 @@ class BulletinGenerator(object): else: # Generation du document PDF sem = sco_formsemestre.get_formsemestre(self.context, formsemestre_id) - report = cStringIO.StringIO() # in-memory document, no disk file + report = StringIO.StringIO() # in-memory document, no disk file document = sco_pdf.BaseDocTemplate(report) document.addPageTemplates( sco_pdf.ScolarsPageTemplate( diff --git a/app/scodoc/sco_bulletins_pdf.py b/app/scodoc/sco_bulletins_pdf.py index eca31dead..f848f90bb 100644 --- a/app/scodoc/sco_bulletins_pdf.py +++ b/app/scodoc/sco_bulletins_pdf.py @@ -54,8 +54,11 @@ import time import traceback import re import os -import cStringIO +try: + from io import StringIO # for Python 3 +except ImportError: + from cStringIO import StringIO # for Python 2 from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate from app.scodoc import VERSION @@ -89,7 +92,7 @@ def pdfassemblebulletins( sco_preferences.get_preference(context, "bottom_margin", formsemestre_id), ) - report = cStringIO.StringIO() # in-memory document, no disk file + report = StringIO.StringIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.addPageTemplates( sco_pdf.ScolarsPageTemplate( diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 96b49e60c..cdef47ace 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -36,7 +36,6 @@ Optimisation possible: import time import collections import re -import sets import operator import xml.dom.minidom @@ -1274,7 +1273,7 @@ def groups_auto_repartition(context, partition_id=None, REQUEST=None): ) # > identdict identdict = nt.identdict # build: { civilite : liste etudids trie par niveau croissant } - civilites = sets.Set([x["civilite"] for x in identdict.values()]) + civilites = set([x["civilite"] for x in identdict.values()]) listes = {} for civilite in civilites: listes[civilite] = [ diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index a2a5f33cd..66050dff3 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -314,7 +314,7 @@ def pdf_basic_page( adding a title if specified. """ StyleSheet = styles.getSampleStyleSheet() - report = cStringIO.StringIO() # in-memory document, no disk file + report = StringIO.StringIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.addPageTemplates( ScolarsPageTemplate( diff --git a/app/scodoc/sco_pvpdf.py b/app/scodoc/sco_pvpdf.py index 11b9d99c0..315aedec7 100644 --- a/app/scodoc/sco_pvpdf.py +++ b/app/scodoc/sco_pvpdf.py @@ -28,9 +28,12 @@ """Edition des PV de jury """ import os -import types import re -import cStringIO + +try: + from io import StringIO # for Python 3 +except ImportError: + from cStringIO import StringIO # for Python 2 import reportlab from reportlab.lib.units import cm, mm from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY @@ -387,7 +390,7 @@ def pdf_lettres_individuelles( ) # ----- Build PDF - report = cStringIO.StringIO() # in-memory document, no disk file + report = StringIO.StringIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.addPageTemplates( CourrierIndividuelTemplate( @@ -587,7 +590,7 @@ def _make_signature_image(signature, leftindent, formsemestre_id, context=None): # cree une image PIL pour avoir la taille (W,H) from PIL import Image as PILImage - f = cStringIO.StringIO(signature) + f = StringIO.StringIO(signature) im = PILImage.open(f) width, height = im.size pdfheight = ( @@ -671,7 +674,7 @@ def pvjury_pdf( ) # ----- Build PDF - report = cStringIO.StringIO() # in-memory document, no disk file + report = StringIO.StringIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.pagesize = landscape(A4) document.addPageTemplates(