U o^@sddlZddlmZddlmZmZmZmZmZm Z m Z ddl m Z ddl mZddlmZmZdZdZd Zed eeeZd d ZGd ddeZGdddeZGddde ZdS)N)warn)AliasBoolStrictStringInteger MatchPatternTyped) Serialisable)Element)escapeunescapez&"(?P.+)"z&K(?P[A-F0-9]{6})z&(?P\d+\s?)z {0}|{1}|{2}cCsXtdtjtjB}||}z |}Wn(tk rRtddddd}YnX|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.+?))? (&C(?P
.+?))? (&R(?P.+?))? $z3Cannot parse header or footer so it will be ignored)leftrightcenter)recompileVERBOSEDOTALLmatch groupdictAttributeErrorr)textZ ITEM_REGEXmpartsrz/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/openpyxl/openpyxl/worksheet/header_footer.py _split_strings   rc@sheZdZdZeddZeddZeddZdZ e de dZ dddZ d d Z d d ZeZed dZdS)_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!patternNcCs||_||_||_||_dSN)rfontsizecolor)selfrr$r%r&rrr__init__]sz_HeaderFooterPart.__init__cCs^g}|jr|d|j|jr4|d|j|jrL|d|jd||jgS)zI Convert to Excel HeaderFooter miniformat minus position z&"{0}"z&{0} z&K{0}r)r$appendformatr%r&joinr)r'fmtrrr__str__dsz_HeaderFooterPart.__str__cCs t|jSr#)boolrr'rrr__bool__qsz_HeaderFooterPart.__bool__cs:dtfddt|D}td||d<|f|S)z3 Convert from miniformat to object )r$r&r%c3s.|]&}t|D]\}}|r||fVqqdSr#)zip).0rkvkeysrr }s  z-_HeaderFooterPart.from_str..rr)dict FORMAT_REGEXfindallsub)clsrkwrr5rfrom_strwsz_HeaderFooterPart.from_str)NNNN)__name__ __module__ __qualname____doc__rrr$rr%ZRGBrr&r(r-r0 __nonzero__ classmethodr>rrrrr5s      rc@sleZdZdZeedZeedZedZ eedZ dZ dddZ dd Z d d ZeZd d ZeddZdS)HeaderFooterItemz Header or footer item ) expected_typer)LCRNcCs@|dkrt}||_|dkr"t}||_|dkr6t}||_dSr#)rrrr)r'rrrrrrr(szHeaderFooterItem.__init__c sddddddddd td d d D}fd d}g}t|j|j|j|jgD](\}}|jdk rX| d |t |qXd|}| ||}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]|cSsg|]}dt|qS)z({0}))r*rr )r2r3rrr sz,HeaderFooterItem.__str__..cs|d}|S)zn Callback for re.sub Replace expanded control with mini-format equivalent r)group)rr;Z TRANSFORMrrreplaces z)HeaderFooterItem.__str__..replaceNz&{0}{1}r)rrr+r1_HeaderFooterItem__keysrrrrr)r*strr;r )r'Z SUBS_REGEXrNtxtkeypartrrMrr-s*      zHeaderFooterItem.__str__cCst|j|j|jgSr#)anyrrrr/rrrr0szHeaderFooterItem.__bool__cCst|}t||_|S)z$ Return as XML node )r rPr)r'tagnameelrrrto_trees zHeaderFooterItem.to_treecCsR|jrNt|j}t|}|D]\}}|dk r t|||<q |f|}|SdSr#)rr ritemsrr>)r<noderrr3r4r'rrr from_trees  zHeaderFooterItem.from_tree)NNN)r?r@rArBr rrrrZcentrerrOr(r-r0rCrWrDrZrrrrrEs     rEc @seZdZdZeddZeddZeddZeddZe e ddZ e e ddZ e e ddZ e e ddZe e ddZe e ddZdZd ddZd d ZeZdS) HeaderFooterZ headerFooterTr )rFr!) oddHeader oddFooter evenHeader evenFooter firstHeader firstFooterNc Cs||_||_||_||_|dkr&t}||_|dkr:t}||_|dkrNt}||_|dkrbt}||_| dkrvt} | |_ | dkrt} | |_ dSr#) differentOddEvendifferentFirst scaleWithDocalignWithMarginsrEr\r]r^r_r`ra) r'rbrcrdrer\r]r^r_r`rarrrr(s, zHeaderFooter.__init__cs"fddjjD}t|S)Ncsg|]}t|qSr)getattr)r2attrr/rrrKsz)HeaderFooter.__bool__..) __attrs__ __elements__rT)r'rrr/rr0 szHeaderFooter.__bool__) NNNNNNNNNN)r?r@rArUrrbrcrdrer rEr\r]r^r_r`rarir(r0rCrrrrr[s2           $r[)rwarningsrZopenpyxl.descriptorsrrrrrrr Z!openpyxl.descriptors.serialisabler Zopenpyxl.xml.functionsr Zopenpyxl.utils.escaper r Z FONT_PATTERNZ COLOR_PATTERNZ SIZE_REGEXrr*r9rrrEr[rrrrs $   PS