o
    g                     @   st   d Z ddlmZ ddlmZ ddlmZmZ ddlmZm	Z	m
Z
 ddlmZmZ G dd deZG d	d
 d
eZdS )z
RichText definition
    copy)NUMERIC_TYPES)
InlineFontText)StrictStringTyped)Element
whitespacec                   @   sH   e Zd ZdZeedZe Zdd Z	dd Z
dd Zd	d
 Zdd ZdS )	TextBlockzv Represents text string in a specific format

    This class is used as part of constructing a rich text strings.
    )expected_typec                 C   s   || _ || _d S N)fonttext)selfr   r    r   Q/var/www/html/api-tag/env/lib/python3.10/site-packages/openpyxl/cell/rich_text.py__init__   s   
zTextBlock.__init__c                 C   s   | j |j ko| j|jkS r   )r   r   )r   otherr   r   r   __eq__   s   zTextBlock.__eq__c                 C   s   | j S )zJust retun the text)r   r   r   r   r   __str__"   s   zTextBlock.__str__c                 C   s0   | j t kr	| j p
d}| jj d| j d| S )Ndefaultz text=z, font=)r   r   	__class____name__r   )r   r   r   r   r   __repr__'   s   zTextBlock.__repr__c                 C   sB   t d}|| jjdd t d}| j|_t| || |S )NrrPr)tagnamet)r
   appendr   to_treer   r   )r   elr    r   r   r   r"   ,   s   
zTextBlock.to_treeN)r   
__module____qualname____doc__r	   r   r   r   r   r   r   r   r   r"   r   r   r   r   r      s    
r   c                       s   e Zd ZdZ fddZedd Zedd Zedd	 Z fd
dZ	 fddZ
dd Z fddZ fddZ fddZdd Zdd Zdd Zdd Z  ZS )CellRichTexta  Represents a rich text string.

    Initialize with a list made of pure strings or :class:`TextBlock` elements
    Can index object to access or modify individual rich text elements
    it also supports the + and += operators between rich text strings
    There are no user methods for this class

    operations which modify the string will generally call an optimization pass afterwards,
    that merges text blocks with identical formats, consecutive pure text strings,
    and remove empty strings and empty text blocks
    c                    sZ   t |dkr |d }t|ttfrt| nt| |g}nt| t | d S )N   r   )	len
isinstancelisttupler'   _check_rich_text_check_elementsuperr   )r   argsr   r   r   r   I   s   

zCellRichText.__init__c                 C   s"   t |tttfstd| d S )NzIllegal CellRichText element )r*   strr   r   	TypeError)clsvaluer   r   r   r.   V   s   zCellRichText._check_elementc                 C   s   |D ]}t | qd S r   )r'   r.   )r4   	rich_textr    r   r   r   r-   \   s   zCellRichText._check_rich_textc                 C   st   t |}|jr|jddfS g }|jD ] }d}|jr#|jdd}|jr0|t|j| q|| q| |S )Nx005F_ )r   	from_treer    replacer   r   r!   r   )r4   noder   sr   r    r   r   r   r9   a   s   

zCellRichText.from_treec                    s   d }t t }| D ]9}t|tr|sq	n|jsq	t|t|kr9t|tr*||7 }q	|j|jkr9| j|j7  _q	|r@|| |}q	|rJ|| t 	t
d | | S r   )r'   r,   r*   r2   r   typer   r!   r/   __setitem__slice)r   last_tlr    r1   r   r   _opts   s.   




zCellRichText._optc                    s,   t | t dd t|D  |  S )Nc                 S      g | ]}t |qS r   r   .0er   r   r   
<listcomp>       z)CellRichText.__iadd__.<locals>.<listcomp>)r'   r-   r/   __iadd__r+   rB   r   argr1   r   r   rI      s   
zCellRichText.__iadd__c                 C   s"   t dd t| t| D  S )Nc                 S   rC   r   r   rD   r   r   r   rG      rH   z(CellRichText.__add__.<locals>.<listcomp>)r'   r+   rB   rJ   r   r   r   __add__   s   "zCellRichText.__add__c                    s$   t | t || |   d S r   )r'   r.   r/   r>   rB   )r   indxvalr1   r   r   r>      s   
zCellRichText.__setitem__c                       t | t | d S r   )r'   r.   r/   r!   rJ   r1   r   r   r!         
zCellRichText.appendc                    rO   r   )r'   r-   r/   extendrJ   r1   r   r   rQ      rP   zCellRichText.extendc                 C   s   d ddd | D S )NzCellRichText([{}])z, c                 s   s    | ]}t |V  qd S r   )reprrE   r<   r   r   r   	<genexpr>   s    z(CellRichText.__repr__.<locals>.<genexpr>)formatjoinr   r   r   r   r      s   zCellRichText.__repr__c                 C   s   d dd | D S )Nr8   c                 S   rC   r   r2   rS   r   r   r   rG      rH   z(CellRichText.__str__.<locals>.<listcomp>)rV   r   r   r   r   r      s   zCellRichText.__str__c                 C   s   dd | D S )zv
        Returns a list of the strings contained.
        The main reason for this is to make editing easier.
        c                 S   rC   r   rW   rS   r   r   r   rG      rH   z(CellRichText.as_list.<locals>.<listcomp>r   r   r   r   r   as_list   s   zCellRichText.as_listc                 C   sb   t d}| D ](}t|tr||  qt d}t d}||_t| || || q|S )z4
        Return the full XML representation
        isr   r    )r
   r*   r   r!   r"   r   r   )r   	containerobjr#   r    r   r   r   r"      s   

zCellRichText.to_tree)r   r$   r%   r&   r   classmethodr.   r-   r9   rB   rI   rL   r>   r!   rQ   r   r   rX   r"   __classcell__r   r   r1   r   r'   <   s&    


r'   N)r&   r   openpyxl.compatr   openpyxl.cell.textr   r   openpyxl.descriptorsr   r   r	   openpyxl.xml.functionsr
   r   r   r+   r'   r   r   r   r   <module>   s   +