
    Q?h                        S r SrSrSSK7  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	KJr  SS
KJrJrJr  SSKrSSKJr  SSKJrJrJrJrJr   \  SSKrSSK r \ RB                  " S5      r" " S S\#5      r$S r%S r& " S S\'5      r( " S S\)5      r* " S S\)5      r+ " S S\+5      r, " S S\+5      r- " S S\+5      r. " S  S!\-5      r/ " S" S\+5      r, " S# S$\-5      r0\0" S%5      r1\-" S&5      r2S' r3 " S( S)\)5      r4 " S* S+\45      r5 " S, S-\45      r6 " S. S/\+5      r7 " S0 S15      r8S2 r9 " S3 S4\:5      r; " S5 S65      r<S7 r= " S8 S95      r> " S: S;\>5      r?S< r@\AS=:X  a  SS>KBJCrCJDrD  S? rES@ rFSA rG\G" 5         gg! \ a
    SSKJr   GN9f = f)B)ActionFlowableBaseDocTemplateCurrentFrameFlowableFrameActionFlowable
FrameBreakIndenterIndexingFlowableLayoutErrorLCActionFlowableNextFrameFlowableNextPageTemplateNotAtTopPageBreakNullActionFlowablePageAccumulator	PageBeginPageTemplateSimpleDocTemplatez3.5.20a>  
This module contains the core structure of platypus.

rlatypus constructs documents.  Document styles are determined by DocumentTemplates.

Each DocumentTemplate contains one or more PageTemplates which defines the look of the
pages of the document.

Each PageTemplate has a procedure for drawing the "non-flowing" part of the page
(for example the header, footer, page number, fixed logo graphic, watermark, etcetera) and
a set of Frames which enclose the flowing part of the page (for example the paragraphs,
tables, or non-fixed diagrams of the text).

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.

The special invisible flowable NextPageTemplate can be used to specify
the page template for the next page (which by default is the one being used
for the current frame).
    )*)_ContainerSpace)inch)rl_safe_eval)	Paragraph)Frame)defaultPageSizeverbose	invariantN)canvas)isSeqencode_labeldecode_labelannotateExceptionstrTypes)Setzreportlab.platypusc                       \ rS rSrSrg)r	   E    N)__name__
__module____qualname____firstlineno____static_attributes__r&       P/var/www/html/env/lib/python3.13/site-packages/reportlab/platypus/doctemplate.pyr	   r	   E   s    r,   r	   c                    [        U SS 5      nUc  [        U SS 5      n[        U SS 5      nUc  [        U SS 5      n[        U S5      (       a  SU R                  5       -  nOSnUc  Ub  Uc  SnUc  SnS	U< S
U< SU< 3$ g)Nwidth_widthheight_height_culpritz, %s,  z???(z x ))getattrhasattrr3   )fwhcs       r-   _fSizeStringr=   H   s    aAy
!HT
"aAy
!Id
#q*qzz|#}9a9a !!A&&r,   c                     g)zDummy callback for onPageNr&   )r   docs     r-   
_doNothingr@   \   s    r,   c                   :    \ rS rSrS r\S 5       r\S 5       rSrg)PTCycle`   c                 V    [         R                  " U /UQ70 UD6nSUl        SUl        U$ Nr   )list__new___restart_idx)clsargskwdsselfs       r-   rG   PTCycle.__new__a   s-    ||C---	r,   c                     X R                      nU =R                   S-  sl         U R                   [        U 5      :  a  U R                  U l         U$ N   )rI   lenrH   )rM   vs     r-   
next_valuePTCycle.next_valueg   s:    O		Q	99c$iDIr,   c                     X R                      $ N)rI   rM   s    r-   peekPTCycle.peeko   s    IIr,   )rI   rH   N)	r'   r(   r)   r*   rG   propertyrT   rY   r+   r&   r,   r-   rB   rB   `   s/        r,   rB   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r   s   zAbstract interface definition for flowables which might
hold references to other pages or themselves be targets
of cross-references.  XRefStart, XRefDest, Table of Contents,
Indexes etc.c                     grP   r&   rX   s    r-   
isIndexingIndexingFlowable.isIndexingx       r,   c                     grP   r&   rX   s    r-   isSatisfiedIndexingFlowable.isSatisfied{   ra   r,   c                     g)zThis will be called by the framework wherever 'stuff' happens.
'kind' will be a value that can be used to decide whether to
pay attention or not.Nr&   )rM   kindstuffs      r-   notifyIndexingFlowable.notify~        	r,   c                     g)zECalled by multiBuild before it starts; use this to clear
old contentsNr&   rX   s    r-   beforeBuildIndexingFlowable.beforeBuild        	r,   c                     g)z.Called after build ends but before isSatisfiedNr&   rX   s    r-   
afterBuildIndexingFlowable.afterBuild       r,   r&   N)r'   r(   r)   r*   __doc__r_   rc   rh   rl   rp   r+   r&   r,   r-   r   r   s   s     
r,   r   c                   8    \ rS rSrSrS	S jrS rS rS
S jrSr	g)r      zThis 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.
c                 t    [         R                  U 5        [        U5      (       d  U4n[        U5      U l        g rW   )Flowable__init__r   tupleaction)rM   rz   s     r-   rx   ActionFlowable.__init__   s-     	$V}}YFFmr,   c           	      >   U R                   S   n[        U R                   SS 5      nSU-   nUS:X  a
  US   S:X  a    [        X5      " U6   g! [         a'  nUR                  S   U:X  a  [        SU-  5      ee SnAf  [        SU< S	[        U5      < 35         g= f)
z]
This is called by the doc.build processing to allow the instance to
implement its behaviour
r   rQ   Nhandle_handle_nextPageTemplatemainzCan't handle ActionFlowable(%s)z
handle_z args=)rz   ry   r7   AttributeErrorrK   NotImplementedErrorr!   ascii)rM   r?   rz   rK   arnaerrs         r-   applyActionFlowable.apply   s    
 QT[[_%))d1gvo	JCd# 	yy|S )*Kf*TUU	JVE$KHIs   A 
B"A99!Bc                     U $ rW   r&   rX   s    r-   __call__ActionFlowable.__call__   s    r,   Nc                 V    S[        U R                  5      < U R                  5       < 3$ )NzActionFlowable: )strrz   
_frameName)rM   maxLens     r-   identityActionFlowable.identity   s    ),T[[)9$//:KLLr,   )rz   )r&   rW   )
r'   r(   r)   r*   rs   rx   r   r   r   r+   r&   r,   r-   r   r      s    $J(Mr,   r   c                       \ rS rSrSrS rSrg)r      z#an ActionFlowable that does nothingc                     g rW   r&   rM   r?   s     r-   r   NullActionFlowable.apply       r,   r&   N)r'   r(   r)   r*   rs   r   r+   r&   r,   r-   r   r      s
    -r,   r   c                   $    \ rS rSrSrS rS rSrg)r
      rQ   c                 F    [        SU R                  R                  -  5      e)Should never be called.z%s.wrap should never be calledr   	__class__r'   )rM   
availWidthavailHeights      r-   wrapLCActionFlowable.wrap       !"BT^^E\E\"\]]r,   c                 F    [        SU R                  R                  -  5      e)r   z%s.draw should never be calledr   rX   s    r-   drawLCActionFlowable.draw   r   r,   r&   N)r'   r(   r)   r*   
locChangerr   r   r+   r&   r,   r-   r
   r
      s    J^^r,   r
   c                   "    \ rS rSrSrSS jrSrg)r      rQ   c                 4    [         R                  U SX45        g )N	nextFramer   rx   rM   ixresumes      r-   rx   NextFrameFlowable.__init__   s    k"%<=r,   r&   Nr   r'   r(   r)   r*   r   rx   r+   r&   r,   r-   r   r      s    J>r,   r   c                       \ rS rSrSS jrSrg)r      c                 4    [         R                  U SX45        g )NcurrentFramer   r   s      r-   rx   CurrentFrameFlowable.__init__   s    nR%?@r,   r&   Nr   )r'   r(   r)   r*   rx   r+   r&   r,   r-   r   r      s    Ar,   r   c                       \ rS rSrS rSrg)r      c                     g rW   r&   r   s     r-   r   r      r   r,   r&   N)r'   r(   r)   r*   r   r+   r&   r,   r-   r   r      s    r,   c                   (    \ rS rSrSrSS jrS rSrg)_FrameBreak   zq
A special ActionFlowable that allows setting doc._nextFrameIndex

eg story.append(FrameBreak('mySpecialFrame'))
Nc                 P    U R                  U R                  U4-   5      nXl        U$ rW   )r   rz   _ix)rM   r   r   rs       r-   r   _FrameBreak.__call__   s%    NN4;;y01r,   c                     [        U SS 5      (       a  UR                  U R                  5        [        R	                  X5        g )Nr   )r7   handle_nextFramer   r   r   r   s     r-   r   _FrameBreak.apply   s1    4d##  *T&r,   r&   rE   )r'   r(   r)   r*   rs   r   r   r+   r&   r,   r-   r   r      s    

'r,   r   frameEnd	pageBeginc                 v    [        U [        5      (       a#  SSKJn  U" U 5      n [	        U 5      (       a  U S   n U $ )Nr   )_numrQ   )
isinstancer   reportlab.platypus.paraparserr   r   )nr   s     r-   _evalMeasurementr      s1    !C6G881QHr,   c                   (    \ rS rSrS=rrS rS rSrg)r      rQ   c                 F    [        SU R                  R                  -  5      e)Nz5%s.__init__ should never be called for abstract Classr   )rM   argkws      r-   rx   FrameActionFlowable.__init__   s     !"YZ^ZhZhZqZq"qrrr,   c                 F    [        SU R                  R                  -  5      e)Nz8%s.frameAction should never be called for abstract Classr   rM   frames     r-   frameActionFrameActionFlowable.frameAction   s     !"\]a]k]k]t]t"tuur,   r&   N)	r'   r(   r)   r*   _fixedWidth_fixedHeightrx   r   r+   r&   r,   r-   r   r      s    !""K,svr,   r   c                   4    \ rS rSrSrSrSrSrS	S jrS r	Sr
g)
r      zIncreases or decreases left and right margins of frame.

This allows one to have a 'context-sensitive' indentation
and makes nested lists way easier.
Tr   c                 D    [        U5      U l        [        U5      U l        g rW   )r   leftright)rM   r   r   s      r-   rx   Indenter.__init__   s    $T*	%e,
r,   c                     U=R                   U R                  -  sl         U=R                  U R                  -  sl        g rW   )_leftExtraIndentr   _rightExtraIndentr   r   s     r-   r   Indenter.frameAction   s,    $))+4::-r,   )r   r   N)r   r   )r'   r(   r)   r*   rs   	_ZEROSIZEr/   r1   rx   r   r+   r&   r,   r-   r   r      s"    
 I
EF-.r,   r   c                   (    \ rS rSrSrSS jrS rSrg)r   i  rQ   Nc                     Xl         g rW   nextTemplate)rM   r   s     r-   rx   NotAtTopPageBreak.__init__  s    (r,   c                 l    UR                   (       d#  UR                  [        U R                  S95        g g )Nr   )_atTopadd_generated_content	PageBreakr   r   s     r-   r   NotAtTopPageBreak.frameAction	  s'    ||''	t?P?P(QR r,   r   rW   )r'   r(   r)   r*   r   rx   r   r+   r&   r,   r-   r   r     s    J)Sr,   r   c                        \ rS rSrSr S rSrg)r   i  rQ   c                 4    [         R                  U SU45        g )NnextPageTemplater   )rM   pts     r-   rx   NextPageTemplate.__init__  s    &8%<=r,   r&   Nr   r&   r,   r-   r   r     s    Ji>r,   r   c            
       H    \ rS rSrSrS/ \\SSSSSS4
S jrS rS rS r	Sr
g)	r   i  z
essentially a list of Frames and an onPage routine to call at the start
of a page when this is selected. onPageEnd gets called at the end.
derived classes can also implement beforeDrawPage and afterDrawPage if they want
Nc                 ,   U=(       d    / n[        U5      (       d  U/nU Vs/ s H  n[        U[        5      (       a  M  UPM     sn/ :X  d   S5       eXl        X l        X0l        X@l        XPl        X`l        Xpl	        Xl
        Xl        Xl        g s  snf )Nzframes argument error)r   r   r   idframesonPage	onPageEndpagesizeautoNextPageTemplatecropBoxartBoxtrimBoxbleedBox)rM   r   r   r   r   r   r   r   r   r   r   xs               r-   rx   PageTemplate.__init__  s     2V}}xf!=6aAe)<6=rAZCZZA" $8!  >s   B Bc                     g)zOverride this if you want additional functionality or prefer
a class based page routine.  Called before any flowables for
this page are processed.Nr&   rM   canvr?   s      r-   beforeDrawPagePageTemplate.beforeDrawPage.  rj   r,   c                 8   SnSnSnUR                   (       a#  [        [        [        UR                   5      5      nU R                  (       a#  [        [        [        U R                  5      5      nUR                  (       a#  [        [        [        UR                  5      5      nX5:w  aC  U(       a  UR                  U R                  5        O X4:w  a  UR                  UR                  5        S H*  n[        XS-   S5      nU(       d  M  UR                  XvS9  M,     g)zThis gets called by the template framework
If canv size != template size then the canv size is set to
the template size or if that's not available to the
doc size.
N)croparttrimbleedBox)name)	_pagesizerF   mapintr   setPageSizer7   
setCropBox)rM   r  r?   cpdpspboxsizes           r-   checkPageSizePageTemplate.checkPageSize4  s     >>Sdnn%= >2==tCT]]$;<"<<d3sCLL#9:6  /  ..C4E	$/Dt. /r,   c                     g)zThis is called after the last flowable for the page has
been processed.  You might use this if the page header or
footer needed knowledge of what flowables were drawn on
this page.Nr&   r   s      r-   afterDrawPagePageTemplate.afterDrawPageM      
 	r,   )
r   r   r   r   r   r   r   r   r   r   )r'   r(   r)   r*   rs   r@   rx   r  r  r  r+   r&   r,   r-   r   r     s7    
 RzZT!*/2r,   r   c                 :    [        USS 5      nU(       a  X SS& U?g g )N_generated_contentr   )r7   r  )	flowablesr   Ss      r-   _addGeneratedContentr  T  s(    *40A!A$ 	r,   c                   $    \ rS rSrSS jrS rSrg)	onDrawStriZ  Nc                 T    [         R                  X5      nX%l        XEl        X5l        U$ rW   )r   rG   onDrawrf   label)rJ   valuer#  r$  rf   rM   s         r-   rG   onDrawStr.__new__[  s$    {{3%	
r,   c                 \    [        U 5      U R                  U R                  U R                  4$ rW   )r   r#  r$  rf   rX   s    r-   __getnewargs__onDrawStr.__getnewargs__b  s!    4yTZZ		99r,   )rf   r$  r#  rW   )r'   r(   r)   r*   rG   r(  r+   r&   r,   r-   r!  r!  Z  s    :r,   r!  c                   \    \ rS rSrSrSrSS jrS rS rS r	S	 r
S
 rS rS rS rS rSrg)r   ie  zfgadget to accumulate information in a page
and then allow it to be interrogated at the end
of the pager   Nc                     UcU  U R                   R                  [        U R                   R                  5      -   nU R                   =R                  S-  sl        Xl        / U l        g rP   )r   r'   r   _countr
  data)rM   r
  s     r-   rx   PageAccumulator.__init__j  sK    <>>**3t~~/D/D+EEDNN!!Q&!		r,   c                 "    / U R                   S S & g rW   )r-  rX   s    r-   resetPageAccumulator.resetq  s    		!r,   c                 :    U R                   R                  U5        g rW   )r-  appendrM   rK   s     r-   addPageAccumulator.addt  s    		r,   c                 >    SU R                   < S[        U5      < S3$ )Nz<onDraw name="z	" label="z" />)r
  r   r4  s     r-   
onDrawTextPageAccumulator.onDrawTextw  s    48IIl4>PQQr,   c                 4    U R                   " [        U5      6   g rW   )r5  r    )rM   r  rf   r$  s       r-   r   PageAccumulator.__call__z  s    ,u%&r,   c                    ^  UR                   (       a  UR                   4U 4S jjnOU 4S jnX!l         UR                  (       a  UR                  4U 4S jjnOU 4S jnX1l        g )Nc                 8   > TR                  X5        U" X5        g rW   r   r  r?   ooprM   s      r-   r   4PageAccumulator.attachToPageTemplate.<locals>.onPage  s    D%Dr,   c                 (   > TR                  X5        g rW   r>  r  r?   rM   s     r-   r   rA    s    D%r,   c                 8   > TR                  X5        U" X5        g rW   r   r?  s      r-   r   7PageAccumulator.attachToPageTemplate.<locals>.onPageEnd  s    t(Dr,   c                 (   > TR                  X5        g rW   rE  rC  s     r-   r   rF    s    t(r,   )r   r   )rM   r   r   r   s   `   r-   attachToPageTemplate$PageAccumulator.attachToPageTemplate}  sG    99$&II  &	<<')||  ) r,   c                 P    [        XR                  U 5        U R                  5         g)z,this will be called at the start of the pageN)setattrr
  r0  r   s      r-   r   PageAccumulator.onPage  s    YYt$

r,   c                     U R                  X5         [        XR                  5        U R                  5         g!    N= f)z(this will be called at the end of a pageN)pageEndActiondelattrr
  r0  r   s      r-   r   PageAccumulator.onPageEnd  s6    4$	D# 	

	s   9 =c                     g)z0this should be overridden to do something usefulNr&   r   s      r-   rN  PageAccumulator.pageEndAction  rr   r,   c                 ,    [        X[        U5      5      $ rW   )r!  r   )rM   r%  rK   s      r-   r!  PageAccumulator.onDrawStr  s    L$677r,   )r-  r
  rW   )r'   r(   r)   r*   rs   r,  rx   r0  r5  r8  r   rH  r   r   rN  r!  r+   r&   r,   r-   r   r   e  sA     FR'!$
8r,   r   c                 j    [        U [        [        [        45      =(       d    [	        U SS5      (       + $ )z6return true if allowed in containers like KeepTogetherr   F)r   r   DocIfDocWhiler7   )r9   s    r-   _ktAllowrX    s(    1oeH=>_'!LY^B_``r,   c                     ^  \ rS rSrSr0 S\_S/ _SS_S\_S\_S	\_S
\_SS_SS_SS_SS_SS_SS_S/ _SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S_S#S_S$S_S%\_S&S_S'S_ESSSSSSSSSSSS(.ErS)r	Sr
S* rS+ rS, rS- rS. rS/ rS0 rS1 rS2 rS3 rS4 rSWS5 jrSXS6 jrSYS7 jrS8 rS9 rS: rSYS; jrSYS< jrS= rS> rSZS? jr S@ r!\r"\r#\r$\r%\r&\!r'\r(\r)\r*S\+RX                  4SA jr-S\+RX                  4SB jr.SC r/S\+RX                  4SD jr0SE r1SF r2SG r3 S[SH jr4SI r5SJ r6SK r7SL r8SM r9SN r:SOr;SP r<SQ r=SR r>SS r?ST r@U 4SU jrASVrBU =rC$ )\r   i  a:	  
First attempt at defining a document template class.

The basic idea is simple.

1)  The document has a list of data associated with it
    this data should derive from flowables. We'll have
    special classes like PageBreak, FrameBreak to do things
    like forcing a page end etc.

2)  The document has one or more page templates.

3)  Each page template has one or more frames.

4)  The document class provides base methods for handling the
    story events and some reasonable methods for getting the
    story flowables into the frames.

5)  The document instances can override the base handler routines.

Most of the methods for this class are not called directly by the user,
but in some advanced usages they may need to be overridden via subclassing.

EXCEPTION: doctemplate.build(...) must be called for most reasonable uses
since it builds a document using the page template.

Each document template builds exactly one document into a file specified
by the filename argument on initialization.

Possible keyword arguments for the initialization:

- pageTemplates: A list of templates.  Must be nonempty.  Names
  assigned to the templates are used for referring to them so no two used
  templates should have the same name.  For example you might want one template
  for a title page, one for a section first page, one for a first page of
  a chapter and two more for the interior of a chapter on odd and even pages.
  If this argument is omitted then at least one pageTemplate should be provided
  using the addPageTemplates method before the document is built.
- pageSize: a 2-tuple or a size constant from reportlab/lib/pagesizes.pu.
  Used by the SimpleDocTemplate subclass which does NOT accept a list of
  pageTemplates but makes one for you; ignored when using pageTemplates.

- showBoundary: if set draw a box around the frame boundaries.
- leftMargin:
- rightMargin:
- topMargin:
- bottomMargin:  Margin sizes in points (default 1 inch).  These margins may be
  overridden by the pageTemplates.  They are primarily of interest for the
  SimpleDocumentTemplate subclass.

- allowSplitting:  If set flowables (eg, paragraphs) may be split across frames or pages
  (default: 1)
- title: Internal title for document (does not automatically display on any page)
- author: Internal author for document (does not automatically display on any page)
r   pageTemplatesshowBoundaryr   
leftMarginrightMargin	topMarginbottomMarginallowSplittingrQ   titleNauthorsubjectcreatorproducerkeywordsr   pageCompression_pageBreakQuickrotation_debugencrypt	cropMarksenforceColorSpacedisplayDocTitlelanginitialFontNameinitialFontSizeinitialLeadingr   r   r   r   keepTogetherClasshideToolbarhideMenubar)hideWindowUI	fitWindowcenterWindownonFullScreenPageMode	directionviewAreaviewClip	printArea	printClipprintScalingduplexr&   c                 >   Xl         [        U S9U l        0 U l        U R                  R                  5        HE  nX2;  a  U R                  U   nO!X0R                  ;   a  [        SU-  5      eX#   n[        XU5        MG     U R                  n/ U l	        U R                  U5        0 U l        / U l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        / U l        / U l        / U l        U R1                  5         U R3                  5         g)z^create a document template bound to a filename (see class documentation for keyword arguments))r?   zInvalid argument %sNr   
   g        )filenamedict
_nameSpace
_lifetimes	_initArgskeys_invalidInitArgs
ValueErrorrK  rZ  addPageTemplates	_pageRefs_indexingFlowables_onPage_onProgress_flowableCount_curPageFlowableCount_emptyPages_emptyPagesAllowedr   r   _topFlowables_pageTopFlowables	_frameBGs_calc	afterInit)rM   r  r   krS   ps         r-   rx   BaseDocTemplate.__init__  s    4.$$&A{NN1%---$%:Q%>??ED1 ' a  "$  &'""$ !$!$!#

r,   c                     U R                   S   U R                  -
  U l        U R                   S   U R                  -
  U l        U R                  U R
                  -
  U l        U R                  U R                  -
  U l        g )Nr   rQ   )	r   r]  _rightMarginr^  
_topMarginr\  r/   r_  r1   rX   s    r-   r  BaseDocTemplate._calc?  sc     MM!,t/?/??--*T^^;&&8
oo(9(99r,   c                     Xl         g)z>Simple progress monitor - func(pageNo) called on each new pageN)r  rM   funcs     r-   setPageCallBackBaseDocTemplate.setPageCallBackE  s    r,   c                     Xl         g)z=Cleverer progress monitor - func(typ, value) called regularlyN)r  r  s     r-   setProgressCallBack#BaseDocTemplate.setProgressCallBackI  s    r,   c                     [        U R                  5      (       a8  U R                  U R                  5        [        U R                  5      (       a  M7  gg)z!handle internal postponed actionsN)rR   _hanginghandle_flowablerX   s    r-   clean_hangingBaseDocTemplate.clean_hangingM  s4    $--    / $--  r,   c                 r    [        U5      (       d  U/nU H  nU R                  R                  U5        M      g)z&add one or a sequence of pageTemplatesN)r   rZ  r3  )rM   rZ  ts      r-   r   BaseDocTemplate.addPageTemplatesR  s4    ]##*OM A%%a( r,   c                    [         /U l        [        U R                  [        5      (       a,  U R                  U R                  5        U R                  5         OU R                  U R                     U l        SU l	        U R                  5         g)z*implement actions at beginning of documentr   N)r   r  r   _firstPageTemplateIndexrF   r~   _setPageTemplaterZ  pageTemplatepagebeforeDocumentrX   s    r-   handle_documentBegin$BaseDocTemplate.handle_documentBegin[  sj    "d22488(()E)EF!!# $ 2 243O3O PD	r,   c                    U =R                   S-  sl         U R                  (       a"  [        R                  SU R                   -  5        U R                  R                  U R                  U 5        U R                  R                  U R                  U 5        U R                  R                  U R                  U 5        U R                  R                   H  oR                  5         M     U R                  5         SU l        [        U S5      (       a  U ?U R                  R                  S   U l        U R                  U R                  l        U R!                  U R"                  S9  g)zTPerform actions required at beginning of page.
shouldn't normally be called directlyrQ   zbeginning page %dr   _nextFrameIndex)pageTopFlowablesN)r  rj  loggerdebugr  r  r  r  r   r   _reset
beforePager  r8   r  r   handle_frameBeginr  )rM   r9   s     r-   handle_pageBegin BaseDocTemplate.handle_pageBeginf  s     			Q	;;%8499%DE((48''		$7  40""))A88:)%&"4)**$&&--a0
 KK

0F0FGr,   c                    [        U S5      (       a  U R                  R                  U l        g [        U S5      (       a!  U R                  U R
                     U l        U ?g U R                  R                  (       aD  U R                  U R                  R                  5        U R                  U R
                     U l        g g )N_nextPageTemplateCycle_nextPageTemplateIndex)r8   r  rT   r  rZ  r  r   r~   rX   s    r-   r   BaseDocTemplate._setPageTemplatex  s    4011 $ ; ; F FDT233 $ 2 243N3N OD+33(():):)O)OP $ 2 243N3N OD 4r,   c                    [        U5      (       a  [        U S/ 5      $ [        U[        5      (       aO  U[	        U S5      (       a%  U R
                  U R                     R                  :H  $ U R                  R                  :H  $ [        U[        5      (       aj  SUs=::  a  [        U R
                  5      :  aI  O  g [	        U S5      (       a  XR                  :H  $ XR
                  R                  U R                  5      :H  $ g g )Nr  r  r   )r   r7   r   r"   r8   rZ  r  r   r  r  rR   find)rM   npts     r-   _samePTBaseDocTemplate._samePT  s    ::4 8<<c(##QXY]^vQwQw4--d.I.IJMM  S  S  ~B  ~O  ~O  ~R  ~R  S  Sc#1c#A#d.@.@*A#At4557777**//0A0ABBB $Br,   c                 H   U R                  S5        U R                  R                  U l        U R                  R                  U l        U R                  R                  U l        U R
                  S:X  a  U =R                  S-  sl        OSU l        U R                  U R                  :  a   SU R                  -  n[        U5      eU R                  (       a*  U R                  SU R                  R                  5       5        U R                  R                  U R                  U 5        U R                  R                  U R                  U 5        U R                  5         U R                   (       a"  ["        R%                  SU R&                  -  5        U R                  R)                  [+        U R                  SU R,                  5      5        U R                  R/                  5         U R1                  5         U R                  S:X  a   U R2                  R5                  [6        5        g)	zEshow the current page
check the next page template
hang a page begin
)r  r   r   rQ   zrMore than %d pages generated without content - halting layout.  Likely that a flowable is too large for any frame.PAGEzending page %dri  N)_removeVarsr   r   r   r  r  r  r  r	   r  r  getPageNumberr  r  r   	afterPagerj  r  r  r  setPageRotationr7   ri  showPager  r  r3  r   )rM   idents     r-   handle_pageEndBaseDocTemplate.handle_pageEnd  s   
 	)* $

 ; ;!%!=!=--%%*! Dt666 M  PT  Pg  Pg  g!%((   )@)@)BC++DIIt<''		48NN{{FLL)9DII)EFII%%gd.?.?
4==&YZII !!#"Y'r,   c                 
   U R                   (       a  U(       d  U R                  5         g[        U R                  5      n[        U R                  5      U:X  a,  U R	                  5         [        U R                  5      U:X  a  M+  gg)z+some might choose not to end all the framesN)rh  r  rR   r  handle_frameEnd)rM   slowr   s      r-   handle_pageBreak BaseDocTemplate.handle_pageBreak  sW    !DMM"Admm$a'$$& dmm$a'r,   c                    U R                   nUR                  (       aV  U R                   R                  =(       d    U R                  nU(       a&  U R                   R                  U R                  U5        U R
                  Ul        U R                  Ul        U R                  Ul        U(       a  U R                  R                  U5        U R                  (       a&  U R                  R                  U R                  5        gg)z&What to do at the beginning of a frameN)r   r   r[  drawBoundaryr  r   r   r  r  extendr  )rM   r   r  r9   boundarys        r-   r  !BaseDocTemplate.handle_frameBegin  s    JJ88zz..C$2C2CH

''		(;!22"44nnMM  !12MM  !3!34 r,   c                    U R                  S5        U R                  R                  U l        U R                  R                  U l        U R                  R                  U l        [        U S5      (       aW  U R                  R                  U R                     U l        U R                  U R                  l	        U ?U R                  U5        gU R                  n[        US5      (       d  X R                  R                  S   L a  U R                  5         SU l        gU R                  R                  U R                  R                  R                  U5      S-      U l        U R                  U R                  l	        U R                  5         g)zHandles the semantics of the end of a frame. This includes the selection of
the next frame or if this is the last frame then invoke pageEnd.
)r   r  	lastFrameNrQ   )r  r   r   r   r  r8   r  r   r  rj  r  r  index)rM   r   r9   s      r-   r  BaseDocTemplate.handle_frameEnd  s(    	$ $

 ; ;!%!=!=--4)****11$2F2FGDJ $DJJ$""6*

Aq%%.?.?.F.Fr.J)J##%!
!..55d6G6G6N6N6T6TUV6WZ[6[\
$(KK

!&&(r,   c                    [        U[        5      (       af  [        U S5      (       a  U ?U R                   H5  nUR
                  U:X  d  M  U R                  R                  U5      U l          g   [        SU-  5      e[        U[        5      (       a  [        U S5      (       a  U ?Xl        g[        U5      (       a  [        5       nU Hj  nSnUS:X  a  [        U5      Ul        M  U R                   H(  nUR
                  U:X  d  M  UR                  U5        SnM*     U(       a  M^  [        SU-  5      e   U(       d  [        S5      eUR                  [        U5      :  a  [        S	5      eX0l        g[        S
5      e)z<On endPage change to the page template with name or index ptr  Ncan't find template('%s')r   r   rQ   #Cannot find page template called %s No valid page templates in cycleInvalid cycle restart position/argument pt should be string or integer or list)r   r"   r8   r  rZ  r   r  r  r  r  r   rB   rR   rH   r3  	TypeErrorrM   r   r  r<   ptnfounds         r-   r~   'BaseDocTemplate.handle_nextPageTemplate  sL   b""t566D<W''442:262D2D2J2J12MD/ ( 8;<<3t566D<W*,'2YY 	A8!$QAJ++Atts{ ! , u$%JS%PQQ   !CDDCF" !ABB +,'MNNr,   c                    [        U[        5      (       a5  U R                   H  nUR                  U:X  d  M  Us  $    [	        SU-  5      e[        U[
        5      (       a  U R                  U     g [        U5      (       a  [        5       nU Hj  nSnUS:X  a  [        U5      Ul	        M  U R                   H(  nUR                  U:X  d  M  UR                  U5        SnM*     U(       a  M^  [	        SU-  5      e   U(       d  [	        S5      eUR                  [        U5      :  a  [	        S5      eUR                  $ [        S5      e)	Nr  r   r   rQ   r  r  r  r  )r   r"   rZ  r   r  r  r   rB   rR   rH   r3  rY   r  r  s         r-   _peekNextPageTemplate%BaseDocTemplate._peekNextPageTemplate  s   b""''442:H ( 8;<<3r"2YY 	A8!$QAJ++Atts{ ! , u$%JS%PQQ   !CDDCF" !ABB66MMNNr,   c                    [        U S5      (       a#  U R                  R                  U R                     $ U R                  n[        US5      (       d  XR                  R                  S   L a  [        U S5      (       a  U R
                  R                  nOx[        U S5      (       a  U R                  U R                     nOMU R                  R                  (       a&  U R                  U R                  R                  5      nOU R                  nUR                  S   $ U R                  R                  U R                  R                  R                  U5      S-      $ )z(intended to be used by extreme flowablesr  r  r  r  r  r   rQ   )r8   r  r   r  r   r  rY   rZ  r  r   r  r  )rM   r9   r  s      r-   _peekNextFrameBaseDocTemplate._peekNextFrame$  s   4)**$$++D,@,@AAJJ1[!!Q*;*;*B*B2*F%Ft455#::??677#11$2M2MN""77#99$:K:K:`:`a#00&&q))$$++D,=,=,D,D,J,J1,MPQ,QRRr,   c                    [        U[        5      (       a  U R                  R                   H?  nUR                  U:X  d  M  U R                  R                  R                  U5      U l          g   [        SU< SU R                  < SU R                  R                  < SU R                  R                   Vs/ s H  o3UR                  4PM     sn< 35      e[        U[        5      (       a  Xl        g[        S5      es  snf )z5On endFrame change to the frame with name or index fxNzcan't find frame('z') in r5   z) which has frames z'argument fx should be string or integer)
r   r"   r  r   r   r  r  r  r  r  )rM   fxr   r9   s       r-   r    BaseDocTemplate.handle_nextFrame7  s   b""&&--442:+/+<+<+C+C+I+I!+LD( . UWX\XiXijnj{j{j~j~  SW  Sd  Sd  Sk  Sk  @l  Sk  NO  DE  DH  DH  AI  Sk  @l  m  n  n3#% EFF	 @ls   7C?c                 H    U R                  X5        U R                  U5        g)z)change to the frame with name or index fxN)r   r  )rM   r  r   s      r-   handle_currentFrame#BaseDocTemplate.handle_currentFrameD  s    b(V$r,   c                    US   n[        US5      (       a  [        US5        g[        US5      (       a2  UR                  S:X  a"  SUl        UR	                  S[        5       5        g[        US5      (       aW  [        UR                  S5      (       a<  UR                  R                  S:X  a"  SUl        UR	                  S[        5       5        g[        US5      (       a2  UR                  S:X  a"  SUl        UR	                  S[        5       5        g[        US5      (       aY  [        UR                  S5      (       a=  UR                  R                  S:X  a"  SUl        UR	                  S[        5       5        gggg)zKpreprocessing step to allow pageBreakBefore and frameBreakBefore attributesr   _skipMeNextTimeNpageBreakBeforerQ   styleframeBreakBefore)	r8   rO  r  r  insertr   r  r  r   )rM   r  firsts      r-   handle_breakBefore"BaseDocTemplate.handle_breakBeforeI  sF   ! 5+,,E,- 5*++0E0E0J$%E!LLIK(5!!gekk;L&M&MRWR]R]RmRmqrRr$%E!Q	,5+,,1G1G11L$%E!Q
-5!!gekk;M&N&NSXS^S^SoSostSt$%E!Q
- Tu&N!r,   c                    Sn[        U5      nX#:  a^  X   R                  5       (       aG  [        X   5      (       a5  US-  o"U:  a+  X   R                  5       (       a  [        X   5      (       a  M5  U(       a  X#:  a  [        X   5      (       a  US-  nU R                  USU 5      n[	        U SS5      nU(       aa  UR
                  SS  HM  n[        US5      (       a  U" [        USUR                  45        OU" [        US45        SUR                  S'   MO     O%UR
                  SS  H  nSUR                  S'   M     USU2	 UR                  SU5        gg)zimplements keepWithNextr   rQ   N_multiBuildEditsr  keepWithNext)rR   getKeepWithNextrX  rs  r7   _contentr8   rK  r  rO  __dict__r   )rM   r  ir   Kmber9   s          r-   handle_keepWithNext#BaseDocTemplate.handle_keepWithNexte  s8   	Ncil2244),9O9OQRVWQWQRcil2244),9O9Osx	--qAvq&&y!}5A$1$7CCRAq00WQ~annEFWQ~6712AJJ~. ) CRA12AJJ~. )"1"Qq! r,   c                 r    U(       a  X1l          UR                  U5      U(       a  U? $ $ ! U(       a  U? f f = frW   )_framer   )rM   r9   r   r   s       r-   _fIdentBaseDocTemplate._fIdent{  s-    U(	#::f%!(uu!(us   * 6c           	         U R                  U5        US   nU(       a'  U R                  U5        U R                  U5        US   nUS	 Uc  g[        U[        5      (       a  UR
                  nU(       aC  U R                  U5      (       d-  [        U5      nUR                  U 5        U R                  U5        [        U[        5      (       a  U R                  SS9  OU R                  5         U R                  U5        g[        U[        5      (       a#  UR                  U 5        U R                  U5        gU R                  nU R                  nUR                  X%U R                   S9(       aG  [        U["        5      (       d&  U =R$                  S-  sl        U R                  U5        ['        X5        gU R                   (       a  UR)                  X%5      n[+        U5      nOSnU(       a  [        WS   [        [        [        [,        45      (       d  UR                  US   USS9(       dB  SXpR.                  U R1                  USU5      U R1                  US   SU5      4-  n[3        U5      eU =R$                  S-  sl        U R                  US   5        USS USS& ['        X5        gXaSS& g[5        US5      (       az  S	U R1                  USU5      [7        U5      U R.                  U R                  R8                  U R                  R;                  5       U R<                  R8                  4-  n[3        U5      eSUl        [A        U S
S5      n	U	(       a  U	" [B        US45        URE                  SU5        U RG                  5         g)z<try to handle one flowable from the front of list flowables.r   NrQ   )r  )trySplitz/Splitting error(n==%d) on page %d in
%s
S[0]=%s<   
_postponedz?Flowable %s%s too large on page %d in frame %r%s of template %rr  )$filterFlowablesr  r  r   r   r   r  r   r   afterFlowableSlowPageBreakr  r   r   r  r5  r`  r   r  r  splitrR   
DDIndenterr  r  r	   r8   r=   r   _aSpaceStringr  r  r7   rO  r   r  )
rM   r  r9   r  r   r  r  r   r  r  s
             r-   r  BaseDocTemplate.handle_flowable  s'   
 	Y'aL##I.$$Y/!AaL9a	""..C4<<,,$S)		$""3'!M**%%1%-%%'q!.))GGDMq!JJE99Dyy4+>+>y?!!$788..!3.&&q)$Y5&&A+AAAA%adImNS]+^__$yy1tay@$W[\]f]fgkgsgstuvxy~g  AE  AM  AM  NO  PQ  NR  SU  V[  A\  []  %]E"-e"4422a72**1Q40)*12	!A,Y=)*!Aq.. a!%a5!9,q/$))UYU_U_UbUb(,

(@(@(BDDUDUDXDX!Z!Z *%00#$AL!$'9$?CWQ|45$$Qq)((*r,   c                 r   [         R                  R                  R                  5       U l        U" U=(       d    U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  S9n[%        USS 5      " U R&                  5        U R(                  Ul        UR-                  U R.                  5        UR1                  U R2                  5        UR5                  U R6                  5        UR9                  U R:                  5        UR=                  U R>                  5        URA                  U RB                  5        SSK"J#nJ$n  URJ                  RM                  5        HI  u  pg[%        XS   RO                  5       USS -   S5      nUc  M-  XuL a  SS	/U   nURQ                  Xh5        MK     U RR                  (       a  URU                  U RR                  5        U$ )
zmake and return a sample canvas. As suggested by 
Chris Jerdonek cjerdonek @ bitbucket this allows testing of stringWidths
etc.

*NB* only the canvases created in self._startBuild will actually be used
in the build process.
)r   r   rg  rm  rp  rq  rr  r   r   r   r   ro  
setEncryptc                     g rW   r&   )r   s    r-   <lambda>-BaseDocTemplate._makeCanvas.<locals>.<lambda>  s    Dr,   r   )ViewerPreferencesPDFDictionarycheckPDFBooleanrQ   Nfalsetrue)+	reportlablib	sequencer	Sequencerseqr  r   r   rg  rm  rp  rq  rr  r   r   r   r   ro  r7   rk  rl  
_cropMarks	setAuthorrb  setTitlera  
setSubjectrc  
setCreatorrd  setProducerre  setKeywordsrf  reportlab.pdfbase.pdfdocr#  r$  validateitemslowersetViewerPreferencer  r  )	rM   r  canvasmakerr  VPDcPDFBr  vfrS   s	            r-   _makeCanvasBaseDocTemplate._makeCanvas  s    ==**44684t}}%)]]&*nn,0,@,@.2.D.D.2.B.B.2.B.B-1-@-@&*ll%)[[&*ll'+}}#'99 	\.1$,,?..t{{#djj!%%''	 LL&&(DAqTZZ\!AB%/5A}; (+A((- ) <<  .r,   c                 l    U R                  5         U R                  XS9U l        U R                  5         g )N)r  r8  )r  r<  r  r  )rM   r  r8  s      r-   _startBuildBaseDocTemplate._startBuild  s,    

$$h$O	!!#r,   c                    U R                  S5        U R                  / :w  a4  U R                  S   [        L a  U R                  S	 U R                  5         O U R                  5         U R	                  5         [        U SS5      (       a  U R                  R                  5         U R                  (       a  U R                  R                  S 5        g g )N)buildr  r   r  _doSaverQ   )
r  r  r   r  r  r7   r  saver  r  rX   s    r-   	_endBuildBaseDocTemplate._endBuild  s    12=="r!2i!?b!  !!#4	!$$diinn&6<<2248<r,   c           
      j   [        U5      nU R                  (       a-  U R                  SS5        U R                  S[        U5      5        U R                  X#5        U R                  nUR                  R
                  U l        Sn Xl        [        U5      (       Ga  U R                  (       a  U R                  S   [        L as  [        US   [        5      (       a[  US   R                  nU(       aB  U R                  U5      (       d,  [        U5      nUR                  U 5        U R!                  5         US	 U R#                  5          US   nU R%                  U5        US-  nU R                  (       a  U R                  SU[        U5      -
  5        [        U5      (       a  GM  U?U R                  UR                  l        U R?                  5         U R                  (       a  U R                  S	S5        g
g
!   ['        WS5      (       a  UR(                  (       a  [*        R,                  " 5       S   n	[/        U	R0                  5      n
UR(                  nU
S==   SUR2                  UR4                  UR6                  UR8                  UR:                  4-  -  ss'   [=        U
5      U	l        e = f! U?f = f)a  Build the document from a list of flowables.
If the filename argument is provided then that filename is used
rather than the one provided upon initialization.
If the canvasmaker argument is provided then it will be used
instead of the default.  For example a slideshow might use
an alternate canvas which places 6 slides on a page (by
doing translations, scalings and redefining the page break
operations).
STARTEDr   SIZE_ESTr  rQ   
_traceInfoz1
(srcFile %s, line %d char %d to line %d char %d)PROGRESSFINISHEDN) rR   r  r?  r  _docinfo
_savedInfo_doctemplater  r   r   PageBreakIfNotEmptyr   r  r   r   r  r  r  r8   rJ  sysexc_inforF   rK   srcFilestartLineNostartLinePos	endLineNo
endLinePosry   rE  )rM   r  r  r8  flowableCountr  handledr  r  excrK   trs               r-   rB  BaseDocTemplate.build  s+    IYq)ZY8. yy))..!	" $i..==T]]2%6)%C
S\]^S_`sHtHt#A,33C4<<#4#4,S1		$--/!!""$%aLE((3qLG  ##$$ZI0NO; i..> ! 		Z* 3ul338H8H!llnQ/#CHH~"--Q#WJJNNOOLLMM[ $  $); !s&   CJ. G6 "?J. 6B5J++J. .J2c                 d    SnU R                    H  nUR                  5       (       a  M  Sn  U$    U$ )z:Called by multi-build - are all cross-references resolved?rQ   r   )r  rc   )rM   allHappyr9   s      r-   _allSatisfiedBaseDocTemplate._allSatisfiedY  s6    ((A==??	 ) r,   c                     U R                    HA  n[        USU 5      n X@:X  a  U R                  Ul        UR	                  X5        X@:X  a  U?MA  MC     g! X@:X  a  U?f f = f)zForward to any listeners_canvN)r  r7   r  rc  rh   )rM   rf   rg   lrc  s        r-   rh   BaseDocTemplate.notifyb  sc    ((AAgd+E ;"iiAG%;  ) ; s   'A
Ac                 ~    [         (       a  [        SXR                  4-  5        U R                  U R                  U'   g)zhook to register a page numberz)pageRef called with label '%s' on page %dN)r   printr  r  )rM   r$  s     r-   pageRefBaseDocTemplate.pageRefn  s5    7EE99I   $		ur,   c                 h   / U l         U H5  nUR                  5       (       d  M  U R                   R                  U5        M7     SU l        Sn/ nUR                  U l         US-  nU R
                  (       a  U R                  SU5        [        (       a.  [        R                  R                  S[        U5      -   S-   5        U R                    H  nUR                  5         M     USS nU R                  " U40 UD6  U R                    H  nUR                  5         M     U R                  5       n	U	(       a"  SU l        U R                  R!                  5         OBXR:  a  [#        SU-  5      eU(       a%  UR%                  S5      n
U
S   " U
SS 6   U(       a  M%  GM:  U ?[        (       a  ['        S5        U$ )	zWMakes multiple passes until all indexing flowables
are happy.

Returns number of passesr   rQ   PASSzbuilding pass z...Nz*Index entries not resolved after %d passessaved)r  r_   r3  rC  r  r  r   rR  stdoutwriter   rl   rB  rp   r`  r  rD  
IndexErrorpoprg  )rM   story	maxPasses	buildKwdsthingpassesr  fl	tempStoryhappyes              r-   
multiBuildBaseDocTemplate.multiBuildt  s}    #%E!!''..u5 
  #

aKF  0w

(()9#f+)E)MN--  . aIJJy.I. -- . &&(E 		 ! !MPY!YZZ GGAJ!ae #7 > !7E'Nr,   c                     g)z6This is called after initialisation of the base class.Nr&   rX   s    r-   r  BaseDocTemplate.afterInit  rr   r,   c                     g)z=This is called before any processing is
done on the document.Nr&   rX   s    r-   r  BaseDocTemplate.beforeDocument  rn   r,   c                     g)zThis is called at the beginning of page
processing, and immediately before the
beforeDrawPage method of the current page
template.Nr&   rX   s    r-   r  BaseDocTemplate.beforePage  r  r,   c                     g)zrThis is called after page processing, and
immediately after the afterDrawPage method
of the current page template.Nr&   rX   s    r-   r  BaseDocTemplate.afterPage  rj   r,   c                     g)zcalled to filter flowables at the start of the main handle_flowable method.
Upon return if flowables[0] has been set to None it is discarded and the main
method returns.
Nr&   )rM   r  s     r-   r  BaseDocTemplate.filterFlowables  r  r,   c                     g)z)called after a flowable has been renderedNr&   )rM   flowables     r-   r  BaseDocTemplate.afterFlowable  rr   r,   )r  r   rB  foreverc                     [        U[        5      (       d  [        U5      nUR                  5       nUR                  5       nU R	                  UR                  5       < SUR                  5       < S3U5        g )Nz=(r6   )r   r"   r   stripdocExec)rM   varexprlifetimes       r-   	docAssignBaseDocTemplate.docAssign  sL    $x((s4y$ZZ\IIK		DJJL9(Cr,   c                    UR                  5       nU R                  n[        UR                  5       5      n X R                  ;  a  [        SU< SU R                  < 35      e[        R                  " UR                  5       0 U5        U R                  UR                  5        Vs/ s H  oUU;  d  M
  UPM     snU5        g !   U Vs/ s H  oUU;  d  M
  UPM     Os  snf nnU H  nX5	 M     [        SU< SU< S35         N{= fs  snf )Nzbad lifetime z not in z	
docExec z
 lifetime=z	 failed!
)
r  r  rF   r  _allowedLifetimesr  r   rl_safe_execr!   _addVars)rM   stmtr  NSK0r  K1s          r-   r  BaseDocTemplate.docExec  s    ZZ\??	?	V555 htG]G]!^__%%djjl2b9 	"'');)Q{q);HE	V/RB;!R/B/E d8TU;s*   AC &	D3DD	CC'Dc                     U R                   nU H\  nUR                  5        H  nXE;   d  M
  UR                  U5        M     UR                  U[	        / 5      5      R                  U5        M^     g)z*add namespace variables to lifetimes listsN)r  valuesremove
setdefaultsetr5  )rM   varsr  LTr  rS   s         r-   r  BaseDocTemplate._addVars  sT    ??CYY[8HHSM ! MM(3r7+//4	 r,   c                     U R                   nU R                  nU H!  nUR                  U/ 5       H  n X5	 M     X$	 M#     g! [         a     M  f = f)z9remove namespace variables for with lifetime in lifetimesN)r  r  r  KeyError)rM   	lifetimesr  r  r  r  s         r-   r  BaseDocTemplate._removeVars  sX    ????!H]]8B/ 0
  "   s   A
AAc                      [         R                   " UR                  5       0 U R                  5      $ !   [        SU-  5         g = f)Nz
docEval %s failed!
)r   r  r  r!   )rM   r  s     r-   docEvalBaseDocTemplate.docEval  s;    	?,,TZZ\"T__MM	?6=>s	   /2 Ac                    > [         (       a1  SU R                  R                   SU R                  R                   S3$ [        TU ]  5       $ )N<.z object at 0x?hidden?>)r   r   r(   r'   super__repr__)rM   r   s    r-   r  BaseDocTemplate.__repr__   sF    gpgpa112!DNN4K4K3LLbc -)+-r,   )!r  rC  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r   r  rO  r  r  r  r  r   r1   r  r  rZ  r+  r/   rW   )r   Nr   )NN)r  )Dr'   r(   r)   r*   rs   r   r   KeepTogetherr  r  r  rx   r  r  r  r  r  r  r  r  r  r  r  r  r  r~   r  r  r   r  r  r  r  r  _handle_documentBegin_handle_pageBegin_handle_pageEnd_handle_frameBegin_handle_frameEnd_handle_flowable_handle_nextPageTemplate_handle_currentFrame_handle_nextFramer   Canvasr<  r?  rE  rB  r`  rh   rh  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r+   __classcell__)r   s   @r-   r   r     s/   6n-J -#B-"1- !- "$	-
  - #4- %Q- D- T- d- d- t- r-  - &d-  &a!-" q#-$ Q%-& t'-(  )-* (+-, &t--. D/-0 &t1-2 &t3-4 %d5-6 t7-8 d9-: t;-< =-> (?-@ "4A-B "4C-D %)!%$(-1!% $ $!%!%$("Y-I\ ,\: 0
)	H$	PC!(F'5)0#OJO>S&G%
8",#G+T 1($O*&&6.(#'V]] .` $(V]] $

9 )-&-- @+D
 *  "4t
 9DF5
?- -r,   r   c                   F    \ rS rSrSrSrS r\\\R                  4S jr
Srg)r   i  a  A special case document template that will handle many simple documents.
See documentation for BaseDocTemplate.  No pageTemplates are required
for this special case.   A page templates are inferred from the
margin information and the onFirstPage, onLaterPages arguments to the build method.

A document which has all pages with the same look except for the first
page may can be built using this special approach.
)rZ  c                 F    U R                  5         U R                  S5        g)zSoverride base method to add a change of page template after the firstpage.
        LaterN)r  r  rX   s    r-   r  "SimpleDocTemplate.handle_pageBegin  s     	 %%g.r,   c           
         U R                  5         [        U R                  U R                  U R                  U R
                  SS9nU R                  [        SXRU R                  S9[        SXSU R                  S9/5        U[        L a/  [        U S5      (       a  U R                  U R                  S   l        U[        L a/  [        U S5      (       a  U R                  U R                  S	   l        [        R!                  XUS
9  g)a  build the document using the flowables.  Annotate the first page using the onFirstPage
function and later pages using the onLaterPages function.  The onXXX pages should follow
the signature

   def myOnFirstPage(canvas, document):
       # do annotations and modify the document
       ...

The functions can do things like draw logos, page numbers,
footers, etcetera. They can use external variables to vary
the look (for example providing page numbering or section names).
normal)r   First)r   r   r   r   r  onFirstPager   onLaterPagesrQ   )r8  N)r  r   r\  r_  r/   r1   r  r   r   r@   r8   r  rZ  r  r  r   rB  )rM   r  r  r  r8  frameTs         r-   rB  SimpleDocTemplate.build  s     	

t(9(94::t{{W_`|wfbfbobop$v\`\i\ijl 	m*$m)D)D373C3CDq!0:%'$~*F*F373D3DDq!0d+Fr,   r&   N)r'   r(   r)   r*   rs   r  r  r@   r   r  rB  r+   r&   r,   r-   r   r     s*     */ *4*Z`ZgZg Gr,   r   c                 "    [        SX4-  5        g)a  Example prototype for progress monitoring.

This aims to provide info about what is going on
during a big job.  It should enable, for example, a reasonably
smooth progress bar to be drawn.  We design the argument
signature to be predictable and conducive to programming in
other (type safe) languages.  If set, this will be called
repeatedly with pairs of values.  The first is a string
indicating the type of call; the second is a numeric value.

typ 'STARTING', value = 0
typ 'SIZE_EST', value = numeric estimate of job size
typ 'PASS', value = number of this rendering pass
typ 'PROGRESS', value = number between 0 and SIZE_EST
typ 'PAGE', value = page number of page
type 'FINISHED', value = 0

The sequence is
    STARTING - always called once
    SIZE_EST - always called once
    PROGRESS - called often
    PAGE - called often when page is emitted
    FINISHED - called when really, really finished

some juggling is needed to accurately estimate numbers of
pages in pageDrawing mode.

NOTE: the SIZE_EST is a guess.  It is possible that the
PROGRESS value may slightly exceed it, or may even step
back a little on rare occasions.  The only way to be
really accurate would be to do two passes, and I don't
want to take that performance hit.
zPROGRESS MONITOR:  %-10s   %dN)rg  )typr%  s     r-   
progressCBr  ,  s    D 

)SL
89r,   __main__)_baseFontName_baseFontNameBc                    SSK Jn  U R                  S   nU R                  " 5         U R                  " U5        U R
                  " S5        U R                  " SSSUS-
  5        U R                  " [        S5        U R                  " SUS-
  S	5        U R                  " [        S
5        U R                  " S[        -  S[        -  S5        U R                  " 5         g )Nr   redrQ      B   H      l   zTABLE OF CONTENTS DEMO            ?z
First Page)reportlab.lib.colorsr  r  	saveStatesetStrokeColorsetLineWidthlinesetFontr  
drawStringr  r   restoreStater   r?   r  PAGE_HEIGHTs       r-   myFirstPager  R  s    ,&&q)c"ABr"[^,~b)#{30HI}R(!d(D4K>r,   c                 v   SSK Jn  U R                  S   nU R                  " 5         U R                  " U5        U R
                  " S5        U R                  " SSSUS-
  5        U R                  " [        S5        U R                  " S[        -  S	[        -  S
UR                  -  5        U R                  " 5         g )Nr   r  rQ   r  r  r  r  r  r  zPage %d)r  r  r  r  r  r  r  r  r  r  r   r  r  r  s       r-   myLaterPagesr  _  s    ,&&q)c"ABr"[^,}R(!d(D4KSXX1EFr,   c                     / n SSK Jn  SSKJn  U" S5      nSUl        SUl        SSKJn  SS Kn[        S5       Hj  nS	S
UR                  5       -  -   n[        S[        -  U[        -  SU-  5      nU R                  U5        [        U" 5       U5      n	U R                  U	5        Ml     U" S5      R                  U [        [         S9  g )Nr   )ParagraphStyle)r   r        )
randomText   g      ?   zBox Number %dzdoctemplate.pdf)r  r  )reportlab.lib.stylesr  reportlab.platypus.doctemplater   firstLineIndentspaceBeforereportlab.lib.randomtextr  randomrangeXBoxr   r3  r   rB  r  r  )
objects_to_drawr  r   r  r  r  r
  r1   r  paras
             r-   runr  j  s    7D  )!#7rAAfmmo-.Fq4x$!0CDC""3'Z\62D""4(  	+,22?# 	3 	?r,   )H__all____version__rs   reportlab.platypus.flowablesr   reportlab.lib.unitsr   reportlab.libr   reportlab.platypus.paragraphr   reportlab.platypus.framesr   reportlab.rl_configr   r   r   reportlab.lib.sequencerr'  reportlab.pdfgenr   reportlab.lib.utilsr   r   r    r!   r"   r  	NameErrorsetsr#   rR  logging	getLoggerr  	Exceptionr	   r=   r@   rF   rB   rw   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r  r   r!  r   rX  r   r   r  r'   r  r  r  r  r  r  r&   r,   r-   <module>r     s  
& 	0 + 8 $ & 2 + C C  # ^ ^   			/	0	) 	(	d &x 4%MX %MN 
	^~ 	^> >
A+ A '" '  $
[)	v( v." ."S+ S>~ >? ?B%	: 	:=8 =8~aZ- Z-x&G &GP":H zB	?, Ea e(    s   E9 9F	F	