From 0252bf4df48b5762b7f5f114dd0e20c758a307f5 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 26 Jul 2021 18:11:00 +0300 Subject: [PATCH] Fix: bytes I/O (zips and pdfs) --- app/scodoc/sco_trombino.py | 10 +++++----- app/scodoc/sco_trombino_tours.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/scodoc/sco_trombino.py b/app/scodoc/sco_trombino.py index e603270be9..eb303fda75 100644 --- a/app/scodoc/sco_trombino.py +++ b/app/scodoc/sco_trombino.py @@ -28,7 +28,7 @@ """Photos: trombinoscopes """ -from io import StringIO +import io from zipfile import ZipFile, BadZipfile import reportlab from reportlab.lib.units import cm, mm @@ -221,7 +221,7 @@ def check_local_photos_availability(context, groups_infos, REQUEST, format=""): def _trombino_zip(context, groups_infos, REQUEST): "Send photos as zip archive" - data = StringIO() + data = io.BytesIO() Z = ZipFile(data, "w") # assume we have the photos (or the user acknowledged the fact) # Archive originals (not reduced) images, in JPEG @@ -229,7 +229,7 @@ def _trombino_zip(context, groups_infos, REQUEST): im_path = sco_photos.photo_pathname(context, t, size="orig") if not im_path: continue - img = open(im_path).read() + img = open(im_path, "rb").read() code_nip = t["code_nip"] if code_nip: filename = code_nip + ".jpg" @@ -337,7 +337,7 @@ def _trombino_pdf(context, groups_infos, REQUEST): N_PER_ROW = 5 # XXX should be in ScoDoc preferences StyleSheet = styles.getSampleStyleSheet() - report = StringIO() # in-memory document, no disk file + report = io.BytesIO() # in-memory document, no disk file objects = [ Paragraph( SU("Trombinoscope " + sem["titreannee"] + " " + groups_infos.groups_titles), @@ -411,7 +411,7 @@ def _listeappel_photos_pdf(context, groups_infos, REQUEST): # ROWS_PER_PAGE = 26 # XXX should be in ScoDoc preferences StyleSheet = styles.getSampleStyleSheet() - report = StringIO() # in-memory document, no disk file + report = io.BytesIO() # in-memory document, no disk file objects = [ Paragraph( SU( diff --git a/app/scodoc/sco_trombino_tours.py b/app/scodoc/sco_trombino_tours.py index 3e1073ae41..7a7be41f7f 100644 --- a/app/scodoc/sco_trombino_tours.py +++ b/app/scodoc/sco_trombino_tours.py @@ -30,7 +30,7 @@ Modification Jérome Billoue,Vincent Grimaud, IUT de Tours, 2017 """ -from io import StringIO +import io from reportlab.lib import colors from reportlab.lib import pagesizes @@ -265,7 +265,7 @@ def pdf_trombino_tours( # Réduit sur une page objects = [KeepInFrame(0, 0, objects, mode="shrink")] # Build document - report = StringIO() # in-memory document, no disk file + report = io.BytesIO() # in-memory document, no disk file filename = "trombino-%s-%s.pdf" % (DeptName, groups_infos.groups_filename) document = BaseDocTemplate(report) document.addPageTemplates( @@ -456,7 +456,7 @@ def pdf_feuille_releve_absences( # Réduit sur une page objects = [KeepInFrame(0, 0, objects, mode="shrink")] # Build document - report = StringIO() # in-memory document, no disk file + report = io.BytesIO() # in-memory document, no disk file filename = "absences-%s-%s.pdf" % (DeptName, groups_infos.groups_filename) if sco_preferences.get_preference(context, "feuille_releve_abs_taille") == "A3": taille = A3