--- a/reportlab/platypus/doctemplate.py Mon May 08 14:34:45 2006 +0000
+++ b/reportlab/platypus/doctemplate.py Mon May 08 15:04:15 2006 +0000
@@ -393,7 +393,7 @@
def handle_pageBegin(self):
'''Perform actions required at beginning of page.
shouldn't normally be called directly'''
- self.page = self.page + 1
+ self.page += 1
if self._debug: logger.debug("beginning page %d" % self.page)
self.pageTemplate.beforeDrawPage(self.canv,self)
self.pageTemplate.checkPageSize(self.canv,self)
@@ -415,7 +415,7 @@
'''
#detect infinite loops...
if self._curPageFlowableCount == 0:
- self._emptyPages = self._emptyPages + 1
+ self._emptyPages += 1
else:
self._emptyPages = 0
if self._emptyPages >= self._emptyPagesAllowed:
@@ -615,7 +615,7 @@
else:
#try to fit it then draw it
if self.frame.add(f, self.canv, trySplit=self.allowSplitting):
- self._curPageFlowableCount = self._curPageFlowableCount + 1
+ self._curPageFlowableCount += 1
self.afterFlowable(f)
else:
if self.allowSplitting:
@@ -627,7 +627,7 @@
if n:
if not isinstance(S[0],(PageBreak,SlowPageBreak,ActionFlowable)):
if self.frame.add(S[0], self.canv, trySplit=0):
- self._curPageFlowableCount = self._curPageFlowableCount + 1
+ self._curPageFlowableCount += 1
self.afterFlowable(S[0])
else:
ident = "Splitting error(n==%d) on page %d in\n%s" % (n,self.page,self._fIdent(f,30,self.frame))
@@ -706,7 +706,7 @@
exc = sys.exc_info()[1]
args = list(exc.args)
tr = first._traceInfo
- args[0] = args[0] + '\n(srcFile %s, line %d char %d to line %d char %d)' % (
+ args[0] += '\n(srcFile %s, line %d char %d to line %d char %d)' % (
tr.srcFile,
tr.startLineNo,
tr.startLinePos,
@@ -758,7 +758,7 @@
self._doSave = 0
passes = 0
while 1:
- passes = passes + 1
+ passes += 1
if self._onProgress:
self._onProgress('PASS', passes)
if verbose: print 'building pass '+str(passes) + '...',
--- a/reportlab/platypus/frames.py Mon May 08 14:34:45 2006 +0000
+++ b/reportlab/platypus/frames.py Mon May 08 15:04:15 2006 +0000
@@ -165,8 +165,6 @@
s = 0
if not self._atTop: s = flowable.getSpaceBefore()
flowable.canv = canv #some flowables might need this
-
- #print 'asked table to split. _aW = %0.2f, y-p-s=%0.2f' % (self._aW, y-p-s)
r = flowable.split(self._aW, y-p-s)
del flowable.canv
return r
--- a/reportlab/platypus/paragraph.py Mon May 08 14:34:45 2006 +0000
+++ b/reportlab/platypus/paragraph.py Mon May 08 15:04:15 2006 +0000
@@ -145,7 +145,7 @@
spacelen = tx._canvas.stringWidth(' ', tx._fontname, tx._fontsize)
xtraState.links.append( (xtraState.link_x, cur_x-spacelen, xtraState.link) )
xtraState.link = None
- cur_x = cur_x + txtlen
+ cur_x += txtlen
if xtraState.underline:
xtraState.underlines.append( (xtraState.underline_x, cur_x, xtraState.underlineColor) )
if xtraState.link:
@@ -224,7 +224,7 @@
for w in S[:-1]:
W.append((f,w))
- n = n + stringWidth(w, f.fontName, f.fontSize)
+ n += stringWidth(w, f.fontName, f.fontSize)
W.insert(0,n)
R.append(W)
W = []
@@ -232,7 +232,7 @@
w = S[-1]
W.append((f,w))
- n = n + stringWidth(w, f.fontName, f.fontSize)
+ n += stringWidth(w, f.fontName, f.fontSize)
if text[-1] in whitespace:
W.insert(0,n)
R.append(W)
@@ -268,7 +268,7 @@
i = len(f)-1
while hasattr(f[i],'cbDefn'): i = i-1
g = f[i]
- if g.text and g.text[-1]!=' ': g.text = g.text+' '
+ if g.text and g.text[-1]!=' ': g.text += ' '
return f
def _drawBullet(canvas, offset, cur_y, bulletText, style):
@@ -328,9 +328,9 @@
while 1:
#find a non whitespace character
while i<l:
- while start<lim and text[start]==' ': start=start+1
+ while start<lim and text[start]==' ': start += 1
if start==lim:
- i = i + 1
+ i += 1
if i==l: break
start = 0
f = frags[i]
@@ -350,7 +350,7 @@
j = find(text,' ',start)
if j<0: j==lim
w = stringWidth(text[start:j],f.fontName,f.fontSize)
- cLen = cLen + w
+ cLen += w
if cLen>maxW and line!=[]:
cLen = cLen-w
#this is the end of the line
@@ -364,7 +364,7 @@
g = (f,start,j)
line.append(g)
if j==lim:
- i=i+1
+ i += 1
def _do_under_line(i, t_off, tx):
y = tx.XtraState.cur_y - i*tx.XtraState.style.leading - tx.XtraState.f.fontSize/8.0 # 8.0 factor copied from para.py
@@ -548,7 +548,7 @@
1) unused width in points
2) word list
- B) When there is more than one input formatting fragment the out put is
+ B) When there is more than one input formatting fragment the output is
A fragment specifier with
kind = 1
lines= A list of fragments each having fields
@@ -601,7 +601,7 @@
lines.append((maxWidth - currentWidth, cLine))
cLine = [word]
currentWidth = wordWidth
- lineno = lineno + 1
+ lineno += 1
try:
maxWidth = maxWidths[lineno]
except IndexError:
@@ -639,7 +639,7 @@
newWidth = currentWidth
if newWidth<=maxWidth or n==0:
# fit one more on this line
- n = n + 1
+ n += 1
maxSize = max(maxSize,f.fontSize)
nText = w[1][1]
if words==[]:
@@ -651,16 +651,16 @@
if hasattr(g,'cbDefn'):
i = len(words)-1
while hasattr(words[i],'cbDefn'): i = i-1
- words[i].text = words[i].text + ' '
+ words[i].text += ' '
else:
- g.text = g.text + ' '
- nSp = nSp + 1
+ g.text += ' '
+ nSp += 1
g = f.clone()
words.append(g)
g.text = nText
else:
if nText!='' and nText[0]!=' ':
- g.text = g.text + ' ' + nText
+ g.text += ' ' + nText
for i in w[2:]:
g = i[0].clone()
@@ -676,7 +676,7 @@
words=words, fontSize=maxSize))
#start new line
- lineno = lineno + 1
+ lineno += 1
try:
maxWidth = maxWidths[lineno]
except IndexError:
@@ -708,8 +708,18 @@
"""Initially, the dumbest possible wrapping algorithm.
Cannot handle font variations."""
-
- if type(width) <> ListType: maxWidths = [width]
+ #for now we only handle one fragment. Need to generalize this quickly.
+ if len(self.frags) > 1:
+ raise ValueError('CJK Wordwrap can only handle one fragment per paragraph for now')
+ elif len(self.frags) == 0:
+ return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
+ textColor=style.textColor, lines=[])
+ f = self.frags[0]
+ if 1 and hasattr(self,'blPara') and getattr(self,'_splitpara',0):
+ #NB this is an utter hack that awaits the proper information
+ #preserving splitting algorithm
+ return f.clone(kind=0, lines=self.blPara.lines)
+ if type(width)!=ListType: maxWidths = [width]
else: maxWidths = width
lines = []
lineno = 0
@@ -723,12 +733,6 @@
self.height = 0
- #for now we only handle one fragment. Need to generalize this quickly.
- if len(self.frags) > 1:
- raise ValueError('CJK Wordwrap can only handle one fragment per paragraph for now')
- elif len(self.frags) == 0:
- return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
- textColor=style.textColor, lines=[])
f = self.frags[0]
@@ -958,12 +962,12 @@
l = 0
cum = 0
for W in _getFragWords(frags):
- cum = cum + W[0]
+ cum += W[0]
print "fragword%d: cum=%3d size=%d" % (l, cum, W[0]),
for w in W[1:]:
print "'%s'" % w[1],
print
- l = l + 1
+ l += 1
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
--- a/reportlab/test/runAll.py Mon May 08 14:34:45 2006 +0000
+++ b/reportlab/test/runAll.py Mon May 08 15:04:15 2006 +0000
@@ -38,7 +38,8 @@
from reportlab.lib.utils import isSourceDistro
haveSRC = isSourceDistro()
- def cleanup(folder,patterns=('*.pdf', '*.log','*.svg','runAll.txt', 'test_*.txt')):
+ def cleanup(folder,patterns=('*.pdf', '*.log','*.svg','runAll.txt', 'test_*.txt','_i_am_actually_a_*.*')):
+ if not folder: return
for pat in patterns:
for filename in GlobDirectoryWalker(folder, pattern=pat):
try:
@@ -51,16 +52,18 @@
# want this if reusing runAll anywhere else.
if string.find(folder, 'reportlab' + os.sep + 'test') > -1: cleanup(folder)
cleanup(outputfile(''))
-
NI = []
- testSuite = makeSuite(folder,nonImportable=NI,pattern=pattern+(not haveSRC and 'c' or ''))
- unittest.TextTestRunner().run(testSuite)
+ cleanOnly = '--clean' in sys.argv
+ if not cleanOnly:
+ testSuite = makeSuite(folder,nonImportable=NI,pattern=pattern+(not haveSRC and 'c' or ''))
+ unittest.TextTestRunner().run(testSuite)
if haveSRC: cleanup(folder,patterns=('*.pyc','*.pyo'))
- if NI:
- sys.stderr.write('\n###################### the following tests could not be imported\n')
- for f,tb in NI:
- print 'file: "%s"\n%s\n' % (f,string.join(tb,''))
- printLocation()
+ if not cleanOnly:
+ if NI:
+ sys.stderr.write('\n###################### the following tests could not be imported\n')
+ for f,tb in NI:
+ print 'file: "%s"\n%s\n' % (f,string.join(tb,''))
+ printLocation()
if __name__ == '__main__': #noruntests
main()
--- a/reportlab/test/test_pdfgen_general.py Mon May 08 14:34:45 2006 +0000
+++ b/reportlab/test/test_pdfgen_general.py Mon May 08 15:04:15 2006 +0000
@@ -713,13 +713,13 @@
if haveImages:
import shutil
c.drawString(1*inch, 10.25*inch, 'This jpeg is actually a gif')
- jpg = outputfile(os.path.basename(gif.replace('gif','jpg')))
+ jpg = outputfile('_i_am_actually_a_gif.jpg')
shutil.copyfile(gif,jpg)
c.drawImage(jpg, 1*inch, 9.25*inch, w, h, mask='auto')
tjpg = os.path.join(os.path.dirname(os.path.dirname(gif)),'docs','images','lj8100.jpg')
if os.path.isfile(tjpg):
c.drawString(4*inch, 10.25*inch, 'This gif is actually a jpeg')
- tgif = outputfile(os.path.basename(gif.replace('jpg','gif')))
+ tgif = outputfile(os.path.basename('_i_am_actually_a_jpeg.gif'))
shutil.copyfile(tjpg,tgif)
c.drawImage(tgif, 4*inch, 9.25*inch, w, h, mask='auto')
c.showPage()
--- a/reportlab/test/utils.py Mon May 08 14:34:45 2006 +0000
+++ b/reportlab/test/utils.py Mon May 08 15:04:15 2006 +0000
@@ -1,50 +1,54 @@
"""Utilities for testing Python packages.
"""
-
-
import sys, os, string, fnmatch, copy, re
from ConfigParser import ConfigParser
-
from reportlab.test import unittest
-
# Helper functions.
-
+def isWritable(D):
+ try:
+ fn = '00DELETE.ME'
+ f = open(fn, 'w')
+ f.write('test of writability - can be deleted')
+ f.close()
+ if os.path.isfile(fn):
+ os.remove(fn)
+ return 1
+ except:
+ return 0
_TEST_DIR_IS_WRITABLE = None #not known yet
+_OUTDIR = None
def canWriteTestOutputHere():
"""Is it a writable file system distro being invoked within
test directory? If so, can write test output here. If not,
it had better go in a temp directory. Only do this once per
process"""
- global _TEST_DIR_IS_WRITABLE
+ global _TEST_DIR_IS_WRITABLE, _OUTDIR
if _TEST_DIR_IS_WRITABLE is not None:
return _TEST_DIR_IS_WRITABLE
-
- from reportlab.lib.utils import isSourceDistro
- if isSourceDistro():
- curDir = os.getcwd()
- parentDir = os.path.dirname(curDir)
- if curDir.endswith('test') and parentDir.endswith('reportlab'):
- #we're probably being run within the test directory.
- #now check it's writeable.
- writable = False
- try:
- fn = '00DELETE.ME'
- open(fn, 'w').write('test of writability - can be deleted')
- if os.path.isfile(fn):
- writable = True
- os.remove(fn)
- except:
- pass
- if writable:
- _TEST_DIR_IS_WRITABLE = True
+ D = [d[9:] for d in sys.argv if d.startswith('--outdir=')]
+ if D:
+ _OUTDIR = D[-1]
+ try:
+ os.makedirs(_OUTDIR)
+ except:
+ pass
+ map(sys.argv.remove,D)
+ _TEST_DIR_IS_WRITABLE = isWritable(_OUTDIR)
+ else:
+ from reportlab.lib.utils import isSourceDistro
+ if isSourceDistro():
+ curDir = os.getcwd()
+ parentDir = os.path.dirname(curDir)
+ if curDir.endswith('test') and parentDir.endswith('reportlab'):
+ #we're probably being run within the test directory.
+ #now check it's writeable.
+ _TEST_DIR_IS_WRITABLE = isWritable(curDir)
+ _OUTDIR = curDir
return _TEST_DIR_IS_WRITABLE
-
-
-
def outputfile(fn):
"""This works out where to write test output. If running
@@ -53,17 +57,17 @@
normally be a file called 'test_foo.pdf', next door.
"""
if canWriteTestOutputHere():
- return fn
+ D = _OUTDIR
else:
from reportlab.lib.utils import isSourceDistro, get_rl_tempdir
D = get_rl_tempdir('reportlab_test')
- if fn: D = os.path.join(D,fn)
- return D
+ if fn: D = os.path.join(D,fn)
+ return D
def printLocation(depth=1):
if sys._getframe(depth).f_locals.get('__name__')=='__main__':
outDir = outputfile('')
- if outDir <> '':
+ if outDir!=_OUTDIR:
print 'Logs and output files written to folder "%s"' % outDir
def makeSuiteForClasses(*classes):
@@ -73,10 +77,8 @@
loader = unittest.TestLoader()
for C in classes:
suite.addTest(loader.loadTestsFromTestCase(C))
-
return suite
-
def getCVSEntries(folder, files=1, folders=0):
"""Returns a list of filenames as listed in the CVS/Entries file.
@@ -108,7 +110,6 @@
# Still experimental class extending ConfigParser's behaviour.
-
class ExtConfigParser(ConfigParser):
"A slightly extended version to return lists of strings."