
    Kwg                     X    d Z ddlmZmZmZ ddlmZ d Z G d de      Z G d d      Z	y	)
zHhelper for importing pdf structures into a ReportLab generated document
    )format	PDFObject	pdfdocEnc)strTypesc                 0   t        t        t              rt        nt        f}|t        t        fz   }| D ]a  }t        ||      rt        |      dk7  rt        dt        |      z         t        |d   t              rIt        dt        |d         z          y )N   zTsequence elts must be strings/bytes/PDFPatternIfs or singletons containing strings: r   zCSingletons must contain strings/bytes or PDFObject instances only: )
isinstancer   tupler   PDFPatternIflen
ValueErrorascii)pattern_sequenceallowedTypesxs      S/var/www/horilla/myenv/lib/python3.12/site-packages/reportlab/pdfbase/pdfpattern.py_patternSequenceCheckr      s    )(E:8L9\"::L t!L)1vqy !wx}~  yA  "A  B  Bad8, !fglmnopmqgr!rsst    c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	
PDFPatternr   c                 6    t        |       || _        || _        y)a  
        Description of a kind of PDF object using a pattern.

        Pattern sequence should contain strings, singletons of form [string] or
        PDFPatternIf objects.
        Strings are literal strings to be used in the object.
        Singletons are names of keyword arguments to include.
        PDFpatternIf objects allow some conditionality.
        Keyword arguments can be non-instances which are substituted directly in string conversion,
        or they can be object instances in which case they should be pdfdoc.* style
        objects with a x.format(doc) method.
        Keyword arguments may be set on initialization or subsequently using __setitem__, before format.
        "constant object" instances can also be inserted in the patterns.
        N)r   pattern	arguments)selfr   keywordargss      r   __init__zPDFPattern.__init__   s     	./'$r   c                 "    || j                   |<   y Nr   )r   itemvalues      r   __setitem__zPDFPattern.__setitem__%   s    $tr   c                      | j                   |   S r   r   )r   r    s     r   __getitem__zPDFPattern.__getitem__(   s    ~~d##r   c              #     K   | j                   }| j                  }|D ]:  }t        |t              rt	        |       "t        |t
              r|j                  |       Ft        |t              r`t        | j                  |j                              }|xr |d   }| j                  |r|j                  n|j                        D ]  }|  |d   }|j                  |d       }	|	t        dt        |      z        t        |	t
              rt        |	|       t        |	t              rt	        |	       %t	        t!        |	             = y w)Nr   z%s value not defined)r   _PDFPattern__documentr	   r   r   r   r   r   listevalcondthenPartelsePartgetr   r   str)
r   Lr   documentr   resultr)   znamer!   s
             r   r(   zPDFPattern.eval+   s    NN	?? 	0A!H%l"Ai(hhx((Al+dii/0+&)1::1::F AG t!dD1=$%;eDk%IJJeI. x00h/#E**#CJ//)	0s   EEc                 x    || _         	 dj                  | j                  | j                              | ` S # | ` w xY w)Nr   )r&   joinr(   r   )r   r/   s     r   r   zPDFPattern.formatD   s2    "	 88DIIdll34s   )5 9c                     t         j                  | j                        }| j                  |_        | j                  |_        |S r   )object__new__	__class__r   r   )r   cs     r   clonezPDFPattern.cloneK   s/    NN4>>*LL	nnr   N)
__name__
__module____qualname____RefOnly__r   r"   r$   r(   r   r:    r   r   r   r      s%    K%&%$02 r   r   c                       e Zd ZdZg g fdZy)r   zcond will be evaluated as [cond] in PDFpattern eval.
    It should evaluate to a list with value 0/1 etc etc.
    thenPart is a list to be evaluated if the cond evaulates true,
    elsePart is the false sequence.
    c                 ~    t        |t              s|g}|||fD ]  }t        |        || _        || _        || _        y r   )r	   r'   r   r)   r*   r+   )r   r)   r*   r+   r   s        r   r   zPDFPatternIf.__init__W   sE    $t$dVdx) 	%A!!$	%	  r   N)r;   r<   r=   __doc__r   r?   r   r   r   r   Q   s    
 %' !r   r   N)
rB   reportlab.pdfbase.pdfdocr   r   r   reportlab.lib.utilsr   r   r   r   r?   r   r   <module>rE      s2   	 A A (t? ?B! !r   