U
    '1e³  ã                   @   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 ]L}t ||ƒs$t|ƒdkrNtdt|ƒ ƒ‚t |d tƒs$t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_sequenceZallowedTypesÚx© r   ú@/tmp/pip-unpacked-wheel-109iniqw/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   Z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 ]ä}t|tƒr*t|ƒV  qt|tƒrB| |¡V  qt|tƒrŒt|  	|j
¡ƒ}|of|d }|  	|rv|jn|j¡D ]
}|V  q~q|d }| |d ¡}	|	d kr¸tdt|ƒ ƒ‚t|	tƒrÐt|	|ƒV  qt|	tƒræt|	ƒ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   +   s*    





zPDFPattern.evalc                 C   s(   || _ zd |  | j¡¡W ¢S | ` X d S )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__Z__RefOnly__r   r   r   r   r   r0   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   W   s    
 
zPDFPatternIf.__init__N)r1   r2   r3   Ú__doc__r   r   r   r   r   r	   Q   s   r	   N)
r4   Zreportlab.pdfbase.pdfdocr   r   r   Zreportlab.lib.utilsr   r   r   r	   r   r   r   r   Ú<module>   s
   
A