
    fh                        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
                    eee                    Zd Z G d de          Z G d de          Z G d de          ZdS )    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            }|                    |           }	 |                                }n%# t          $ r t          d           dddd}Y nw xY w|S )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/histauto/venv/lib/python3.11/site-packages/openpyxl/worksheet/header_footer.py_split_stringr       s      	 *ry
 	" "J 	A5 5 5 5FGGGB445 Ls   A A:9A: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dS )_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                 >    || _         || _        || _        || _        d S N)r   fontsizecolor)selfr   r(   r)   r*   s        r   __init__z_HeaderFooterPart.__init__]   s"    			


    c                 z   g }| j         r-|                    d                    | j                              | j        r-|                    d                    | j                             | j        r-|                    d                    | j                             d                    || 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     9 	4JJy''	223339 	2JJw~~di00111: 	3JJw~~dj11222xxtyk)***r-   c                 *    t          | j                  S r'   )boolr   r+   s    r   __bool__z_HeaderFooterPart.__bool__q   s    DIr-   c                     dt          fdt                              |          D                       }t                              d|          |d<    | di |S )z3
        Convert from miniformat to object
        )r(   r*   r)   c              3   P   K   | ] }t          |          D ]\  }}|||fV  !d S r'   )zip).0r   kvkeyss       r   	<genexpr>z-_HeaderFooterPart.from_str.<locals>.<genexpr>|   sa       5 5U!$..5 5a!51a& 5 5 5 5 5 5 5r-   r   r    )dictFORMAT_REGEXfindallsub)clsr   kwr>   s      @r   from_strz_HeaderFooterPart.from_strv   sy    
 ) 5 5 5 5l&:&:4&@&@ 5 5 5 5 5 "%%b$//6
syyRyyr-   )NNNN)__name__
__module____qualname____doc__r   r   r(   r   r)   RGBr	   r*   r,   r3   r7   classmethodrG   r@   r-   r   r"   r"   5   s         > 6T"""D6T"""D7d###DCLD#66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dS )HeaderFooterItemz 
    Header or footer item

    )expected_typer   )LCRNc                     |t                      }|| _        |t                      }|| _        |t                      }|| _        d S r'   )r"   r   r   r   )r+   r   r   r   s       r   r,   zHeaderFooterItem.__init__   sK    <$&&D	>&((F=%''E


r-   c           	         ddddddddd	t          j        d
                    d D                                 }fd}g }t          | j        | j        | j        | j        g          D ]B\  }}|j        6|	                    d
                    |t          |                               Cd                    |          }|                    ||          }t          |          S )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]|c                 \    g | ])}d                      t          j        |                    *S )z({0}))r0   r   r   )r;   r<   s     r   
<listcomp>z,HeaderFooterItem.__str__.<locals>.<listcomp>   s<     *> *> *>./ +2..1*F*F *> *> *>r-   c                 >    |                      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-   Nz&{0}{1}r   )r   r   r1   r:   _HeaderFooterItem__keysr   r   r   r   r/   r0   strrD   r   )r+   
SUBS_REGEXr\   txtkeypartr[   s         @r   r3   zHeaderFooterItem.__str__   s     $$ $$SW#') )	
 Z *> *>3<*> *> *> !? !? @ @
	" 	" 	" 	" 	" K$)T[$*=? ? 	> 	>ICy$

:,,S#d))<<===ggcllnnWc**c{{r-   c                 D    t          | j        | j        | j        g          S r'   )anyr   r   r   r6   s    r   r7   zHeaderFooterItem.__bool__   s    DIt{DJ7888r-   c                 L    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         rft          |j                   }t          |          }|                                D ]$\  }}|t                              |          ||<   % | di |}|S d S )Nr@   )r   r   r    itemsr"   rG   )rE   noder   r   r<   r=   r+   s          r   	from_treezHeaderFooterItem.from_tree   s    9 	DI&&D!$''E = =1=099!<<E!H3<<<<DK	 	r-   )NNN)rH   rI   rJ   rK   r
   r"   r   r   r   centrer   r]   r,   r3   r7   rh   rM   rl   r@   r-   r   rO   rO      s         
 50111DU!2333FU8__FE 1222EF	 	 	 	  <9 9 9
     [  r-   rO   c                   4   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dS )
HeaderFooterheaderFooterTr#   )rP   r$   )	oddHeader	oddFooter
evenHeader
evenFooterfirstHeaderfirstFooterNc                 R   || _         || _        || _        || _        |t	                      }|| _        |t	                      }|| _        |t	                      }|| _        |t	                      }|| _        |	t	                      }	|	| _	        |
t	                      }
|
| _
        d S r'   )differentOddEvendifferentFirstscaleWithDocalignWithMarginsrO   rq   rr   rs   rt   ru   rv   )r+   rx   ry   rz   r{   rq   rr   rs   rt   ru   rv   s              r   r,   zHeaderFooter.__init__   s     !1,( 0(**I"(**I")++J$)++J$*,,K&*,,K&r-   c                 X      fd j          j        z   D             }t          |          S )Nc                 0    g | ]}t          |          S r@   )getattr)r;   attrr+   s     r   rX   z)HeaderFooter.__bool__.<locals>.<listcomp>  s#    TTTt$$TTTr-   )	__attrs____elements__rd   )r+   r   s   ` r   r7   zHeaderFooter.__bool__  s2    TTTT$BS1STTT5zzr-   )
NNNNNNNNNN)rH   rI   rJ   rf   r   rx   ry   rz   r{   r
   rO   rq   rr   rs   rt   ru   rv   r   r,   r7   r@   r-   r   ro   ro      s*       Gtt,,,TT***N44(((Ltt,,,$4FFFI$4FFFI%5$GGGJ%5$GGGJ%&64HHHK%&64HHHKgL #' $""&  !!!' !' !' !'H    r-   ro   )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   ro   r@   r-   r   <module>r      s  
 
			                        ; : : : : : + * * * * * 2 2 2 2 2 2 2 2 !+!
rz-..|]/9; ;    ,L L L L L L L L^O O O O Ov O O Od7 7 7 7 7< 7 7 7 7 7r-   