U
    .R”i�
  ã                   @   sj   d dl mZ d dlmZmZmZmZ d dlmZ ddl	m
Z
 d dlmZ G dd„ deƒZG d	d
„ d
ƒZdS )é    )ÚOrderedDict)ÚBoolÚSequenceÚAliasÚConvertible)ÚSerialisableé   )ÚRule)ÚMultiCellRangec                   @   sh   e Zd ZdZeed�ZedƒZe	dd�Z
eed�ZedƒZdd	d
„Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚConditionalFormattingZconditionalFormatting)Zexpected_typeÚsqrefT)Ú
allow_noneÚcfRule© Nc                 C   s   || _ || _|| _d S ©N)r   Úpivotr   )Úselfr   r   r   ZextLstr   r   úB/tmp/pip-unpacked-wheel-r0v169r1/openpyxl/formatting/formatting.pyÚ__init__   s    zConditionalFormatting.__init__c                 C   s   t || jƒsdS | j|jkS )NF)Ú
isinstanceÚ	__class__r   )r   Úotherr   r   r   Ú__eq__"   s    zConditionalFormatting.__eq__c                 C   s
   t | jƒS r   )Úhashr   ©r   r   r   r   Ú__hash__(   s    zConditionalFormatting.__hash__c                 C   s   dj | jj| jd�S )Nz<{cls} {cells}>)ÚclsÚcells)Úformatr   Ú__name__r   r   r   r   r   Ú__repr__,   s    zConditionalFormatting.__repr__c                 C   s
   || j kS )zL
        Check whether a certain cell is affected by the formatting
        ©r   )r   Zcoordr   r   r   Ú__contains__0   s    z"ConditionalFormatting.__contains__)r   Nr   N)r   Ú
__module__Ú__qualname__Útagnamer   r
   r   r   r   r   r   r   r	   r   Úrulesr   r   r   r    r"   r   r   r   r   r      s   



r   c                   @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚConditionalFormattingListzConditional formatting rules.c                 C   s   t ƒ | _d| _d S )Nr   )r   Ú	_cf_rulesÚmax_priorityr   r   r   r   r   ;   s    z"ConditionalFormattingList.__init__c                 C   s`   |}t |tƒrt|ƒ}t |tƒs(tdƒ‚|}|  jd7  _|jsH| j|_| j |g ¡ 	|¡ dS )zyAdd a rule such as ColorScaleRule, FormulaRule or CellIsRule

         The priority will be added automatically.
        z<Only instances of openpyxl.formatting.rule.Rule may be addedr   N)
r   Ústrr   r	   Ú
ValueErrorr)   Úpriorityr(   Ú
setdefaultÚappend)r   Zrange_stringr   ÚcfÚruler   r   r   Úadd@   s    

zConditionalFormattingList.addc                 C   s
   t | jƒS r   )Úboolr(   r   r   r   r   Ú__bool__R   s    z"ConditionalFormattingList.__bool__c                 C   s
   t | jƒS r   )Úlenr(   r   r   r   r   Ú__len__V   s    z!ConditionalFormattingList.__len__c                 c   s$   | j  ¡ D ]\}}||_|V  q
d S r   )r(   Úitemsr&   )r   r/   r&   r   r   r   Ú__iter__Z   s    z"ConditionalFormattingList.__iter__c                 C   s   t |tƒrt|d�}| j| S )z0
        Get the rules for a cell range
        r!   )r   r*   r   r(   ©r   Úkeyr   r   r   Ú__getitem__`   s    

z%ConditionalFormattingList.__getitem__c                 C   s   t |d�}| j|= d S )Nr!   )r   r(   r8   r   r   r   Ú__delitem__i   s    
z%ConditionalFormattingList.__delitem__c                 C   s   |   ||¡ dS )z-
        Add a rule for a cell range
        N)r1   )r   r9   r0   r   r   r   Ú__setitem__n   s    z%ConditionalFormattingList.__setitem__N)r   r#   r$   Ú__doc__r   r1   r3   r5   r7   r:   r;   r<   r   r   r   r   r'   7   s   	r'   N)Úcollectionsr   Zopenpyxl.descriptorsr   r   r   r   Z!openpyxl.descriptors.serialisabler   r0   r	   Zopenpyxl.worksheet.cell_ranger
   r   r'   r   r   r   r   Ú<module>   s   &