U
    >Ke\                     @   sF  d dl mZ ddlmZ ddlmZmZmZ ddlm	Z	m
Z
 dZG dd deZe ZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZddddd d d d dZd dddddddddddddd Zd ddd!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1Zd2Zi Ze D ]>Ze \ZZeed Zeee< d3ekreee d3d4< q[[[[d5d6 Z!d7Z"e#e"d8kst$d d dddddddddddddddd9d:d;d<Z%d=d> Z&dud@dAZ'e'Z(dBdC Z)dDdE Z*dFd dddGdHdIdId ddddddddddJ
ed:dKd0d dLe*gdMedNdNd ddddddOdPedQdReedgeedgeedgeedgeedgee(gee(gee(gee(gee(gdSdTdUdVdWeedXeedYdYdYee)gd dddZd dddddd[ed\ee&eeeed dd]dd^d_gd`dadadbdbe%ed;gdaee(gdbee(gdc	eedddeZ+dvdgdhZ,dwdmdnZ-dxdqdrZ.dydsdtZ/dpS )z    )print_function   )
Formatting)NumberFormatRecordXFRecordStyleRecord)
basestringxrange   c                   @   s   e Zd Zdd ZdS )XFStylec                 C   s<   d| _ t | _t | _t | _t | _	t
 | _d S )NZGeneral)num_format_strr   FontfontZ	Alignment	alignmentZBordersbordersPatternpatternZ
Protection
protectionself r   ./tmp/pip-unpacked-wheel-x1drl5t4/xlwt/Style.py__init__   s    



zXFStyle.__init__N)__name__
__module____qualname__r   r   r   r   r   r   
   s   r   c                $   @   s   e Zd Zddddddddd	d
dddddddddddddddddddddd d!d"d#d$g$Zd;d&d'Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Z	d2d3 Z
d4d5 Zd6d7 Zd8d9 Zd:S )<StyleCollectiongeneral0z0.00z#,##0z#,##0.00z"$"#,##0_);("$"#,##0)z"$"#,##0_);[Red]("$"#,##0)z"$"#,##0.00_);("$"#,##0.00)z "$"#,##0.00_);[Red]("$"#,##0.00)z0%z0.00%z0.00E+00z# ?/?z# ??/??zM/D/YYzD-MMM-YYzD-MMMzMMM-YYz
h:mm AM/PMzh:mm:ss AM/PMzh:mmzh:mm:sszM/D/YY h:mmz_(#,##0_);(#,##0)z_(#,##0_);[Red](#,##0)z_(#,##0.00_);(#,##0.00)z_(#,##0.00_);[Red](#,##0.00)z0_("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)z'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)z8_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)z/_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)zmm:ssz	[h]:mm:sszmm:ss.0z##0.0E+0@r   c                 C   s   || _ ddddddg| _i | _i | _i | _dD ]2}t }| }|| j|< || j|< || j|< q.i | _i | _	i | _
i | _ttddtjdd D ]\}}|| j|< qttddtjdd  D ]\}}|| j|< qt | _| | jd | _d S )Nr   )r   r               %   2   )style_compressionstats
_font_id2x
_font_x2id_font_val2xr   r   _search_key_xf_id2x_xf_x2id	_xf_val2x_num_formatszipranger   _std_num_fmt_listr   default_style
_add_style_default_xf)r   r&   xr   
search_keyfmtidxfmtstrr   r   r   r   >   s*    

""zStyleCollection.__init__c                 C   s   |d krdS |  |d S )N   r   )r4   )r   styler   r   r   addY   s    zStyleCollection.addc                 C   s>  |j }|| jkr| j| }n"tt| j ttj }|| j|< |j}|| jkrl| j| }| jd  d7  < n| j	r|
 }| j|}|d k	r|| j|< | jd  d7  < n>t| jd }|| j|< || j|< || j|< | jd  d7  < n*t| jd }|| j|< | jd  d7  < |j|j|j|jf}||f| }|| jkr`| j| }	| jd  d7  < n| j	dkr||ftdd |D  }
| j|
}	|	d k	r|	| j|< | jd  d7  < n>dt| j }	|	| j|< |	| j|
< || j|	< | jd	  d7  < n*dt| j }	|	| j|< | jd	  d7  < |	d
kr6td||	fS )Nr   r   r    r!   c                 s   s   | ]}|  V  qd S N)r+   ).0objr   r   r   	<genexpr>   s     z-StyleCollection._add_style.<locals>.<genexpr>   r:   r"   i  zMore than 4094 XFs (styles))r   r/   !FIRST_USER_DEFINED_NUM_FORMAT_IDXlenr   r2   r   r(   r'   r&   r+   r*   getr)   r   r   r   r   r,   tupler.   r-   
ValueError)r   r;   r   Znum_format_idxr   font_idxr7   ZgofxfZxf_indexZxf_keyr   r   r   r4   ^   sd    
















zStyleCollection._add_stylec                 C   s
   |  |S r=   )	_add_font)r   r   r   r   r   add_font   s    zStyleCollection.add_fontc                 C   s   || j kr(| j | }| jd  d7  < n| jr| }| j|}|d k	rh|| j |< | jd  d7  < qt| jd }|| j |< || j|< || j|< | jd  d7  < n*t| j d }|| j |< | jd  d7  < |S )Nr   r   r    )r(   r'   r&   r+   r*   rD   rC   r)   )r   r   rG   r7   r   r   r   rI      s$    






zStyleCollection._add_fontc                 C   s8   d}||   7 }||  7 }||  7 }||  7 }|S )N    )
_all_fonts_all_num_formats_all_cell_styles_all_styles)r   resultr   r   r   get_biff_data   s    zStyleCollection.get_biff_datac                 C   sP   d}| j r| j }ndd | j D }t|D ]\}}||  7 }q2|S )NrK   c                 S   s   g | ]\}}||fqS r   r   r>   or6   r   r   r   
<listcomp>   s     z.StyleCollection._all_fonts.<locals>.<listcomp>)r&   r)   itemsr(   sortedZget_biff_recordrD   )r   rP   ZfontsrG   r   r   r   r   rL      s    zStyleCollection._all_fontsc                 C   sD   d}dd | j  D }|  |D ]\}}|t|| 7 }q$|S )NrK   c                 S   s    g | ]\}}|t kr||fqS r   )rB   )r>   kvr   r   r   rT      s   z4StyleCollection._all_num_formats.<locals>.<listcomp>)r/   rU   sortr   rD   )r   rP   alistr8   r9   r   r   r   rM      s    z StyleCollection._all_num_formatsc                 C   sx   d}t ddD ]}|t| jd 7 }q| jdkr>| j }ndd | j D }t|D ]\}}|t| 7 }qZ|S )NrK   r   r:   r;   r    c                 S   s   g | ]\}}||fqS r   r   rR   r   r   r   rT      s     z4StyleCollection._all_cell_styles.<locals>.<listcomp>)	r1   r   r5   rD   r&   r-   rU   r,   rV   )r   rP   iZstylesZxf_idxrH   r   r   r   rN      s    
z StyleCollection._all_cell_stylesc                 C   s
   t   S r=   )r   rD   r   r   r   r   rO      s    zStyleCollection._all_stylesN)r   )r   r   r   r2   r   r<   r4   rJ   rI   rQ   rL   rM   rN   rO   r   r   r   r   r      s^   '
=
r   c                   @   s   e Zd ZdS )EasyXFExceptionNr   r   r   r   r   r   r   r\      s   r\   c                   @   s   e Zd ZdS )EasyXFCallerErrorNr]   r   r   r   r   r^      s   r^   c                   @   s   e Zd ZdS )EasyXFAuthorErrorNr]   r   r   r   r   r_      s   r_   c                   @   s   e Zd Zdd Zdd ZdS )IntULimc                 C   s
   || _ d S r=   )limit)r   ra   r   r   r   r      s    zIntULim.__init__c                 C   sF   zt |d}W n tk
r$   Y d S X d|  kr<| jksBn d S |S Nr   )intrF   ra   )r   Zastringvaluer   r   r   __call__   s    zIntULim.__call__N)r   r   r   r   re   r   r   r   r   r`      s   r`   )1yestrueonr   nofalseoffr    r!   rA   r"            	   
            )Zno_lineZthinZmediumZdashedZdottedZthickdoubleZhairZmedium_dashedZthin_dash_dottedZmedium_dash_dottedZthin_dash_dot_dottedZmedium_dash_dot_dottedZslanted_medium_dash_dottedM                                                )Z
ansi_latinZsys_defaultsymbolZapple_romanZansi_jap_shift_jisZansi_kor_hangulZansi_kor_johabZansi_chinese_gbkZansi_chinese_big5Z
ansi_greekZansi_turkishZansi_vietnameseZansi_hebrewZansi_arabicZansi_balticZansi_cyrillicZ	ansi_thaiZansi_latin_iiZoem_latin_ia  aqua 0x31
black 0x08
blue 0x0C
blue_gray 0x36
bright_green 0x0B
brown 0x3C
coral 0x1D
cyan_ega 0x0F
dark_blue 0x12
dark_blue_ega 0x12
dark_green 0x3A
dark_green_ega 0x11
dark_purple 0x1C
dark_red 0x10
dark_red_ega 0x10
dark_teal 0x38
dark_yellow 0x13
gold 0x33
gray_ega 0x17
gray25 0x16
gray40 0x37
gray50 0x17
gray80 0x3F
green 0x11
ice_blue 0x1F
indigo 0x3E
ivory 0x1A
lavender 0x2E
light_blue 0x30
light_green 0x2A
light_orange 0x34
light_turquoise 0x29
light_yellow 0x2B
lime 0x32
magenta_ega 0x0E
ocean_blue 0x1E
olive_ega 0x13
olive_green 0x3B
orange 0x35
pale_blue 0x2C
periwinkle 0x18
pink 0x0E
plum 0x3D
purple_ega 0x14
red 0x0A
rose 0x2D
sea_green 0x39
silver_ega 0x16
sky_blue 0x28
tan 0x2F
teal 0x15
teal_ega 0x15
turquoise 0x0F
violet 0x14
white 0x09
yellow 0x0DZgrayZgreyc                 C   s.   d|  krdks"n t d| |t| < d S )Nro   ?   z9add_palette_colour: colour_index (%d) not in range(8, 64))	Exception
colour_map)Z
colour_strcolour_indexr   r   r   add_palette_colourv  s
    r   )8r   l     l      ~ i                ~           i      l                l    @ l      l    33     ff2 l    L      i f fl      i f l     r   r   r   r   r   r   r   r   i  r   l    L l     l    3 l    L3 l    3 l     i f3i 3l     3 l      l     2 l     ~ i ffl    -- i f3 i f3i  3 i  33l     f2 r   i 33i 3338         r:   )Zno_fillnoneZsolidZ
solid_fillZsolid_patternZ	fine_dotsZalt_barsZsparse_dotsZthick_horz_bandsZthick_vert_bandsZthick_backward_diagZthick_forward_diagZ	big_spotsZbricksZthin_horz_bandsZthin_vert_bandsZthin_backward_diagZthin_forward_diagZsquaresZdiamondsc                 C   s   |   S r=   )stripsr   r   r   any_str_func  s    r      c                 C   sD   zt | d}W n tk
r$   Y d S X d|  kr:|ks@n d S |S rb   )rc   rF   )r   maxvalrd   r   r   r   colour_index_func  s    r   c                 C   s   t | ddS )Ni  )r   )r   r   r   r   r   colour_index_func_15  s    r   c                 C   s\   zt | d}W n tk
r$   Y d S X d|  kr:dksHn td| |dk rXd| }|S )Nr   iZ   z)rotation %d: should be -90 to +90 degrees)rc   rF   r^   )r   rd   r   r   r   rotation_func  s    r   r   )r   lrZrldirehorz)
r   leftcentercentrerightZfilled	justifiedZcenter_across_selectionZcentre_across_selectiondistributedinde)Zstackedr   rotashri)topr   r   bottomr   r   vert)r   	directionZhorizZ
horizontalr   r   indentr   Zrotationr   shrinkZshrink_to_fitr   Zverticalwrapr   
top_colourbottom_colourleft_colourright_colourdiag_colour)r   r   r   r   Zdiagr   r   r   r   r   Z	top_colorZbottom_colorZ
left_colorZright_colorZ
diag_colorZ
need_diag1Z
need_diag2r   )r   ZsuperscriptZ	subscript)r   ZromanZswissZmodernscriptZ
decorativei  !   "   )r   ZsingleZ
single_accru   Z
double_acc)ZboldcharsetcolorZcolor_indexZcolourr   Z
escapementfamilyheightZitalicnameoutlineZshadowZ
struck_outZ	underlinepattern_back_colourpattern_fore_colour)	Z
back_colorZback_colourZ
fore_colorZfore_colourr   Zpattern_back_colorr   Zpattern_fore_colorr   )Zcell_lockedZformula_hidden)Zalignr   Zborderr   r   r   r   \c                 C   sd   d}dg}| D ]P}|r,|d  |7  < d}q||kr:d}q||krN| d q|d  |7  < q|S )NF T)append)r   Z
split_charesc_charescapedZolistcr   r   r   _esplita  s    r   ,;:Fc              
   C   s  t | ||D ]}| }|s$ qt |||}	t|	dkrLtd||f |	\}
}|
  }
tdD ]V}||
}|d krtd|
 t|tr qt|t	st
d|
t|f |
}|}
qht
d||f |}t||
d }|d krt
d|jj|
f t |||D ]}| }|s q|d  dd	}d
|dd  }|s\td|
|f tdD ]D}||}|d krtd|
|f t|ts q|}|}qdt
d||f |}t|ts|g}|D ]p}t|tr| dd	}||krB|| } qXn4t|r2||}|d k	rB qXnt
d||f qtd||
|f zt||}W n& tk
r   t
d|
|f Y nX |rtd|
||||f  t||| qqd S )Nr    z"line %r should have exactly 1 "%c"zsection %r is unknownz5section %r should map to dict or str object; found %rz-Attempt to define synonym of synonym (%r: %r)z.instance of %s class has no attribute named %sr   -_ r   zno value supplied for %s.%sz%s.%s is not a known attributez'unknown value rule for attribute %r: %rzunexpected value %r for %s.%sz.%s.%s in dictionary but not in supplied objectz+++ %s.%s = %r # %s; was %r)r   r   rC   r^   lowerr1   rD   
isinstancedictstrr_   typegetattr	__class__r   splitreplacejoinr	   r   listcallableAttributeErrorprintsetattr)strgr?   Z
parse_dict	field_sepline_sep	intro_sepr   debuglineZ
split_linesectionZitem_strcounterrP   Zold_sectionZsection_dictZsection_objZkv_strZguffrW   rX   Zold_kZ
value_infoZ
value_ruleZvlrd   origr   r   r   _parse_strg_to_objp  s    







 r   r   Nc              
   C   s4   t  }|dk	r||_| r0t| |t|||||d |S )a  
    This function is used to create and configure
    :class:`XFStyle` objects for use with (for example) the
    :meth:`Worksheet.write` method.

    It takes a string to be parsed to obtain attribute values for
    :class:`Alignment`, :class:`Borders`, :class:`Font`, :class:`Pattern` and
    :class:`Protection` objects.

    Refer to the examples in the file `examples/xlwt_easyxf_simple_demo.py`
    and to the `xf_dict` dictionary in :mod:`xlwt.Style`.

    Various synonyms including color/colour, center/centre and gray/grey are
    allowed. Case is irrelevant (except maybe in font names). ``-`` may be used
    instead of ``_``.

    Example: ``font: bold on; align: wrap on, vert centre, horiz center``

    :param num_format_str:

      To get the "number format string" of an existing
      cell whose format you want to reproduce, select the cell and click on
      Format/Cells/Number/Custom. Otherwise, refer to Excel help.

      Examples: ``"#,##0.00"``, ``"dd/mm/yyyy"``

    :return: An :class:`XFstyle` object.

    Nr   r   r   r   r   )r   r   r   xf_dict)strg_to_parser   r   r   r   r   r   xfobjr   r   r   easyxf  s        r   c              
   C   s,   t  }| r&td|  |t|dd||d |jS )Nzfont: r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   r   easyfont  s        r   )r   )r   )r   r   r   r   F)r   Nr   r   r   r   F)r   r   r   F)0
__future__r   r   r   ZBIFFRecordsr   r   r   compatr   r	   rB   objectr   r3   r   r   r\   r^   r_   r`   Zbool_mapZborder_line_mapZcharset_mapZ_colour_map_textr   
splitlines_liner   _nameZ_numrc   r   r   Zexcel_default_palette_b8rC   AssertionErrorZpattern_mapr   r   Zcolour_index_func_7r   r   r   r   r   r   r   r   r   r   r   <module>   s  
 P      	:

:
	'






_
         
I          
'