[reportlab-users] doctemplate.py: use of isinstance on NullActionFlowable instance

Hans Brand hans at marcans.nl
Tue Jan 20 20:26:10 EST 2009


Hello, this is my first use of this list. Please have a look at the
following problem.

I received the following error message:


> Traceback (most recent call last):

> File "/usr/local/www/Zope210/first/Extensions/StudentPDF_double.py", line 310, in StudentPDF_double

> content = str(MakeStudent(self, date, termname, term, klas, format, report_type))

> File "/usr/local/www/Zope210/first/Extensions/StudentPDF_double.py", line 223, in __init__

> pdf_student.build(lst, onFirstPage=self.myAllPages, onLaterPages=self.myAllPages)

> File "/usr/local/lib/python2.4/site-packages/reportlab/platypus/doctemplate.py", line 911, in build

> BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)

> File "/usr/local/lib/python2.4/site-packages/reportlab/platypus/doctemplate.py", line 740, in build

> self.handle_flowable(flowables)

> File "/usr/local/lib/python2.4/site-packages/reportlab/platypus/doctemplate.py", line 633, in handle_flowable

> f.apply(self)

> TypeError: apply() takes exactly 1 argument (2 given)

>


Looking up the location in doctemplate.py gives the following code:


> 628 self.handle_pageBreak(slow=1)

> 629 else:

> 630 self.handle_pageBreak()

> 631 self.afterFlowable(f)

> 632 elif isinstance(f,ActionFlowable):

> 633 -> f.apply(self)

> 634 self.afterFlowable(f)

> 635 else:

> 636 frame = self.frame

> 637 #try to fit it then draw it

> 638 if frame.add(f, self.canv, trySplit=self.allowSplitting):


Using the pdb debugger I get the following results:


> (Pdb) f

> <reportlab.platypus.doctemplate.NullActionFlowable instance at 0xeaac06c>

> (Pdb) isinstance(f,ActionFlowable)

> True

> (Pdb) isinstance(f,NullActionFlowable)

> True

> (Pdb)


This reveals that f is a NullActionFlowable but that it is (also)
recognised as being an ActionFlowable instance.

So when f is a NullActionFlowable then the code at line

> 632 elif isinstance(f,ActionFlowable):

will be true.

However, the NullActionFlowable.apply function:


> class NullActionFlowable(ActionFlowable):

> def apply(self):

> pass


differs from the ActionFlowable.apply function:


> class ActionFlowable(Flowable):

> '''This Flowable is never drawn, it can be used for data driven

> controls

> For example to change a page template (from one column to two,

> for example)

> use NextPageTemplate which creates an ActionFlowable.

> '''

> def __init__(self,action=()):

> #must call super init to ensure it has a width and height (of

> zero),

> #as in some cases the packer might get called on it...

> Flowable.__init__(self)

> if type(action) not in (ListType, TupleType):

> action = (action,)

> self.action = tuple(action)

>

> def apply(self,doc):


The python documentation states:

> *isinstance*( object, classinfo)

>

> Return true if the object argument is an instance of the classinfo

> argument, or of a (direct or indirect) subclass thereof.


My question is now whether the code


> 632 elif isinstance(f,ActionFlowable):


was not meant to include the NullActionFlowable
OR
that the apply function of the NullActionFlowable
needs to include the doc parameter.

Thanks in advance for your replies,
Hans Brand


More information about the reportlab-users mailing list