fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
authorrobin
Wed, 06 Jul 2016 14:34:24 +0100
changeset 4279 f69571262c74
parent 4278 5aa80e7cdba8
child 4280 7f3365bf11f2
fix fake KeepTogether setup in handle_keepWithNext; version--> 3.3.13
src/reportlab/__init__.py
src/reportlab/platypus/doctemplate.py
src/reportlab/platypus/flowables.py
--- a/src/reportlab/__init__.py	Wed Jun 08 10:24:06 2016 +0100
+++ b/src/reportlab/__init__.py	Wed Jul 06 14:34:24 2016 +0100
@@ -1,9 +1,9 @@
 #Copyright ReportLab Europe Ltd. 2000-2016
 #see license.txt for license details
 __doc__="""The Reportlab PDF generation library."""
-Version = "3.3.12"
+Version = "3.3.13"
 __version__=Version
-__date__='20160608'
+__date__='20160706'
 
 import sys, os
 
--- a/src/reportlab/platypus/doctemplate.py	Wed Jun 08 10:24:06 2016 +0100
+++ b/src/reportlab/platypus/doctemplate.py	Wed Jul 06 14:34:24 2016 +0100
@@ -29,6 +29,7 @@
 """
 
 from reportlab.platypus.flowables import *
+from reportlab.platypus.flowables import _ContainerSpace
 from reportlab.lib.units import inch
 from reportlab.platypus.paragraph import Paragraph
 from reportlab.platypus.frames import Frame
@@ -167,13 +168,14 @@
 
     def wrap(self, availWidth, availHeight):
         '''Should never be called.'''
-        raise NotImplementedError
+        raise NotImplementedError('%s.wrap should never be called' % self.__class__.__name__)
 
     def draw(self):
         '''Should never be called.'''
-        raise NotImplementedError
+        raise NotImplementedError('%s.draw should never be called' % self.__class__.__name__)
 
 class NextFrameFlowable(ActionFlowable):
+    locChanger = 1                  #we cause a frame or page change
     def __init__(self,ix,resume=0):
         ActionFlowable.__init__(self,('nextFrame',ix,resume))
 
@@ -214,10 +216,10 @@
 class FrameActionFlowable(Flowable):
     _fixedWidth = _fixedHeight = 1
     def __init__(self,*arg,**kw):
-        raise NotImplementedError('Abstract Class')
+        raise NotImplementedError('%s.__init__ should never be called for abstract Class'%self.__class__.__name__)
 
     def frameAction(self,frame):
-        raise NotImplementedError('Abstract Class')
+        raise NotImplementedError('%s.frameAction should never be called for abstract Class'%self.__class__.__name__)
 
 class Indenter(FrameActionFlowable):
     """Increases or decreases left and right margins of frame.
@@ -237,6 +239,7 @@
         frame._rightExtraIndent += self.right
 
 class NotAtTopPageBreak(FrameActionFlowable):
+    locChanger = 1                  #we cause a frame or page change
     def __init__(self,nextTemplate=None):
         self.nextTemplate = nextTemplate
 
@@ -245,6 +248,7 @@
             frame.add_generated_content(PageBreak(nextTemplate=self.nextTemplate))
 
 class NextPageTemplate(ActionFlowable):
+    locChanger = 1                  #we cause a frame or page change
     """When you get to the next page, use the template specified (change to two column, for example)  """
     def __init__(self,pt):
         ActionFlowable.__init__(self,('nextPageTemplate',pt))
@@ -391,6 +395,10 @@
     def onDrawStr(self,value,*args):
         return onDrawStr(value,self,encode_label(args))
 
+def _ktAllow(f):
+    '''return true if allowed in containers like KeepTogether'''
+    return not (isinstance(f,(_ContainerSpace,DocIf,DocWhile)) or getattr(f,'locChanger',False))
+
 class BaseDocTemplate:
     """
     First attempt at defining a document template class.
@@ -766,9 +774,9 @@
         "implements keepWithNext"
         i = 0
         n = len(flowables)
-        while i<n and flowables[i].getKeepWithNext(): i += 1
+        while i<n and flowables[i].getKeepWithNext() and _ktAllow(flowables[i]): i += 1
         if i:
-            if i<n and not getattr(flowables[i],'locChanger',None): i += 1
+            if i<n and _ktAllow(flowables[i]): i += 1
             K = KeepTogether(flowables[:i])
             mbe = getattr(self,'_multiBuildEdits',None)
             if mbe:
--- a/src/reportlab/platypus/flowables.py	Wed Jun 08 10:24:06 2016 +0100
+++ b/src/reportlab/platypus/flowables.py	Wed Jul 06 14:34:24 2016 +0100
@@ -36,13 +36,12 @@
 from reportlab.rl_config import _FUZZ, overlapAttachedSpace, ignoreContainerActions, listWrapOnFakeWidth
 import collections
 
-__all__=('TraceInfo','Flowable','XBox','Preformatted','Image','Spacer','PageBreak','SlowPageBreak',
-        'CondPageBreak','KeepTogether','Macro','CallerMacro','ParagraphAndImage',
-        'FailOnWrap','HRFlowable','PTOContainer','KeepInFrame','UseUpSpace',
-        'ListFlowable','ListItem','DDIndenter','LIIndenter',
-        'DocAssign', 'DocExec', 'DocAssert', 'DocPara', 'DocIf', 'DocWhile',
-        'PageBreakIfNotEmpty',
-        )
+__all__ = '''TraceInfo Flowable XBox Preformatted Image NullDraw Spacer UseUpSpace PageBreak SlowPageBreak
+            PageBreakIfNotEmpty CondPageBreak KeepTogether Macro CallerMacro ParagraphAndImage FailOnWrap
+            FailOnDraw HRFlowable PTOContainer KeepInFrame ImageAndFlowables AnchorFlowable FrameBG
+            FrameSplitter BulletDrawer DDIndenter LIIndenter ListItem ListFlowable TopPadder DocAssign
+            DocExec DocPara DocAssert DocIf DocWhile SetTopFlowables splitLines splitLine'''.split()
+
 class TraceInfo:
     "Holder for info about where an object originated"
     def __init__(self):
@@ -535,6 +534,7 @@
         return (availWidth,availHeight-1e-8)  #step back a point
 
 class PageBreak(UseUpSpace):
+    locChanger=1
     """Move on to the next page in the document.
        This works by consuming all remaining space in the frame!"""
     def __init__(self,nextTemplate=None):
@@ -547,6 +547,7 @@
     pass
 
 class CondPageBreak(Spacer):
+    locChanger=1
     """use up a frame if not enough vertical space effectively CondFrameBreak"""
     def __init__(self, height):
         self.height = height
@@ -659,7 +660,11 @@
 
     def wrap(self, aW, aH):
         dims = []
-        W,H = _listWrapOn(self._content,aW,self.canv,dims=dims)
+        try:
+            W,H = _listWrapOn(self._content,aW,self.canv,dims=dims)
+        except:
+            from reportlab.lib.utils import annotateException
+            annotateException('\nraised by class %s(%s)@0x%8.8x wrap\n' % (self.__class__.__name__,self.__class__.__module__,id(self)))
         self._H = H
         self._H0 = dims and dims[0][1] or 0
         self._wrapInfo = aW,aH