o
    ˷e                     @   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dS )    )safe_string)Element)IndexedList   )
DescriptorAlias_convert)
namespacedc                       sB   e Zd ZdZedZeefZdZ	d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                    sJ   t | js
td fdd|D } jrt|}tt || d S )NValue must be a sequencec                    s   g | ]}t  j|qS  )r   expected_type).0valueselfr   T/var/www/ideatree/venv/lib/python3.10/site-packages/openpyxl/descriptors/sequence.py
<listcomp>       z$Sequence.__set__.<locals>.<listcomp>)
isinstance	seq_types	TypeErroruniquer   superr
   __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_treeN)__name__
__module____qualname____doc__typer   listtupler   r#   r   r   r!   __classcell__r   r   r   r   r
      s    
r
   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!   8   s
   zValueSequence.to_treec                 C   s   | | jS r,   )getr8   r   noder   r   r   	from_tree>   s   zValueSequence.from_treer,   )r-   r.   r/   r0   r8   r!   r<   r   r   r   r   r6   /   s
    
r6   c                   @   r5   )	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>   setstrlenappendr!   )r   r&   r'   r(   	containerr*   r   r   r   r!   J   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   r   U   r   z,NestedSequence.from_tree.<locals>.<listcomp>r   r:   r   r   r   r<   T   s   zNestedSequence.from_treer,   )r-   r.   r/   r0   r>   r!   r<   r   r   r   r   r=   C   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   ]   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!   d   s
   zMultiSequence.to_treer,   )r-   r.   r/   r0   r   r!   r   r   r   r   rD   X   s    rD   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   rG   r   r   r   __init__t   s   
zMultiSequencePart.__init__c                 C   s"   t | j|}|j| j | d S r,   )r   r   __dict__rG   rB   )r   r   r   r   r   r   r   y   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   rH   r   rK   r   r   r   r   rF   m   s
    rF   N)openpyxl.compatr   openpyxl.xml.functionsr   openpyxl.utils.indexed_listr   baser   r   r   r(   r	   r
   r6   r=   rD   rF   r   r   r   r   <module>   s   $