o
    vh                     @   sN   d Z ddlmZmZmZ ddlmZ dd ZG dd deZG dd	 d	Z	d
S )zHhelper for importing pdf structures into a ReportLab generated document
    )format	PDFObject	pdfdocEnc)strTypesc                 C   sv   t ttrtntf}|ttf }| D ]&}t ||s8t|dkr'tdt| t |d ts8tdt|d  qd S )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x r   Z/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/reportlab/pdfbase/pdfpattern.py_patternSequenceCheck   s   
r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )
PDFPatternr   c                 K   s   t | || _|| _dS )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   keywordargsr   r   r   __init__   s   
zPDFPattern.__init__c                 C   s   || j |< d S Nr   )r   itemvaluer   r   r   __setitem__%   s   zPDFPattern.__setitem__c                 C   s
   | j | S r   r   )r   r   r   r   r   __getitem__(   s   
zPDFPattern.__getitem__c           
      c   s    | j }| j}|D ]r}t|trt|V  q	t|tr"||V  q	t|trGt| 	|j
}|o4|d }| 	|r<|jn|jD ]}|V  q@q	|d }||d }	|	d u r]tdt| t|	trit|	|V  q	t|	trtt|	V  q	tt|	V  q	d S )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   r   r   r   r!   +   s0   




zPDFPattern.evalc                 C   s&   || _ zd| | jW | ` S | ` w )N    )r   joinr!   r   )r   r(   r   r   r   r   D   s   zPDFPattern.formatc                 C   s    t | j}| j|_| j|_|S r   )object__new__	__class__r   r   )r   cr   r   r   cloneK   s   zPDFPattern.cloneN)
__name__
__module____qualname____RefOnly__r   r   r   r!   r   r2   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZg g fddZdS )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                 C   s>   t |ts|g}|||fD ]}t| q|| _|| _|| _d S r   )r   r    r   r"   r#   r$   )r   r"   r#   r$   r   r   r   r   r   W   s   

zPDFPatternIf.__init__N)r3   r4   r5   __doc__r   r   r   r   r   r	   Q   s    r	   N)
r7   reportlab.pdfbase.pdfdocr   r   r   reportlab.lib.utilsr   r   r   r	   r   r   r   r   <module>   s    
A