o
    g                     @   s   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 d
eeeZdd ZG dd deZG dd deZG d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                 C   sV   t dt jt jB }|| }z| }W |S  ty*   td dddd}Y |S 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parts r   Z/var/www/html/api-tag/env/lib/python3.10/site-packages/openpyxl/worksheet/header_footer.py_split_string   s   


r   c                   @   sd   e Zd ZdZeddZeddZeddZdZ	e
de	dZdddZd	d
 Zdd Zed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                 C   s   || _ || _|| _|| _d S N)r   fontsizecolor)selfr   r%   r&   r'   r   r   r   __init__]   s   
z_HeaderFooterPart.__init__c                 C   s^   g }| j r|d| j  | jr|d| j | jr&|d| j d|| jg S )zI
        Convert to Excel HeaderFooter miniformat minus position
        z&"{0}"z&{0} z&K{0}r   )r%   appendformatr&   r'   joinr   )r(   fmtr   r   r   __str__d   s   z_HeaderFooterPart.__str__c                 C   s
   t | jS r$   )boolr   r(   r   r   r   __bool__q   s   
z_HeaderFooterPart.__bool__c                    s>   d t  fddt|D }td||d< | di |S )z3
        Convert from miniformat to object
        )r%   r'   r&   c                 3   s0    | ]}t  |D ]\}}|r	||fV  q	qd S r$   )zip).0r   kvkeysr   r   	<genexpr>|   s    z-_HeaderFooterPart.from_str.<locals>.<genexpr>r   r   Nr   )dictFORMAT_REGEXfindallsub)clsr   kwr   r6   r   from_strv   s   z_HeaderFooterPart.from_str)NNNN)__name__
__module____qualname____doc__r   r   r%   r   r&   RGBr   r'   r)   r.   r1   classmethodr?   r   r   r   r   r    5   s    



r    c                   @   sh   e Zd ZdZeedZeedZedZ	eedZ
dZdddZdd	 Zd
d Zdd Zedd ZdS )HeaderFooterItemz 
    Header or footer item

    )expected_typer   )LCRNc                 C   s@   |d u rt  }|| _|d u rt  }|| _|d u rt  }|| _d S r$   )r    r   r   r   )r(   r   r   r   r   r   r   r)      s   
zHeaderFooterItem.__init__c              	      s   ddddddddd	 t d
dd  D } fdd}g }t| j| j| j| jgD ]\}}|jdur@|	d
|t| q,d|}|||}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                 S   s   g | ]
}d  t|qS )z({0}))r+   r   r   )r3   r4   r   r   r   
<listcomp>   s    z,HeaderFooterItem.__str__.<locals>.<listcomp>c                    s   |  d} | S )zn
            Callback for re.sub
            Replace expanded control with mini-format equivalent
            r   )group)r   r<   	TRANSFORMr   r   replace   s   
z)HeaderFooterItem.__str__.<locals>.replaceNz&{0}{1}r   )r   r   r,   r2   _HeaderFooterItem__keysr   r   r   r   r*   r+   strr<   r   )r(   
SUBS_REGEXrP   txtkeypartr   rN   r   r.      s$   


zHeaderFooterItem.__str__c                 C   s   t | j| j| jgS r$   )anyr   r   r   r0   r   r   r   r1      s   zHeaderFooterItem.__bool__c                 C   s   t |}t| |_|S )z$
        Return as XML node
        )r   rR   r   )r(   tagnameelr   r   r   to_tree   s   
zHeaderFooterItem.to_treec                 C   sV   |j r)t|j }t|}| D ]\}}|d urt|||< q| di |}|S d S )Nr   )r   r   r   itemsr    r?   )r=   noder   r   r4   r5   r(   r   r   r   	from_tree   s   
zHeaderFooterItem.from_tree)NNN)r@   rA   rB   rC   r	   r    r   r   r   centrer   rQ   r)   r.   r1   rZ   rE   r]   r   r   r   r   rF      s    



	rF   c                   @   s   e Zd ZdZeddZeddZeddZeddZe	e
ddZe	e
ddZe	e
ddZe	e
ddZe	e
ddZe	e
ddZdZ										dddZd	d
 ZdS )HeaderFooterheaderFooterTr!   )rG   r"   )	oddHeader	oddFooter
evenHeader
evenFooterfirstHeaderfirstFooterNc                 C   s   || _ || _|| _|| _|d u rt }|| _|d u rt }|| _|d u r't }|| _|d u r1t }|| _|	d u r;t }	|	| _	|
d u rEt }
|
| _
d S r$   )differentOddEvendifferentFirstscaleWithDocalignWithMarginsrF   ra   rb   rc   rd   re   rf   )r(   rg   rh   ri   rj   ra   rb   rc   rd   re   rf   r   r   r   r)      s,   
zHeaderFooter.__init__c                    s"    fdd j  j D }t|S )Nc                    s   g | ]}t  |qS r   )getattr)r3   attrr0   r   r   rL     s    z)HeaderFooter.__bool__.<locals>.<listcomp>)	__attrs____elements__rW   )r(   r   r   r0   r   r1     s   zHeaderFooter.__bool__)
NNNNNNNNNN)r@   rA   rB   rX   r   rg   rh   ri   rj   r	   rF   ra   rb   rc   rd   re   rf   rn   r)   r1   r   r   r   r   r_      s2    




$r_   )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   r+   r:   r   r    rF   r_   r   r   r   r   <module>   s    $	OR