
    Mwg                         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e      Z G d	 d
e      Zy)z
RichText definition
    )copy)NUMERIC_TYPES)
InlineFontText)StrictStringTyped)Element
whitespacec                   N    e Zd ZdZ ee      Z e       Zd Z	d Z
d Zd Zd Zy)		TextBlockzv Represents text string in a specific format

    This class is used as part of constructing a rich text strings.
    )expected_typec                      || _         || _        y N)fonttext)selfr   r   s      N/var/www/horilla/myenv/lib/python3.12/site-packages/openpyxl/cell/rich_text.py__init__zTextBlock.__init__   s    		    c                 j    | j                   |j                   k(  xr | j                  |j                  k(  S r   )r   r   )r   others     r   __eq__zTextBlock.__eq__   s'    yyEJJ&B499

+BBr   c                     | j                   S )zJust retun the text)r   r   s    r   __str__zTextBlock.__str__"   s    yyr   c                     | j                   t               k7  xr | j                   xs d}| j                  j                   d| j                   d| S )Ndefaultz text=z, font=)r   r   	__class____name__r   )r   r   s     r   __repr__zTextBlock.__repr__'   sF    yyJL(6TYYC)..))*&74&IIr   c                     t        d      }|j                  | j                  j                  d             t        d      }| j                  |_        t        |       |j                  |       |S )NrrPr)tagnamet)r
   appendr   to_treer   r   )r   elr&   s      r   r(   zTextBlock.to_tree,   sT    S\
		$))##E#23CL1
		!	r   N)r    
__module____qualname____doc__r	   r   r   r   r   r   r   r   r!   r(    r   r   r   r      s5     z*D8D
C
J
r   r   c                        e Zd ZdZ fdZed        Zed        Zed        Z fdZ	 fdZ
d Z fd	Z fd
Z fdZd Zd Zd Zd Z x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                     t        |      dk(  rJ|d   }t        |t        t        f      rt        j                  |       n.t        j                  |       |g}nt        j                  |       t        | !  |       y )N   r   )	len
isinstancelisttupler/   _check_rich_text_check_elementsuperr   )r   argsr   s     r   r   zCellRichText.__init__I   sc    t9>7D$u.--d3++D1v))$/r   c                 V    t        |t        t        t        f      st	        d|       y )NzIllegal CellRichText element )r3   strr   r   	TypeError)clsvalues     r   r7   zCellRichText._check_elementV   s,    %#y-!@A;E7CDD Br   c                 <    |D ]  }t         j                  |        y r   )r/   r7   )r=   	rich_textr&   s      r   r6   zCellRichText._check_rich_text\   s     	+A''*	+r   c                    t        j                  |      }|j                  r|j                  j                  dd      fS g }|j                  D ]o  }d}|j                  r|j                  j                  dd      }|j
                  r&|j                  t        |j
                  |             _|j                  |       q  | |      S )Nx005F_ )r   	from_treer&   replacer#   r$   r'   r   )r=   noder   sr#   r&   s         r   rD   zCellRichText.from_treea   s    ~~d#66FFNN8R022 	AAssCCKK"-uu155!,-	 1vr   c                    d }t        t                     }| D ]  }t        |t              r|s|j                  s#t        |      t        |      k(  rOt        |t              r||z  }P|j                  |j                  k(  r |xj                  |j                  z  c_        |r|j                  |       |} |r|j                  |       t        | %  t        d       |       | S r   )r/   r5   r3   r;   r   typer   r'   r8   __setitem__slice)r   last_tlr&   r   s       r   _optzCellRichText._opts   s    ! 	A!S!VVF|tAw&a%aKF[[AFF*KK166)K F	  HHVE$K+r   c                     t         j                  |       t        |   t	        |      D cg c]  }t        |       c}       | j                         S c c}w r   )r/   r6   r8   __iadd__r4   r   rN   )r   arger   s      r   rP   zCellRichText.__iadd__   sB    %%c*495a$q'56yy{ 6s   Ac                     t        t        |       t        |      z   D cg c]  }t        |       c}      j                         S c c}w r   )r/   r4   r   rN   )r   rQ   rR   s      r   __add__zCellRichText.__add__   s5    d4j49.DET!WEFKKMMEs   Ac                 p    t         j                  |       t        |   ||       | j	                          y r   )r/   r7   r8   rJ   rN   )r   indxvalr   s      r   rJ   zCellRichText.__setitem__   s)    ##C(D#&		r   c                 N    t         j                  |       t        |   |       y r   )r/   r7   r8   r'   r   rQ   r   s     r   r'   zCellRichText.append   s    ##C(sr   c                 N    t         j                  |       t        |   |       y r   )r/   r6   r8   extendrY   s     r   r[   zCellRichText.extend   s    %%c*sr   c                 P    dj                  dj                  d | D                    S )NzCellRichText([{}])z, c              3   2   K   | ]  }t        |        y wr   )repr).0rG   s     r   	<genexpr>z(CellRichText.__repr__.<locals>.<genexpr>   s     5L!d1g5Ls   )formatjoinr   s    r   r!   zCellRichText.__repr__   s"    #**4995Lt5L+MNNr   c                 \    dj                  | D cg c]  }t        |       c}      S c c}w )NrC   )rb   r;   r   rG   s     r   r   zCellRichText.__str__   s#    ww-1A-..-s   )c                 >    | D cg c]  }t        |       c}S c c}w )zv
        Returns a list of the strings contained.
        The main reason for this is to make editing easier.
        )r;   rd   s     r   as_listzCellRichText.as_list   s    
 !%%1A%%%s   c                    t        d      }| D ]|  }t        |t              r |j                  |j	                                3t        d      }t        d      }||_        t        |       |j                  |       |j                  |       ~ |S )z4
        Return the full XML representation
        isr#   r&   )r
   r3   r   r'   r(   r   r   )r   	containerobjr)   r&   s        r   r(   zCellRichText.to_tree   s}     DM	 
	%C#y)  / S\CL1		!  $
	% r   )r    r*   r+   r,   r   classmethodr7   r6   rD   rN   rP   rT   rJ   r'   r[   r!   r   rf   r(   __classcell__)r   s   @r   r/   r/   <   s    

 E E
 + +  "4N

O/&r   r/   N)r,   r   openpyxl.compatr   openpyxl.cell.textr   r   openpyxl.descriptorsr   r   r	   openpyxl.xml.functionsr
   r   r   r4   r/   r-   r   r   <module>rq      s?     ) /  7" "VM4 Mr   