Re: Reportlab / platypus bug?

2022-03-14 Thread Les
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-14 Thread Loris Bennett
Marco Sulla  writes:

> On Fri, 11 Mar 2022 at 19:10, Michael Torrie  wrote:
>> Both Debian stable and Ubuntu LTS state they have a five year support
>> life cycle.
>
> Yes, but it seems that official security support in Debian ends after
> three years:
>
> "Debian LTS is not handled by the Debian security team, but by a
> separate group of volunteers and companies interested in making it a
> success"
> https://wiki.debian.org/LTS
>
> This is the only problem for me.

I am not sure how different the two situations are.  Ubuntu is
presumably relying on the Debian security team as well as other
volunteers and at least one company, namely Canonical.

The sysadmins I know who are interested in long-term stability and
avoiding unnecessary OS updates use Debian rather than Ubuntu, but
that's maybe just my bubble.

Cheers,

Loris

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Reportlab / platypus bug?

2022-03-14 Thread Schachner, Joseph
I realize this is Python code, but I doubt that the question is a Python 
question.  I have used Python +numpy, scipy, matplotlib for years.   I have not 
used reportlab and have no idea about the reported problem except that I will 
be very surprised if it turns out to be a Python language issue.   Is there 
possibly a better place to ask this question?


Teledyne Confidential; Commercially Sensitive Business Data

-Original Message-
From: Les  
Sent: Sunday, March 13, 2022 4:56 PM
To: [email protected]
Subject: Reportlab / platypus bug?

  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 
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 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, reportla

Re: Reportlab / platypus bug?

2022-03-14 Thread Les
Unfortunately, the reportlab-users mailing list is unavailable (I cannot
subscribe). There is paid support but since I already have a workaround, I
won't pay for this. I think this is a documentation error of the reportlab
package. (They do not mention that stories cannot be reused.)

I think we can say that my original problem is solved, because I have a
workaround that always works.

Schachner, Joseph  ezt írta (időpont: 2022.
márc. 14., H 19:09):

> I realize this is Python code, but I doubt that the question is a Python
> question.  I have used Python +numpy, scipy, matplotlib for years.   I have
> not used reportlab and have no idea about the reported problem except that
> I will be very surprised if it turns out to be a Python language issue.
>  Is there possibly a better place to ask this question?
>
>
> Teledyne Confidential; Commercially Sensitive Business Data
>
> -Original Message-
> From: Les 
> Sent: Sunday, March 13, 2022 4:56 PM
> To: [email protected]
> Subject: Reportlab / platypus bug?
>
>   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 
> 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  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_s

Re: Reportlab / platypus bug?

2022-03-14 Thread Dennis Lee Bieber
On Mon, 14 Mar 2022 19:17:31 +0100, Les  declaimed the
following:

>Unfortunately, the reportlab-users mailing list is unavailable (I cannot
>subscribe). There is paid support but since I already have a workaround, I
>won't pay for this. I think this is a documentation error of the reportlab
>package. (They do not mention that stories cannot be reused.)
>

https://github.com/eduardocereto/reportlab/blob/master/src/reportlab/platypus/doctemplate.py
"""
A document is built when a DocumentTemplate is fed a sequence of Flowables.
The action of the build consumes the flowables in order and places them
onto frames on pages as space allows.  When a frame runs out of space the
next frame of the page is used.  If no frame remains a new page is created.
A new page can also be created if a page break is forced.
"""

Well, the code does use the term "consumes"

And down near the bottom (line 980 or so; this is a section that does
multiple passes for special cases)
"""
# work with a copy of the story, since it is consumed
tempStory = story[:]
self.build(tempStory, **buildKwds)
#self.notify('debug',None)
"""



-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-14 Thread Marco Sulla
On Mon, 14 Mar 2022 at 18:33, Loris Bennett  wrote:
> I am not sure how different the two situations are.  Ubuntu is
> presumably relying on the Debian security team as well as other
> volunteers and at least one company, namely Canonical.

So do you think that Canonical contributes to the LTS security team of
Debian? It could be. In this perspective, there should be little
difference between Debian and Ubuntu. Debian 11 with XFCE is really
tempting...
-- 
https://mail.python.org/mailman/listinfo/python-list


Weird strace of #! python script

2022-03-14 Thread Dan Stromberg
Hi folks.

First off, I know, python2 is ancient history.  Porting to 3.x is on my
list of things to do (though I'm afraid it's not yet at the top of the
list), and the same thing happens with python3.

So anyway, I'm strace'ing a #!/usr/bin/python2 script.

I expected to see an exec of /usr/bin/python2, but I don't.  I just see an
exec of /tmp/t.

As follows:
tact@celery_worker:/app$ strace -f -s 1024 -o /tmp/t.strace /tmp/t
^Z
[1]+  Stopped strace -f -s 1024 -o /tmp/t.strace /tmp/t
tact@celery_worker:/app$ bg
[1]+ strace -f -s 1024 -o /tmp/t.strace /tmp/t &
tact@celery_worker:/app$ ps axf
  PID TTY  STAT   TIME COMMAND
 1163 pts/0Ss 0:00 bash
 1363 pts/0S  0:00  \_ strace -f -s 1024 -o /tmp/t.strace /tmp/t
 1366 pts/0S  0:00  |   \_ /usr/bin/python2 /tmp/t
 1367 pts/0R+ 0:00  \_ ps axf
tact@celery_worker:/app$ fg
bash: fg: job has terminated
[1]+  Donestrace -f -s 1024 -o /tmp/t.strace /tmp/t
tact@celery_worker:/app$ grep execve /tmp/t.strace
1366  execve("/tmp/t", ["/tmp/t"], 0x7ffd89f9c3b8 /* 49 vars */) = 0
tact@celery_worker:/app$

I've deleted some irrelevant processes from the 'ps axf'.

/tmp/t is actually just:
tact@celery_worker:/app$ cat /tmp/t
#!/usr/bin/python2

import time

time.sleep(10)


Was this some sort of security feature I never heard about?  I'm tracing a
very simple time.sleep(10) here, but the same thing is (not) happening in a
larger script that I need to track down a bug in.

Is there a way I can coax Linux and/or strace to show all the exec's, like
they used to?  Not having them makes me wonder what else is missing from
the strace report.

I'm on a Debian 11.2 system with strace 5.10 and Python 2.7.18.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird strace of #! python script

2022-03-14 Thread Chris Angelico
On Tue, 15 Mar 2022 at 08:28, Dan Stromberg  wrote:
>
> Hi folks.
>
> First off, I know, python2 is ancient history.  Porting to 3.x is on my
> list of things to do (though I'm afraid it's not yet at the top of the
> list), and the same thing happens with python3.
>
> So anyway, I'm strace'ing a #!/usr/bin/python2 script.
>
> I expected to see an exec of /usr/bin/python2, but I don't.  I just see an
> exec of /tmp/t.
>
> As follows:
> tact@celery_worker:/app$ strace -f -s 1024 -o /tmp/t.strace /tmp/t
> ^Z
> [1]+  Stopped strace -f -s 1024 -o /tmp/t.strace /tmp/t
> tact@celery_worker:/app$ bg
> [1]+ strace -f -s 1024 -o /tmp/t.strace /tmp/t &
> tact@celery_worker:/app$ ps axf
>   PID TTY  STAT   TIME COMMAND
>  1163 pts/0Ss 0:00 bash
>  1363 pts/0S  0:00  \_ strace -f -s 1024 -o /tmp/t.strace /tmp/t
>  1366 pts/0S  0:00  |   \_ /usr/bin/python2 /tmp/t
>  1367 pts/0R+ 0:00  \_ ps axf
> tact@celery_worker:/app$ fg
> bash: fg: job has terminated
> [1]+  Donestrace -f -s 1024 -o /tmp/t.strace /tmp/t
> tact@celery_worker:/app$ grep execve /tmp/t.strace
> 1366  execve("/tmp/t", ["/tmp/t"], 0x7ffd89f9c3b8 /* 49 vars */) = 0
> tact@celery_worker:/app$
>
> I've deleted some irrelevant processes from the 'ps axf'.
>
> /tmp/t is actually just:
> tact@celery_worker:/app$ cat /tmp/t
> #!/usr/bin/python2
>
> import time
>
> time.sleep(10)
>
>
> Was this some sort of security feature I never heard about?  I'm tracing a
> very simple time.sleep(10) here, but the same thing is (not) happening in a
> larger script that I need to track down a bug in.
>
> Is there a way I can coax Linux and/or strace to show all the exec's, like
> they used to?  Not having them makes me wonder what else is missing from
> the strace report.
>
> I'm on a Debian 11.2 system with strace 5.10 and Python 2.7.18.
>
> Thanks!

I'm not sure, but I suspect that strace is skipping the exec into the
process itself. When I try this myself, I can see the trace of the
sleep call itself (it's implemented on top of select()), so it does
seem to be doing the proper trace. My guess is that the shebang is
being handled inside the exec of /tmp/t itself, rather than being a
separate syscall.

In any case, it doesn't seem to be a Python thing; I can trigger the
same phenomenon with other interpreters.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird strace of #! python script

2022-03-14 Thread Barry



> On 14 Mar 2022, at 21:29, Dan Stromberg  wrote:
> 
> I expected to see an exec of /usr/bin/python2, but I don't.  I just see an
> exec of /tmp/t.

I understand that the kernel handles the #! Line itself, which is why you do 
not see it in strace.

Barry



-- 
https://mail.python.org/mailman/listinfo/python-list