
    Mwg                         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e      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    )safe_string)Element)IndexedList   )
DescriptorAlias_convert)
namespacedc                   N     e Zd ZdZ ed      ZeefZdZ	dZ
eZ fdZddZ xZS )Sequencez[
    A sequence (list or tuple) that may only contain objects of the declared
    type
    Nr   Fc                      t        | j                        st        d       j                   fd|D              } j                  rt        |      }t           ||       y )NValue must be a sequencec              3   J   K   | ]  }t        j                  |        y wN)r	   expected_type).0valueselfs     T/var/www/horilla/myenv/lib/python3.12/site-packages/openpyxl/descriptors/sequence.py	<genexpr>z#Sequence.__set__.<locals>.<genexpr>   s     RUXd&8&8%@Rs    #)
isinstance	seq_types	TypeError	containeruniquer   super__set__)r   instanceseq	__class__s   `  r   r   zSequence.__set__   sP    #t~~.677nnRcRR;;c"C#&    c              #      K   t        || j                        D ]P  \  }}t        |d      r|j                  ||      }n(t	        |||      }t        |      }t        |      |_        | R yw)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els          r   r$   zSequence.to_tree"   sh       T]]3 	FCq)$YYw,$S'9=W%%a.H	s   A+A-r   )__name__
__module____qualname____doc__typer   listtupler   r&   r   r   r   r$   __classcell__)r    s   @r   r   r      s5    
 JMuIHFI'r!   r   c                       e Zd ZdZeeefZeZy)UniqueSequencez)
    Use a set to keep values unique
    N)	r/   r0   r1   r2   r4   r5   setr   r    r!   r   r8   r8   0   s     uc"IIr!   r8   c                   "    e Zd ZdZdZddZd Zy)ValueSequencezq
    A sequence of primitive types that are stored as a single attribute.
    "val" is the default attribute
    valNc              #   z   K   t        | ||      }|D ]%  }t        || j                  t        |      i       ' y wr   )r
   r   	attributer   )r   r)   r*   r+   r-   s        r   r$   zValueSequence.to_treeA   s?     T7I6 	DA'DNN;q>#BCC	Ds   9;c                 8    |j                  | j                        S r   )getr?   )r   nodes     r   	from_treezValueSequence.from_treeG   s    xx''r!   r   )r/   r0   r1   r2   r?   r$   rC   r:   r!   r   r<   r<   8   s    
 ID(r!   r<   c                   "    e Zd ZdZdZddZd Zy)NestedSequencez1
    Wrap a sequence in an containing object
    FNc                     t        | ||      }t        |      }| j                  r$|j                  dt	        t        |                   |D ]!  }|j                  |j                                # |S )Ncount)r
   r   rG   r9   strlenappendr$   )r   r)   r*   r+   r   r-   s         r   r$   zNestedSequence.to_treeS   s`    T7I6G$	::MM'3s3x=1 	*AQYY[)	*r!   c                 ^    |D cg c]  }| j                   j                  |       c}S c c}w r   )r   rC   )r   rB   r.   s      r   rC   zNestedSequence.from_tree]   s'    ;?@R"",,R0@@@s   "*r   )r/   r0   r1   r2   rG   r$   rC   r:   r!   r   rE   rE   L   s     EAr!   rE   c                       e Zd ZdZd ZddZy)MultiSequencez;
    Sequences can contain objects with different tags
    c                     t        |t        t        f      st        d      t        |      }t	        j
                  | ||       y )Nr   )r   r5   r4   
ValueErrorr   r   )r   r   r   s      r   r   zMultiSequence.__set__f   s7    #t}-7883i43/r!   Nc              #   F   K   |D ]  }|j                  |      }|  yw)r#   )r+   N)r$   )r   r)   r*   r+   r-   r.   s         r   r$   zMultiSequence.to_treem   s,       	AY/BH	s   !r   )r/   r0   r1   r2   r   r$   r:   r!   r   rM   rM   a   s    0r!   rM   c                   "    e Zd ZdZd Zd Zd Zy)MultiSequencePartz
    Allow a multisequence to be built up from parts

    Excluded from the instance __elements__ or __attrs__ as is effectively an Alias
    c                      || _         || _        y r   )r   store)r   r   rT   s      r   __init__zMultiSequencePart.__init__}   s    *
r!   c                     t        | j                  |      }|j                  | j                     j	                  |       y r   )r	   r   __dict__rT   rJ   )r   r   r   s      r   r   zMultiSequencePart.__set__   s1    ++U3$**%,,U3r!   c                     | S r   r:   )r   r   clss      r   __get__zMultiSequencePart.__get__   s    r!   N)r/   r0   r1   r2   rU   r   rZ   r:   r!   r   rR   rR   v   s    
4
r!   rR   N)openpyxl.compatr   openpyxl.xml.functionsr   openpyxl.utils.indexed_listr   baser   r   r	   r+   r
   r   r8   r<   rE   rM   rR   r:   r!   r   <module>r_      sd    ( * 3 - - !"z "JX (H ((AX A*H * r!   