a
    b                     @   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r4t|}tt || d S )NValue must be a sequencec                    s   g | ]}t  j|qS  )r   expected_type).0valueselfr   m/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/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   sV   t || jD ]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                   @   s&   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   s0   t | ||}|D ]}t|| jt|iV  qd S N)r	   r   	attributer   )r   r&   r'   r(   r*   r   r   r   r!   8   s    zValueSequence.to_treec                 C   s   | | jS r6   )getr7   r   noder   r   r   	from_tree>   s    zValueSequence.from_tree)N)r,   r-   r.   r/   r7   r!   r;   r   r   r   r   r4   /   s   
r4   c                   @   s&   e Zd ZdZdZdddZdd ZdS )	NestedSequencez1
    Wrap a sequence in an containing object
    FNc                 C   sJ   t | ||}t|}| jr.|dtt| |D ]}||  q2|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   r9   r   r   r   r;   T   s    zNestedSequence.from_tree)N)r,   r-   r.   r/   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   r2   r1   
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_tree)N)r,   r-   r.   r/   r   r!   r   r   r   r   rC   X   s   rC   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 r6   )r   store)r   r   rF   r   r   r   __init__t   s    zMultiSequencePart.__init__c                 C   s"   t | j|}|j| j | d S r6   )r   r   __dict__rF   rA   )r   r   r   r   r   r   r   y   s    zMultiSequencePart.__set__c                 C   s   | S r6   r   )r   r   clsr   r   r   __get__~   s    zMultiSequencePart.__get__N)r,   r-   r.   r/   rG   r   rJ   r   r   r   r   rE   m   s   rE   N)Zopenpyxl.compatr   Zopenpyxl.xml.functionsr   Zopenpyxl.utils.indexed_listr   baser   r   r   r(   r	   r
   r4   r<   rC   rE   r   r   r   r   <module>   s   $