
    Mwg                         d dl Z d dlmZ d dlmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ dZdZd	Z e j*                  d
j-                  eee            Zd Z G d de      Z G d de      Z G d de      Zy)    N)warn)AliasBoolStrictStringIntegerMatchPatternTyped)Serialisable)Element)escapeunescapez&"(?P<font>.+)"z&K(?P<color>[A-F0-9]{6})z&(?P<size>\d+\s?)z{0}|{1}|{2}c                     t        j                  dt         j                  t         j                  z        }|j	                  |       }	 |j                         }|S # t        $ r t        d       dddd}Y |S w xY w)z
    Split the combined (decoded) string into left, center and right parts

    # See http://stackoverflow.com/questions/27711175/regex-with-multiple-optional-groups for discussion
    zN
    (&L(?P<left>.+?))?
    (&C(?P<center>.+?))?
    (&R(?P<right>.+?))?
    $z3Cannot parse header or footer so it will be ignored )leftrightcenter)recompileVERBOSEDOTALLmatch	groupdictAttributeErrorr   )text
ITEM_REGEXmpartss       W/var/www/horilla/myenv/lib/python3.12/site-packages/openpyxl/worksheet/header_footer.py_split_stringr       s}      	 **ryy
 	"J 	A5 L  5FGB4L5s   A A87A8c                       e Zd ZdZ ed      Z ed      Z ed      ZdZ	 e
de	      ZddZd Zd	 Zed
        Zy)_HeaderFooterParta  
    Individual left/center/right header/footer part

    Do not use directly.

    Header & Footer ampersand codes:

    * &A   Inserts the worksheet name
    * &B   Toggles bold
    * &D or &[Date]   Inserts the current date
    * &E   Toggles double-underline
    * &F or &[File]   Inserts the workbook name
    * &I   Toggles italic
    * &N or &[Pages]   Inserts the total page count
    * &S   Toggles strikethrough
    * &T   Inserts the current time
    * &[Tab]   Inserts the worksheet name
    * &U   Toggles underline
    * &X   Toggles superscript
    * &Y   Toggles subscript
    * &P or &[Page]   Inserts the current page number
    * &P+n   Inserts the page number incremented by n
    * &P-n   Inserts the page number decremented by n
    * &[Path]   Inserts the workbook path
    * &&   Escapes the ampersand character
    * &"fontname"   Selects the named font
    * &nn   Selects the specified 2-digit font point size

    Colours are in RGB Hex
    T
allow_nonez^[A-Fa-f0-9]{6}$)r$   patternNc                 <    || _         || _        || _        || _        y N)r   fontsizecolor)selfr   r(   r)   r*   s        r   __init__z_HeaderFooterPart.__init__]   s    			
    c                    g }| j                   r*|j                  dj                  | j                                | j                  r*|j                  dj                  | j                               | j                  r*|j                  dj                  | j                               dj                  || j                  gz         S )zI
        Convert to Excel HeaderFooter miniformat minus position
        z&"{0}"z&{0} z&K{0}r   )r(   appendformatr)   r*   joinr   )r+   fmts     r   __str__z_HeaderFooterPart.__str__d   s     99JJy''		2399JJw~~dii01::JJw~~djj12xxtyyk)**r-   c                 ,    t        | j                        S r'   )boolr   r+   s    r   __bool__z_HeaderFooterPart.__bool__q   s    DIIr-   c                     dt        fdt        j                  |      D              }t        j                  d|      |d<    | di |S )z3
        Convert from miniformat to object
        )r(   r*   r)   c              3   R   K   | ]  }t        |      D ]  \  }}|r||f    y wr'   )zip).0r   kvkeyss       r   	<genexpr>z-_HeaderFooterPart.from_str.<locals>.<genexpr>|   s;      5U!$.5a! a& 5& 5s   $'r   r    )dictFORMAT_REGEXfindallsub)clsr   kwr>   s      @r   from_strz_HeaderFooterPart.from_strv   sO    
 ) 5l&:&:4&@ 5 5 "%%b$/6
yRyr-   )NNNN)__name__
__module____qualname____doc__r   r   r(   r   r)   RGBr	   r*   r,   r3   r7   classmethodrG   r@   r-   r   r"   r"   5   s[    > T"DT"Dd#DCD#6E+
 
 
r-   r"   c                       e Zd ZdZ ee      Z ee      Z ed      Z	 ee      Z
dZddZd Zd Zd	 Zed
        Zy)HeaderFooterItemz 
    Header or footer item

    )expected_typer   )LCRNc                 v    |
t               }|| _        |
t               }|| _        |
t               }|| _        y r'   )r"   r   r   r   )r+   r   r   r   s       r   r,   zHeaderFooterItem.__init__   s>    <$&D	>&(F=%'E
r-   c                 "   ddddddddd	t        j                  d
j                  D cg c]&  }dj                  t        j                  |            ( c}            }fd}g }t        | j                  | j                  | j                  | j                  g      D ]<  \  }}|j                  |j                  dj                  |t        |                   > dj                  |      }|j                  ||      }t	        |      S c c}w )z1
        Pack parts into a single string
        z&Az&Nz&Dz&Zz&Pz&Tz&Fz&G)z&[Tab]z&[Pages]z&[Date]z&[Path]z&[Page]z&[Time]z&[File]z
&[Picture]|z({0})c                 0    | j                  d      }|   S )zn
            Callback for re.sub
            Replace expanded control with mini-format equivalent
            r   )group)r   rD   	TRANSFORMs     r   replacez)HeaderFooterItem.__str__.<locals>.replace   s    
 ++a.CS>!r-   z&{0}{1}r   )r   r   r1   r0   r   r:   _HeaderFooterItem__keysr   r   r   r   r/   strrD   )r+   r<   
SUBS_REGEXrZ   txtkeypartrY   s          @r   r3   zHeaderFooterItem.__str__   s      $$ $$SW#')	
 ZZ3<*>./ +2..1*F *> !? @
	" KK$))T[[$**=? 	>ICyy$

:,,S#d)<=	> ggclnnWc*c{%*>s   +Dc                 Z    t        | j                  | j                  | j                  g      S r'   )anyr   r   r   r6   s    r   r7   zHeaderFooterItem.__bool__   s     DIIt{{DJJ788r-   c                 <    t        |      }t        |       |_        |S )z$
        Return as XML node
        )r   r\   r   )r+   tagnameels      r   to_treezHeaderFooterItem.to_tree   s     Wd)	r-   c                     |j                   r]t        |j                         }t        |      }|j                         D ]   \  }}|	t        j                  |      ||<   "  | di |}|S y )Nr@   )r   r   r    itemsr"   rG   )rE   noder   r   r<   r=   r+   s          r   	from_treezHeaderFooterItem.from_tree   sj    99DII&D!$'E =1=099!<E!H= <<DK r-   )NNN)rH   rI   rJ   rK   r
   r"   r   r   r   centrer   r[   r,   r3   r7   rf   rM   rj   r@   r-   r   rO   rO      s`    
 01D!23F8_F 12EF	<9
  r-   rO   c                       e Zd ZdZ ed      Z ed      Z ed      Z ed      Z e	e
d      Z e	e
d      Z e	e
d      Z e	e
d      Z e	e
d      Z e	e
d      ZdZ	 	 	 	 	 	 	 	 	 	 d	dZd Zy)
HeaderFooterheaderFooterTr#   )rP   r$   )	oddHeader	oddFooter
evenHeader
evenFooterfirstHeaderfirstFooterNc                     || _         || _        || _        || _        |
t	               }|| _        |
t	               }|| _        |
t	               }|| _        |
t	               }|| _        |	
t	               }	|	| _	        |

t	               }
|
| _
        y r'   )differentOddEvendifferentFirstscaleWithDocalignWithMarginsrO   ro   rp   rq   rr   rs   rt   )r+   rv   rw   rx   ry   ro   rp   rq   rr   rs   rt   s              r   r,   zHeaderFooter.__init__   s     !1,( 0(*I"(*I")+J$)+J$*,K&*,K&r-   c                     | j                   | j                  z   D cg c]  }t        | |       }}t        |      S c c}w r'   )	__attrs____elements__getattrrb   )r+   attrr   s      r   r7   zHeaderFooter.__bool__  s;    15$BSBS1STt$TT5z Us   <)
NNNNNNNNNN)rH   rI   rJ   rd   r   rv   rw   rx   ry   r
   rO   ro   rp   rq   rr   rs   rt   r|   r,   r7   r@   r-   r   rm   rm      s    Gt,T*N4(Lt,$4FI$4FI%5$GJ%5$GJ&64HK&64HKgL #' $""&  !!!'Hr-   rm   )r   warningsr   openpyxl.descriptorsr   r   r   r   r   r	   r
   !openpyxl.descriptors.serialisabler   openpyxl.xml.functionsr   openpyxl.utils.escaper   r   FONT_PATTERNCOLOR_PATTERN
SIZE_REGEXr   r0   rB   r    r"   rO   rm   r@   r-   r   <module>r      s   
 
    ; + 2 !+!
rzz-..|]/9; ,L L^Ov Od7< 7r-   