o
    §…ËY×  ã                   @   s\   d Z ddlmZmZmZ ddlmZ ddlmZ dd„ Z	G dd„ deƒZ
G d	d
„ d
eƒZdS )zHhelper for importing pdf structures into a ReportLab generated document
é    )ÚformatÚ	PDFObjectÚ	pdfdocEnc)Úascii)Ú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Ú
ValueErrorr   )Úpattern_sequenceÚallowedTypesÚx© r   úN/var/www/html/env/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   E   s   zPDFPattern.formatc                 C   s    t  | j¡}| j|_| j|_|S r   )ÚobjectÚ__new__Ú	__class__r   r   )r   Úcr   r   r   ÚcloneL   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
   zÙcond 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   X   s   

zPDFPatternIf.__init__N)r3   r4   r5   Ú__doc__r   r   r   r   r   r
   R   s    r
   N)r7   Úreportlab.pdfbase.pdfdocr   r   r   Ú	reportlabr   Úreportlab.lib.utilsr   r   r   r.   r
   r   r   r   r   Ú<module>   s    
A