
    	h                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	J
r
JrJrJrJrJr  S SKJr  S SKJrJrJr  SS jrS	 rS
SKJr   " S S\5      r " S S\5      rg)    )defaultdictchain)
itemgetter)Serialisable)BoolNoneSetStringSequenceAliasIntegerConvertible)
NestedText)rows_from_rangecoordinate_to_tupleget_column_letterc           	         [        U5      nS U  5       n[        [         5      n[        U[        S5      S9 H  u  pVXF   R	                  U5        M     UR                  5        HZ  u  p`[        U5      nSn[        U 5      S:X  a  SnUR                  U[        U 5      U[        U 5      5      nUR	                  U5        M\     SR                  U5      $ )aK  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              3   8   #    U  H  n[        U5      v   M     g 7fN)r   ).0cells     S/var/www/html/env/lib/python3.13/site-packages/openpyxl/worksheet/datavalidation.py	<genexpr>*collapse_cell_addresses.<locals>.<genexpr>(   s     >%d++      )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rs	            r   collapse_cell_addressesr1      s     ,F ?>J !&N::a=9""3' : %**,
$u:?CJJsCJSZ8a - 88F    c                 d    S U R                  5        5       nS U 5       n[        [        U6 5      $ )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              3   8   #    U  H  n[        U5      v   M     g 7fr   )r   )r   rss     r   r   %expand_cell_ranges.<locals>.<genexpr>B   s     ?*>BOB*>r   c              3   2   #    U  H  n[        U6 v   M     g 7fr   r   )r   r-   s     r   r   r6   C   s     )DSUC[Ds   )splitsetr   )range_stringrowsr(   s      r   expand_cell_rangesr<   ;   s1     @,*<*<*>?D)D)Eue}r2   r   )MultiCellRangec                   V   \ rS rSrSr\" \S9r\" S5      r	\" S5      r
\" SS9r\" S5      r\" SS9r\" SS9r\" SS9r\" S5      r\" SS9r\" SS9r\" SS9r\" SS9r\" S\S	9r\" S\S	9r\" S
S9r\" SS9r\" SS9r\" SS9r\" S5      r                 SS jr!S r"S r#Sr$g)DataValidationJ   dataValidationexpected_typesqrefT
allow_noneshowDropDown
allowBlank)rF   rC   )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typeNc                     Xl         X`l        Xl        Xl        X l        X0l        Ub  UnXpl        X@l        XPl        Xl	        Xl
        Xl        Xl        Xl        Xl        g r   )rD   rG   imeModeoperatorformula1formula2rH   showErrorMessageshowInputMessagerf   promptTitle
errorStyleerrorprompt
errorTitle)selfrf   rj   rk   rl   rm   rG   rH   rD   rn   ro   rp   rq   rr   rh   ri   allow_blanks                    r   __init__DataValidation.__init__j   s^    $ 
(   "$J$ 0 0	&$
$r2   c                 h    [        US5      (       a  UR                  nU =R                  U-  sl        g)z0Adds a cell or cell coordinate to this validator
coordinateNhasattrrx   rD   rs   r   s     r   addDataValidation.add   s&    4&&??D

d
r2   c                 X    [        US5      (       a  UR                  nXR                  ;   $ )Nrx   ry   r{   s     r   __contains__DataValidation.__contains__   s%    4&&??Dzz!!r2   )rH   rp   ro   rr   rj   rk   rh   ri   rq   rn   rG   rl   rm   rD   rf   )NNNFFFF NNNNNNNN)%__name__
__module____qualname____firstlineno__tagnamer   r=   rD   r   r(   r*   r   rG   hide_drop_downrm   rl   rH   rt   r
   rr   rp   rn   rq   r   strrj   rk   r	   rf   ro   rh   ri   validation_typeru   r|   r   __static_attributes__r   r2   r   r?   r?   J   s(   Gn5E'NE7^F4(L>*Nt,t,&J%KT*J%Ed+K&FT=HT=H 3 4D BCJ : ;G  c dHFmO "'"'#!!  !!"%J"r2   r?   c                      ^  \ rS rSrSr\" SS9r\" SS9r\" SS9r	\
" \S9rSrSr     SS jr\S	 5       rS
 rS rSU 4S jjrSrU =r$ )DataValidationList   dataValidationsTrE   rB   )rA   )disablePromptsxWindowyWindowcountc                 4    Xl         X l        X0l        XPl        g r   )r   r   r   rA   )rs   r   r   r   r   rA   s         r   ru   DataValidationList.__init__   s     -,r2   c                     [        U 5      $ r   )r#   rs   s    r   r   DataValidationList.count   s    4yr2   c                 ,    [        U R                  5      $ r   )r#   rA   r   s    r   __len__DataValidationList.__len__   s    4&&''r2   c                 :    U R                   R                  U5        g r   )rA   r!   )rs   dvs     r   r!   DataValidationList.append   s    ""2&r2   c                    > U R                   nU R                    Vs/ s H!  n[        UR                  5      (       d  M  UPM#     snU l         [        TU ]  U5      nX l         U$ s  snf )z3
Need to skip validations that have no cell ranges
)rA   boolrD   superto_tree)rs   r   r*   r0   xml	__class__s        r   r   DataValidationList.to_tree   sX     $$*.*=*=O*=Qaggq*=Ogog&$
 Ps
   A#A#)rA   r   r   r   )NNNNr   r   )r   r   r   r   r   r   r   r   r   r   r   r?   rA   __elements__	__attrs__ru   propertyr   r   r!   r   r   __classcell__)r   s   @r   r   r      sx    GT*N&G&GN;N&LAI !% "
-  (' r2   r   N)r   )collectionsr   	itertoolsr   ri   r   !openpyxl.descriptors.serialisabler   openpyxl.descriptorsr   r	   r
   r   r   r   r   openpyxl.descriptors.nestedr   openpyxl.utilsr   r   r   r1   r<   
cell_ranger=   r?   r   r   r2   r   <module>r      s\    $   :   3 B	 'O"\ O"d. .r2   