U
    d
                     @   sl   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
e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-rwywncvq/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   objectr'   r   r   r   r   <module>   s   &