[reportlab-users] bug - trying to preserve leading whitespace in textLines method
Dave Rogers
reportlab-users@reportlab.com
Thu, 31 Oct 2002 16:39:53 -0500
--------------D071BECC3669294B92DC55E2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
I'm new to this list, but I've been using report lab for 4-5 months.
I think I have found a bug.
Version: Release 1.15
File: pdfgen/textobject.py
Class: PDFTextObject
Method: textLines
The doc string says:
"""prints multi-line or newlined strings, moving down. One
comon use is to quote a multi-line block in your Python code;
since this may be indented, by default it trims whitespace
off each line and from the beginning; set trim=0 to preserve
whitespace."""
My problem is that it is trimming off leading whitespace even when I set trim to 0.
I changed the code to this:
def textLines(self, stuff, trim=1):
"""prints multi-line or newlined strings, moving down. One
comon use is to quote a multi-line block in your Python code;
since this may be indented, by default it trims whitespace
off each line and from the beginning; set trim=0 to preserve
whitespace."""
if type(stuff) == StringType:
if trim==1:
lines = string.split(string.strip(stuff), '\n')
else:
lines = string.split(stuff, '\n') # preserve leading white space dr 10-31-02
if trim==1:
lines = map(string.strip,lines)
....
Basically I don't call string.strip if trim is not 1 when you split on \n for the lines list.
Maybe I'm missing something here, but it seems like leading whitespace would be included in the preservation of whitespace for a trim of 0. I need the whitespace for some padding on the first row of ad hoc tables I create.
Regards,
--
Dave Rogers
DaveRogers@StockAlerts.com
http://StockAlerts.com
--------------D071BECC3669294B92DC55E2
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<p>I'm new to this list, but I've been using report lab for 4-5 months.
<p>I think I have found a bug.
<p>Version: Release 1.15
<br>File: pdfgen/textobject.py
<br>Class: PDFTextObject
<br>Method: textLines
<p>The doc string says:
<p> """prints multi-line or newlined
strings, moving down. One
<br> comon use is to quote a
multi-line block in your Python code;
<br> since this may be indented,
by default it trims whitespace
<br> off each line and from the
beginning; set trim=0 to preserve
<br> whitespace."""
<p>My problem is that it is trimming off leading whitespace even when I
set trim to 0.
<p>I changed the code to this:
<p><tt> def textLines(self, stuff, trim=1):</tt>
<br><tt> """prints multi-line
or newlined strings, moving down. One</tt>
<br><tt> comon use is to quote
a multi-line block in your Python code;</tt>
<br><tt> since this may be indented,
by default it trims whitespace</tt>
<br><tt> off each line and from
the beginning; set trim=0 to preserve</tt>
<br><tt> whitespace."""</tt>
<br><tt> if type(stuff) == StringType:</tt>
<br><tt>
if trim==1:</tt>
<br><tt>
lines = string.split(string.strip(stuff), '\n')</tt>
<br><tt>
else:</tt>
<br><tt>
lines = string.split(stuff, '\n') # preserve leading white space dr 10-31-02</tt>
<br><tt>
if trim==1:</tt>
<br><tt>
lines = map(string.strip,lines)</tt>
<br><tt>....</tt>
<p>Basically I don't call string.strip if trim is not 1 when you split
on \n for the lines list.
<p>Maybe I'm missing something here, but it seems like leading whitespace
would be included in the preservation of whitespace for a trim of 0.
I need the whitespace for some padding on the first row of ad hoc tables
I create.
<p>Regards,
<br>--
<br>Dave Rogers
<br>DaveRogers@StockAlerts.com
<br><A HREF="http://StockAlerts.com">http://StockAlerts.com</A>
<br> </html>
--------------D071BECC3669294B92DC55E2--