o
    ðäjó  ã                   @   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	m
Z
mZmZmZmZmZ d dlmZ d dlmZmZ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 )é    )Údefaultdict©Úchain)Ú
itemgetter)ÚSerialisable)ÚBoolÚNoneSetÚStringÚSequenceÚAliasÚIntegerÚConvertible)Ú
NestedText)Úrows_from_rangeÚcoordinate_to_tupleÚget_column_letter© 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   ó   � | ]}t |ƒV  qd S ©N)r   )Ú.0Úcellr   r   úe/var/www/ticemtrilhas/avaliacao_env/lib/python3.10/site-packages/openpyxl/worksheet/datavalidation.pyÚ	<genexpr>(   ó   € 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   
r/   c                 C   s,   dd„ |   ¡ D ƒ}dd„ |D ƒ}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)
    c                 s   r   r   )r   )r   Úrsr   r   r   r   B   r   z%expand_cell_ranges.<locals>.<genexpr>c                 s   s   � | ]}t |Ž V  qd S r   r   )r   r+   r   r   r   r   C   r   )ÚsplitÚsetr   )Úrange_stringÚrowsr&   r   r   r   Úexpand_cell_ranges;   s   r5   r   )ÚMultiCellRangec                   @   s  e Zd ZdZeed�ZedƒZedƒZ	e
dd�ZedƒZe
dd�Ze
dd�Ze
dd�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Úformula2r?   ÚshowErrorMessageÚshowInputMessager]   ÚpromptTitleÚ
errorStyleÚerrorÚpromptÚ
errorTitle)Úselfr]   r`   ra   rb   rc   r>   r?   r;   rd   re   rf   rg   rh   r^   r_   Úallow_blankr   r   r   Ú__init__j   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©Úhasattrrl   r;   ©ri   r   r   r   r   Úadd�   s   
zDataValidation.addc                 C   s   t |dƒr|j}|| jv S )Nrl   rm   ro   r   r   r   Ú__contains__–   s   

zDataValidation.__contains__)NNNFFFFr   NNNNNNNN)#Ú__name__Ú
__module__Ú__qualname__Útagnamer   r6   r;   r   r&   r(   r   r>   Úhide_drop_downrc   rb   r?   rj   r	   rh   rf   rd   rg   r   Ústrr`   ra   r   r]   re   r^   r_   Úvalidation_typerk   rp   rq   r   r   r   r   r7   J   sR    













ð%r7   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<   r9   )r8   )ÚdisablePromptsÚxWindowÚyWindowÚcountNr   c                 C   s   || _ || _|| _|| _d S r   )r{   r|   r}   r8   )ri   r{   r|   r}   r~   r8   r   r   r   rk   ¨   s   
zDataValidationList.__init__c                 C   s   t | ƒS r   )r!   ©ri   r   r   r   r~   µ   s   zDataValidationList.countc                 C   s
   t | jƒS r   )r!   r8   r   r   r   r   Ú__len__º   s   
zDataValidationList.__len__c                 C   s   | j  |¡ d S r   )r8   r   )ri   Údvr   r   r   r   ¾   s   zDataValidationList.appendc                    s.   | j }dd„ | j D ƒ| _ 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>)r8   ÚsuperÚto_tree)ri   ru   r(   Úxml©Ú	__class__r   r   r…   Â   s
   zDataValidationList.to_tree)NNNNr   r   )rr   rs   rt   ru   r   r{   r   r|   r}   r
   r7   r8   Ú__elements__Ú	__attrs__rk   Úpropertyr~   r€   r   r…   Ú__classcell__r   r   r‡   r   ry   œ   s&    




û
ry   N)r   )Úcollectionsr   Ú	itertoolsr   r_   r   Ú!openpyxl.descriptors.serialisabler   Úopenpyxl.descriptorsr   r   r	   r
   r   r   r   Úopenpyxl.descriptors.nestedr   Úopenpyxl.utilsr   r   r   r/   r5   Ú
cell_ranger6   r7   ry   r   r   r   r   Ú<module>   s   $	
!R