o
    ϩZh                     @   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   )textZ
ITEM_REGEXmparts r   W/var/www/html/lang_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   r5   r   from_strv   s   z_HeaderFooterPart.from_str)NNNN)__name__
__module____qualname____doc__r   r   r$   r   r%   RGBr   r&   r(   r-   r0   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   )r2   r3   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;   Z	TRANSFORMr   r   replace   s   
z)HeaderFooterItem.__str__.<locals>.replaceNz&{0}{1}r   )r   r   r+   r1   _HeaderFooterItem__keysr   r   r   r   r)   r*   strr;   r   )r'   Z
SUBS_REGEXrN   txtkeypartr   rM   r   r-      s$   


zHeaderFooterItem.__str__c                 C   s   t | j| j| jgS r#   )anyr   r   r   r/   r   r   r   r0      s   zHeaderFooterItem.__bool__c                 C   s   t |}t| |_|S )z$
        Return as XML node
        )r   rP   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   r3   r4   r'   r   r   r   	from_tree   s   
zHeaderFooterItem.from_tree)NNN)r?   r@   rA   rB   r	   r   r   r   r   Zcentrer   rO   r(   r-   r0   rW   rD   rZ   r   r   r   r   rE      s    



	rE   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 )HeaderFooterZheaderFooterTr    )rF   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alignWithMarginsrE   r\   r]   r^   r_   r`   ra   )r'   rb   rc   rd   re   r\   r]   r^   r_   r`   ra   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)r2   attrr/   r   r   rK     s    z)HeaderFooter.__bool__.<locals>.<listcomp>)	__attrs____elements__rT   )r'   r   r   r/   r   r0     s   zHeaderFooter.__bool__)
NNNNNNNNNN)r?   r@   rA   rU   r   rb   rc   rd   re   r	   rE   r\   r]   r^   r_   r`   ra   ri   r(   r0   r   r   r   r   r[      s2    




$r[   )r   warningsr   Zopenpyxl.descriptorsr   r   r   r   r   r   r	   Z!openpyxl.descriptors.serialisabler
   Zopenpyxl.xml.functionsr   Zopenpyxl.utils.escaper   r   ZFONT_PATTERNZCOLOR_PATTERNZ
SIZE_REGEXr   r*   r9   r   r   rE   r[   r   r   r   r   <module>   s    $	OR