o
    �?ƒZ9  ã                   @   sÞ   d dl mZ d dlmZ d dlmZ d dlm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mZ d d	lmZmZmZ d d
lmZ ddd„Zdd„ Zddlm Z  G dd„ de	ƒZ!G dd„ de	ƒZ"dS )é    )Úabsolute_import)Údefaultdict)Úchain)Ú
itemgetter)ÚSerialisable)ÚBoolÚNoneSetÚStringÚSequenceÚAliasÚIntegerÚConvertible)Ú
NestedText)Úsafe_stringÚunicode)Úrows_from_rangeÚcoordinate_to_tupleÚget_column_letter)ÚCell© c           	      C   s    t |ƒ}dd„ | D ƒ}tt ƒ}t|tdƒd�D ]\}}||  |¡ q| ¡ D ]#\}} t|ƒ}d}t| ƒdkr9d}| |t	| ƒ|t
| ƒ¡}| |¡ q'd |¡S )ax   Collapse a collection of cell co-ordinates down into an optimal
        range or collection of ranges.

        E.g. Cells A1, A2, A3, B1, B2 and B3 should have the data-validation
        object applied, attempt to collapse down to a single range, A1:B3.

        Currently only collapsing contiguous vertical ranges (i.e. above
        example results in A1:A3 B1:B3).
    c                 s   s   � | ]}t |ƒV  qd S ©N)r   )Ú.0Úcellr   r   úS/var/www/html/env/lib/python3.10/site-packages/openpyxl/worksheet/datavalidation.pyÚ	<genexpr>-   s   € z*collapse_cell_addresses.<locals>.<genexpr>é   )Úkeyz{0}{1}:{2}{3}z{0}{1}ú )Úlistr   Úsortedr   ÚappendÚitemsr   ÚlenÚformatÚminÚmaxÚjoin)	ÚcellsÚinput_rangesÚrangesÚ
raw_coordsÚgrouped_coordsÚrowÚcolÚfmtÚrr   r   r   Úcollapse_cell_addresses   s   
r0   c                 C   s.   g }|   ¡ D ]	}| t|ƒ¡ qtt |¡ƒS )z’
    Expand cell ranges to a sequence of addresses.
    Reverse of collapse_cell_addresses
    Eg. converts "A1:A2 B1:B2" to (A1, A2, B1, B2)
    )ÚsplitÚextendr   Úsetr   Úfrom_iterable)Úrange_stringr'   Úrsr   r   r   Úexpand_cell_ranges@   s   r7   r   )ÚMultiCellRangec                   @   s  e Zd ZdZeed�ZedƒZedƒZ	e
ƒ Ze
dd�ZedƒZe
ƒ Ze
ƒ Ze
ƒ ZedƒZedd�Zedd�Zedd�Zedd�Zeded�Zeded�Zed	d
�Zedd
�Zedd
�Zedd
�ZedƒZ																ddd„Z dd„ Z!dd„ Z"dS )ÚDataValidationÚdataValidation©Úexpected_typeÚsqrefT©Ú
allow_noneÚshowDropDownÚ
allowBlank)r?   r<   )ÚwholeÚdecimalr   ÚdateÚtimeÚ
textLengthÚcustom)Úvalues)ÚstopÚwarningÚinformation)Ú	noControlÚoffÚonÚdisabledÚhiraganaÚfullKatakanaÚhalfKatakanaÚ	fullAlphaÚ	halfAlphaÚ
fullHangulÚ
halfHangul)ÚbetweenÚ
notBetweenÚequalÚnotEqualÚlessThanÚlessThanOrEqualÚgreaterThanÚgreaterThanOrEqualÚtypeNFr   c                 C   sj   |	| _ || _|| _|| _|| _|| _|d ur|}|| _|| _|| _|| _	|
| _
|| _|| _|| _|| _d S r   )r=   r@   ÚimeModeÚoperatorÚformula1Úformula2rA   ÚshowErrorMessageÚshowInputMessager_   ÚpromptTitleÚ
errorStyleÚerrorÚpromptÚ
errorTitle)Úselfr_   rb   rc   Úallow_blankrd   re   r@   rA   r=   rf   rg   rh   ri   rj   r`   ra   r   r   r   Ú__init__p   s"   
zDataValidation.__init__c                 C   s"   t |dƒr|j}|  j|7  _dS )z0Adds a cell or cell coordinate to this validatorÚ
coordinateN©Úhasattrrn   r=   ©rk   r   r   r   r   Úadd•   s   
zDataValidation.addc                 C   s   t |dƒr|j}|| jv S )Nrn   ro   rq   r   r   r   Ú__contains__œ   s   

zDataValidation.__contains__)NNNFTTNNr   NNNNNNN)#Ú__name__Ú
__module__Ú__qualname__Útagnamer   r8   r=   r   r'   r)   r   rd   r@   Úhide_drop_downre   rA   rl   r	   rj   rh   rf   ri   r   r   rb   rc   r   r_   rg   r`   ra   Úvalidation_typerm   rr   rs   r   r   r   r   r9   O   sT    










ð%r9   c                       s‚   e Zd ZdZedd�Zedd�Zedd�Ze	e
d�ZdZdZ					dd	d
„Zedd„ ƒZdd„ Zdd„ Zd‡ fdd„	Z‡  ZS )ÚDataValidationListÚdataValidationsTr>   r;   )r:   )ÚdisablePromptsÚxWindowÚyWindowÚcountNr   c                 C   s   || _ || _|| _|| _d S r   )r|   r}   r~   r:   )rk   r|   r}   r~   r   r:   r   r   r   rm   ®   s   
zDataValidationList.__init__c                 C   s   t | ƒS r   )r"   ©rk   r   r   r   r   »   s   zDataValidationList.countc                 C   s
   t | jƒS r   )r"   r:   r€   r   r   r   Ú__len__À   s   
zDataValidationList.__len__c                 C   s   | j  |¡ d S r   )r:   r    )rk   Údvr   r   r   r    Ä   s   zDataValidationList.appendc                    s2   | j }dd„ | j D ƒ| _ tt| ƒ |¡}|| _ |S )zC
        Need to skip validations that have no cell ranges
        c                 S   s   g | ]	}t |jƒr|‘qS r   )Úboolr=   )r   r/   r   r   r   Ú
<listcomp>Í   s    z.DataValidationList.to_tree.<locals>.<listcomp>)r:   Úsuperrz   Úto_tree)rk   rw   r)   Úxml©Ú	__class__r   r   r†   È   s
   zDataValidationList.to_tree)NNNNr   r   )rt   ru   rv   rw   r   r|   r   r}   r~   r
   r9   r:   Ú__elements__Ú	__attrs__rm   Úpropertyr   r�   r    r†   Ú__classcell__r   r   rˆ   r   rz   ¢   s&    




û
rz   N)r   )#Ú
__future__r   Úcollectionsr   Ú	itertoolsr   ra   r   Ú!openpyxl.descriptors.serialisabler   Úopenpyxl.descriptorsr   r   r	   r
   r   r   r   Úopenpyxl.descriptors.nestedr   Úopenpyxl.compatr   r   Úopenpyxl.utilsr   r   r   Úopenpyxl.cellr   r0   r7   Ú
cell_ranger8   r9   rz   r   r   r   r   Ú<module>   s    $	
!S