o
    ðäj¢  ã                   @   s¨   d dl mZ d dlmZ d dlmZ ddlmZmZm	Z	 ddl
mZ G dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    )Úsafe_string)ÚElement)ÚIndexedListé   )Ú
DescriptorÚAliasÚ_convert)Ú
namespacedc                       sF   e Zd ZdZedƒZeefZdZ	dZ
eZ‡ fdd„Zd	dd„Z‡  ZS )
ÚSequencez[
    A sequence (list or tuple) that may only contain objects of the declared
    type
    Nr   Fc                    sL   t |ˆ jƒs
tdƒ‚ˆ  ‡ fdd„|D ƒ¡}ˆ jrt|ƒ}tƒ  ||¡ d S )NúValue must be a sequencec                 3   s   � | ]	}t ˆ j|ƒV  qd S ©N)r   Úexpected_type)Ú.0Úvalue©Úself© úa/var/www/ticemtrilhas/avaliacao_env/lib/python3.10/site-packages/openpyxl/descriptors/sequence.pyÚ	<genexpr>   s   € z#Sequence.__set__.<locals>.<genexpr>)Ú
isinstanceÚ	seq_typesÚ	TypeErrorÚ	containerÚuniquer   ÚsuperÚ__set__©r   ÚinstanceÚseq©Ú	__class__r   r   r      s   zSequence.__set__c                 c   sX   � t || jƒD ]"\}}t|dƒr| ||¡}nt|||ƒ}t|ƒ}t|ƒ|_|V  qdS )úV
        Convert the sequence represented by the descriptor to an XML element
        Úto_treeN)Ú	enumerateÚidx_baseÚhasattrr"   r	   r   r   Útext)r   ÚtagnameÚobjÚ	namespaceÚidxÚvÚelr   r   r   r"   "   s   €

ùzSequence.to_treer   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Útyper   ÚlistÚtupler   r$   r   r   r   r"   Ú__classcell__r   r   r   r   r
      s    
r
   c                   @   s   e Zd ZdZeeefZeZdS )ÚUniqueSequencez)
    Use a set to keep values unique
    N)	r-   r.   r/   r0   r2   r3   Úsetr   r   r   r   r   r   r5   0   s    
r5   c                   @   ó&   e Zd ZdZdZddd„Zdd„ ZdS )	ÚValueSequencezq
    A sequence of primitive types that are stored as a single attribute.
    "val" is the default attribute
    ÚvalNc                 c   s2   � t | ||ƒ}|D ]}t|| jt|ƒiƒV  q	d S r   )r	   r   Ú	attributer   )r   r'   r(   r)   r+   r   r   r   r"   A   s
   €ÿzValueSequence.to_treec                 C   s   |  | j¡S r   )Úgetr:   ©r   Únoder   r   r   Ú	from_treeG   s   zValueSequence.from_treer   )r-   r.   r/   r0   r:   r"   r>   r   r   r   r   r8   8   s
    
r8   c                   @   r7   )	ÚNestedSequencez1
    Wrap a sequence in an containing object
    FNc                 C   sJ   t | ||ƒ}t|ƒ}| jr| dtt|ƒƒ¡ |D ]	}| | ¡ ¡ q|S )NÚcount)r	   r   r@   r6   ÚstrÚlenÚappendr"   )r   r'   r(   r)   r   r+   r   r   r   r"   S   s   zNestedSequence.to_treec                    s   ‡ fdd„|D ƒS )Nc                    s   g | ]}ˆ j  |¡‘qS r   )r   r>   )r   r,   r   r   r   Ú
<listcomp>^   s    z,NestedSequence.from_tree.<locals>.<listcomp>r   r<   r   r   r   r>   ]   s   zNestedSequence.from_treer   )r-   r.   r/   r0   r@   r"   r>   r   r   r   r   r?   L   s
    

r?   c                   @   s"   e Zd ZdZdd„ Zddd„ZdS )ÚMultiSequencez;
    Sequences can contain objects with different tags
    c                 C   s0   t |ttfƒstdƒ‚t|ƒ}t | ||¡ d S )Nr   )r   r3   r2   Ú
ValueErrorr   r   r   r   r   r   r   f   s   zMultiSequence.__set__Nc                 c   s"   � |D ]}|j |d�}|V  qdS )r!   )r)   N)r"   )r   r'   r(   r)   r+   r,   r   r   r   r"   m   s
   €þzMultiSequence.to_treer   )r-   r.   r/   r0   r   r"   r   r   r   r   rE   a   s    rE   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚMultiSequencePartzŽ
    Allow a multisequence to be built up from parts

    Excluded from the instance __elements__ or __attrs__ as is effectively an Alias
    c                 C   s   || _ || _d S r   )r   Ústore)r   r   rH   r   r   r   Ú__init__}   s   
zMultiSequencePart.__init__c                 C   s"   t | j|ƒ}|j| j  |¡ d S r   )r   r   Ú__dict__rH   rC   )r   r   r   r   r   r   r   ‚   s   zMultiSequencePart.__set__c                 C   s   | S r   r   )r   r   Úclsr   r   r   Ú__get__‡   s   zMultiSequencePart.__get__N)r-   r.   r/   r0   rI   r   rL   r   r   r   r   rG   v   s
    rG   N)Úopenpyxl.compatr   Úopenpyxl.xml.functionsr   Úopenpyxl.utils.indexed_listr   Úbaser   r   r   r)   r	   r
   r5   r8   r?   rE   rG   r   r   r   r   Ú<module>   s   %