Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

All power corrupts, but we need electricity.


devel / comp.lang.python / Re: Reportlab / platypus bug?

SubjectAuthor
* Reportlab / platypus bug?Les
`- Re: Reportlab / platypus bug?Les

1
Reportlab / platypus bug?

<mailman.293.1647207511.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17497&group=comp.lang.python#17497

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: nagy...@gmail.com (Les)
Newsgroups: comp.lang.python
Subject: Reportlab / platypus bug?
Date: Sun, 13 Mar 2022 21:55:36 +0100
Lines: 133
Message-ID: <mailman.293.1647207511.2329.python-list@python.org>
References: <CAKXe9UALi+jOEFfv9cS6QvRRvy8ssEoVDEx+y5u8OpHCNEMp9A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de m0IUMRt3rRPtOlxJ+LMndQuR9Upymo9GHAyk7thxA/wA==
Return-Path: <nagylzs@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=IpCSah6k;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'traceback':
0.04; '(e.g.': 0.05; '(most': 0.05; 'last):': 0.05; 'windows,':
0.05; 'world"': 0.05; '"hello': 0.07; 'explanation': 0.07;
'telling': 0.07; 'template': 0.07; 'amd64': 0.09; 'example.':
0.09; 'identical': 0.09; 'paragraph': 0.09; 'rendering': 0.09;
'subject:bug': 0.09; 'well:': 0.09; 'import': 0.15; '%s"': 0.16;
'72)': 0.16; 'doc': 0.16; 'docs.': 0.16; 'independent,': 0.16;
'laszlo': 0.16; 'once.': 0.16; 'problems:': 0.16; 'render': 0.16;
'reportlab': 0.16; 'skip:t 70': 0.16; 'solves': 0.16; 'title)':
0.16; 'url:doc': 0.16; 'python': 0.16; 'uses': 0.19; 'to:addr
:python-list': 0.20; 'maybe': 0.22; 'version': 0.23;
'environment': 0.29; 'error': 0.29; 'raise': 0.31;
'received:209.85.160': 0.31; 'empty': 0.32; 'happening': 0.32;
'white': 0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
'there': 0.33; 'skip:" 20': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'files': 0.36; 'thanks,': 0.36;
'change': 0.36; 'received:209.85': 0.37; 'hard': 0.37; 'file':
0.38; 'error,': 0.38; 'received:209': 0.39; 'two': 0.39; 'single':
0.39; 'explain': 0.40; 'url:page': 0.40; 'both': 0.40;
'something': 0.40; 'hello,': 0.40; 'try': 0.40; 'url-ip:216/8':
0.60; 'skip:b 30': 0.61; 'skip:h 10': 0.61; 'generation': 0.62;
'here': 0.62; 'skip:o 20': 0.63; 'copy': 0.63; 'skip:m 20': 0.63;
'skip:r 20': 0.64; 'skip:r 40': 0.64; 'skip:t 20': 0.66; 'skip:t
60': 0.70; 'interesting': 0.71; 'skip:f 20': 0.75; '&quot;': 0.76;
'happens': 0.84; '(that': 0.84; '0.2': 0.84; 'skip:" 90': 0.84;
'skip:& 100': 0.84; 'styles': 0.84; 'world&quot;': 0.84; 'inch':
0.91; 'somebody': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:from:date:message-id:subject:to;
bh=cOljqYz227GwQm6EkyEG1nLIa/eeS+IhchmckERM9K0=;
b=IpCSah6kw7MDajFLYbjnzzaTJFCInrhb3Tom7IjdwsrVeAaKc4AlXcwI1PpZH0zx1u
5BWnaMG9qcV/u9lB1ArPknnXd39/UoU9AFtPEfitIUasYwtwOjCd0NvxuVoe1AjBS3eV
L3oFTM4tHRD1MiAzu5V3963HS0oum3pvZshATW1T4sXIVHGryU3RTfnOUGXVOHvnNEUS
G/Xs8q+PnpZIR0REH7LWByHtT4tNBE0Xzc367LXZKj0SMPZlJeK/6negJH+CqDvFH2SD
LzSlKz5GCPIFyzcWJCODKvR0OZ9PmTr+u3gVgceH83NO0JNWBjK/d3UKNeYPO+e3z9Bc
Ihlw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
bh=cOljqYz227GwQm6EkyEG1nLIa/eeS+IhchmckERM9K0=;
b=RrNkGpyHNQMTsM0n/AuArDWkBaSRpeikJGroHmD30PjnefIxvePwEsg/a6ocklZ8+7
PnpiJvzDYciClwB/lLa3gxLh2OYmhw04qG8H+ekSpIHu7g4Kp32NUPKwQ+E2ukMEASxg
5FusF1624u7wqszo4bD1e7UY9mSd6AasdroEcyLUKn0aix7VCnvrce3vwtHNpIG+m3gp
xhi+jrV8zhd6Hn709IZ+7GJonKaTXln6PsjalL8okqNRJO4z5cpLWatW27xBtYylXlja
6E5DD0RP4Emk2ZrVVsDRGO63ApUmwj79CfBPyLt10vZqwMHl2aki9WJ8jcD+a5pUGtq2
ToIg==
X-Gm-Message-State: AOAM531/OFf+OLKOBCBuae3ut0qoE0SUqLIG+v32WvpSuV8OMHbv2ofy
dSarCvdVvsYyBu6s/BllcDBpRcA0OVcbLVJWEIrbbXOyGKfr9A==
X-Google-Smtp-Source: ABdhPJze6cA3OX4Ht6mFGOIfkb51rFfu8Q2URxq/o2XmJ/H+kYOr+jGBXtwCQdl+g69XDTb3yoGFfCIZEGQhBBmEzJA=
X-Received: by 2002:ac8:7ed2:0:b0:2e1:a509:54f0 with SMTP id
x18-20020ac87ed2000000b002e1a50954f0mr16247040qtj.130.1647204947143; Sun, 13
Mar 2022 13:55:47 -0700 (PDT)
X-Mailman-Approved-At: Sun, 13 Mar 2022 17:38:29 -0400
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAKXe9UALi+jOEFfv9cS6QvRRvy8ssEoVDEx+y5u8OpHCNEMp9A@mail.gmail.com>
 by: Les - Sun, 13 Mar 2022 20:55 UTC

Hello,

I have found an error, and I created a minimal working example. The minimal
working example starts with the very first example from Platypus user guide:

from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import inch

PAGE_HEIGHT = A4[1]
PAGE_WIDTH = A4[0]
styles = getSampleStyleSheet()

Title = "Hello world"
pageinfo = "platypus example"

def myFirstPage(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Bold', 16)
canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 108, Title)
canvas.setFont('Times-Roman', 9)
canvas.drawString(inch, 0.75 * inch, "First Page / %s" % pageinfo)
canvas.restoreState()

def myLaterPages(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Roman', 9)
canvas.drawString(inch, 0.75 * inch, "Page %d %s" % (doc.page, pageinfo))
canvas.restoreState()

def go():
Story = [Spacer(1, 2 * inch)]
style = styles["Normal"]
for i in range(100):
bogustext = ("This is Paragraph number %s. " % i) * 20
p = Paragraph(bogustext, style)
Story.append(p)
Story.append(Spacer(1, 0.2 * inch))
doc = SimpleDocTemplate("phello.pdf")
doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)

go()

If I change it to this (e.g. generate two identical files):

doc = SimpleDocTemplate("phello.pdf")
doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
doc = SimpleDocTemplate("phello2.pdf")
doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)

then it builds phello.pdf correctly, but builds a totally empty phello2.pdf
(960 bytes, a single white empty page).

It is hard to explain as it is, but something even more interesting happens
if you try to make them totally independent, and create a copy of the story
as well:

import copy
doc = SimpleDocTemplate("phello.pdf")
doc.build(copy.copy(Story), onFirstPage=myFirstPage, onLaterPages=myLaterPages)
doc = SimpleDocTemplate("phello2.pdf")
doc.build(copy.copy(Story), onFirstPage=myFirstPage, onLaterPages=myLaterPages)

This will render phello.pdf correctly, and it will throw this error when
rendering phello2.pdf:

Traceback (most recent call last):
File "C:\Projects\test\test2.py", line 48, in <module>
go()
File "C:\Projects\test\test2.py", line 45, in go
doc.build(copy.copy(Story), onFirstPage=myFirstPage,
onLaterPages=myLaterPages)
File
"C:\Users\nagyl\.virtualenvs\test-NC9-O-tN\lib\site-packages\reportlab\platypus\doctemplate.py",
line 1314, in build
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
File "C:\Users\nagyl\.virtualenvs\
test-NC9-O-tN\lib\site-packages\reportlab\platypus\doctemplate.py", line
1079, in build
self.handle_flowable(flowables)
File "C:\Users\nagyl\.virtualenvs\
test-NC9-O-tN\lib\site-packages\reportlab\platypus\doctemplate.py", line
958, in handle_flowable
raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: Flowable <Paragraph at
0x148e102cb80 frame=normal>This is Paragraph number 6. This is Paragraph
number 6. This(439.27559055118115 x 72) too large on page 1 in frame
'normal'(439.27559055118115 x 685.8897637795277) of template 'First'

And finally, here is the "solution" that solves all problems:

def go():
def create_story():
Story = [Spacer(1, 2 * inch)]
style = styles["Normal"]
for i in range(100):
bogustext = ("This is Paragraph number %s. " % i) * 20
p = Paragraph(bogustext, style)
Story.append(p)
Story.append(Spacer(1, 0.2 * inch))
return Story

doc = SimpleDocTemplate("phello.pdf")
doc.build(create_story(), onFirstPage=myFirstPage,
onLaterPages=myLaterPages)
doc = SimpleDocTemplate("phello2.pdf")
doc.build(create_story(), onFirstPage=myFirstPage,
onLaterPages=myLaterPages)

This does not throw an error, and it renders both files correctly. But I do
not see why this last version works, and the previous one (that uses
copy.copy) does not.

I was looking for an explanation in the user guide. I was looking for a
note, telling me that a story can be used for document generation only
once. But there is no such thing in the docs. Or maybe I just did not find
it. Can somebody please explain what is happening here?

Environment details: Python 3.10.1 amd64 on Windows, reportlab 3.6.6

Thanks,

Laszlo

Re: Reportlab / platypus bug?

<mailman.297.1647244438.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17501&group=comp.lang.python#17501

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: nagy...@gmail.com (Les)
Newsgroups: comp.lang.python
Subject: Re: Reportlab / platypus bug?
Date: Mon, 14 Mar 2022 08:53:45 +0100
Lines: 3
Message-ID: <mailman.297.1647244438.2329.python-list@python.org>
References: <CAKXe9UALi+jOEFfv9cS6QvRRvy8ssEoVDEx+y5u8OpHCNEMp9A@mail.gmail.com>
<mailman.293.1647207511.2329.python-list@python.org>
<l46t2hpm30vr1sb7f9vq8gab9bg4qsrosd@4ax.com>
<CAKXe9UBf__Rf1mweRM01f2V7nK2ibSt9K4KOLMb5eYdxWphsdQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 6HjfQK3WSZ1KPN9f8Z85sQuYZ8ht5hGJJV/+X3YSbOzg==
Return-Path: <nagylzs@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=USTbJEGy;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.052
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'cc:addr:python-list':
0.09; 'subject:bug': 0.09; 'cc:no real name:2**0': 0.14;
'anywhere.': 0.16; 'received:209.85.222.176': 0.16; 'received
:mail-qk1-f176.google.com': 0.16; 'probably': 0.17; 'bug': 0.19;
'cc:addr:python.org': 0.20; 'cc:2**0': 0.25; 'right,': 0.32;
'message-id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm": 0.33;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'received:209.85': 0.37;
'received:209': 0.39; 'received:209.85.222': 0.39; 'point.': 0.62;
'documented': 0.76; 'consumed': 0.84; 'report,': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=YE9vbk+hRAMwM1mOCd6fLaepOJzpYafyArRLdjZhoFM=;
b=USTbJEGy0EtYuZIDNS4O0k0D4N5JeTB9iAM68koHfUboefgfWWgbfKrIm/dxOTxnhD
q4GDZFy7qV2AFId+kJJUSP5eScnYfgFjeWrMnzv5XWnlAlAM5vUteLvLL06qLpFZMLgM
VlTeltrCj8vUHfXFeSfHGAaX+RocRKwla9AjHLV/frreHARyzaTiSWkTyPO0o04kqrJv
xoj7Ri1pCXkhbfOZspvocPFaMpQnlap3VRgOOXdsorf//v2g87mqNONANlgFZUWYmiI6
+4AQYOxzu9GqdVuG1JpQ0EpefMMYvFuGZGnanafi/j8Q5wYvBpsNpqgKpfD+adWlGA4p
xQlQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=YE9vbk+hRAMwM1mOCd6fLaepOJzpYafyArRLdjZhoFM=;
b=ydObM5AXeCJ/y+soRfuISlBtWSeD31sZTj7eWSmvVDR+VQBKFfv2icByZtbYWiTR0t
/n3mZNVRWw6CVRNAWMFHvjDUzwMovjPLq7WC6VMWnd5rTuGb3CxNokarrKxzoB8DndsK
HbntoVLimZ2ezsdwszzVcP/aVMWzrtmvN/4L1Uc33Sp+uhRwUAsvMXTTsvXFOJD77T7T
08YjyOR4/8xVpCq6kaSFb29KZVUeWxB8T0YC9wv3uzndP8Vt6tvTlUil8zXSAgAw7gmm
U+W1fBVSh4FIlDwXA5B8n3hal7OT7QXrnk4574vELjKVykApeD23O+Qe/oklmMKNlKTM
l/Qg==
X-Gm-Message-State: AOAM530e151EAmkDn9fly34cqL3EN0pK4d3KH+IFvhA9R+w9oI5FIWya
noyg3eOUps8t7OdhK0MVSmOJju8fzaaxAieoBj4ND3dyLXc=
X-Google-Smtp-Source: ABdhPJwd8CIAE9NgBNjWbeIwCRSI5naD6T2JFKkcTa0tlvMNsMBxWNNofmYDpK8otOdyfzkRz1pSnoBIZpNiPFH7DNw=
X-Received: by 2002:ae9:e40a:0:b0:612:4e35:4c86 with SMTP id
q10-20020ae9e40a000000b006124e354c86mr13641717qkc.540.1647244436186; Mon, 14
Mar 2022 00:53:56 -0700 (PDT)
In-Reply-To: <l46t2hpm30vr1sb7f9vq8gab9bg4qsrosd@4ax.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAKXe9UBf__Rf1mweRM01f2V7nK2ibSt9K4KOLMb5eYdxWphsdQ@mail.gmail.com>
X-Mailman-Original-References: <CAKXe9UALi+jOEFfv9cS6QvRRvy8ssEoVDEx+y5u8OpHCNEMp9A@mail.gmail.com>
<mailman.293.1647207511.2329.python-list@python.org>
<l46t2hpm30vr1sb7f9vq8gab9bg4qsrosd@4ax.com>
 by: Les - Mon, 14 Mar 2022 07:53 UTC

Good point. I can confirm, that it works with copy.deepcopy. Probably you
are right, the story is somehow consumed by doc.build. But it is not
documented anywhere. I'm going to submit a bug report, thanks.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor