o
    g                     @   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 W/var/www/html/api-tag/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   %