
    	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  S SKJ	r	  S SK
JrJrJrJr   " S S	\	5      r " S
 S\5      rg)    )copy)
attrgetter)Strict)MinMax)UniqueSequence)Serialisable)range_boundariesrange_to_tupleget_column_letterquote_sheetnamec                      \ rS rSrSr\" SS\S9r\" SS\S9r\" SS\S9r	\" SS\S9r
  S(S jr\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       rS rS rS rS rS rS)S jrS rS rS r\rS rS rS r\rS r S r!S r"S r#\#r$S r%\%r&S r'S*S  jr(S*S! jr)\S" 5       r*\S# 5       r+\S$ 5       r,\S% 5       r-\S& 5       r.S'r/g)+	CellRange   a  
Represents a range in a sheet: title and coordinates.

This object is used to perform operations on ranges, like:

- shift, expand or shrink
- union/intersection with another sheet range,

We can check whether a range is:

- equal or not equal to another,
- disjoint of another,
- contained in another.

We can get:

- the size of a range.
- the range bounds (vertices)
- the coordinates,
- the string representation,

   ifG  )minmaxexpected_typei   Nc                    Ub&  SU;   a  [        U5      u  nu  p#pEO[        U5      u  p#pEX l        X0l        X@l        XPl        X`l        X$:  a  Sn[        UR                  X$S95      eX5:  a  Sn[        UR                  X5S95      eg )N!z({max_col} must be greater than {min_col})min_colmax_colz({max_row} must be greater than {min_row})min_rowmax_row)	r
   r	   r   r   r   r   title
ValueErrorformat)selfrange_stringr   r   r   r   r   fmts           O/var/www/html/env/lib/python3.13/site-packages/openpyxl/worksheet/cell_range.py__init__CellRange.__init__0   s    #l">L\>Z;;'75El5S2'
<CSZZZIJJ<CSZZZIJJ     c                 ^    U R                   U R                  U R                  U R                  4$ )z"
Vertices of the range as a tuple
r   r   r   r   r   s    r    boundsCellRange.boundsF   s#    
 ||T\\4<<EEr#   c                 
   SnU R                   U R                  :X  a  U R                  U R                  :X  a  SnUR	                  [        U R                   5      U R                  [        U R                  5      U R                  S9$ )z)
Excel-style representation of the range
z%{min_col}{min_row}:{max_col}{max_row}z{min_col}{min_row}r%   )r   r   r   r   r   r   r   r   s     r    coordCellRange.coordN   sj    
 6LLDLL(,&Czz%dll3LL%dll3LL	  
 	
r#   c              #      #    [        U R                  U R                  S-   5       H:  n[        U R                  U R                  S-   5       Vs/ s H  o!U4PM     snv   M<     gs  snf 7f)z!
Return cell coordinates as rows
r   N)ranger   r   r   r   )r   rowcols      r    rowsCellRange.rows_   S     
 t||A~6C).t||T\\!^)LM)L#:)LMM 7M   AA*A%A*c              #      #    [        U R                  U R                  S-   5       H:  n[        U R                  U R                  S-   5       Vs/ s H  o"U4PM     snv   M<     gs  snf 7f)z$
Return cell coordinates as columns
r   N)r.   r   r   r   r   )r   r0   r/   s      r    colsCellRange.colsh   r3   r4   c                     SSK Jn  U" [        U R                  U R                  S-   5      [        U R
                  U R                  S-   5      5      $ )Nr   )productr   )	itertoolsr9   r.   r   r   r   r   )r   r9   s     r    cellsCellRange.cellsq   s=    %uT\\4<<>:E$,,PTP\P\]^P^<_``r#   c                     [        U[        5      (       d  [        [        [	        U5      5      5      eUR
                  (       a&  U R
                  UR
                  :w  a  [        S5      egg)z
Check whether comparisons between ranges are possible.
Cannot compare ranges from different worksheets
Skip if the range passed in has no title.
z1Cannot work with ranges from different worksheetsN)
isinstancer   	TypeErrorreprtyper   r   r   others     r    _check_titleCellRange._check_titlew   sN     %++De-..;;4::4PQQ 5;r#   c                     SnU R                   (       a  SnUR                  U R                  R                  U R                   U R                  S9$ )Nz<{cls} {coord}>z<{cls} {title!r}!{coord}>)clsr   r+   )r   r   	__class____name__r+   r*   s     r    __repr__CellRange.__repr__   s:     ::.Czzdnn55TZZtzzzZZr#   c                 p    [        U R                  U R                  U R                  U R                  45      $ N)hashr   r   r   r   r&   s    r    __hash__CellRange.__hash__   s&    T\\4<<t||LMMr#   c                 x    SnU R                   nU(       a  Sn[        U5      nUR                  X R                  S9$ )Nz{coord}z{title}!{coord})r   r+   )r   r   r   r+   )r   r   r   s      r    __str__CellRange.__str__   s7    

$C#E*EzzZZz88r#   c                     U R                  U R                  U R                  U R                  U R                  U R
                  S9$ )Nr   r   r   r   r   )rH   r   r   r   r   r   r&   s    r    __copy__CellRange.__copy__   s8    ~~dllDLL&*llDLL$(JJ  0 	0r#   c                 ,   U R                   U-   S::  d  U R                  U-   S::  a  [        SR                  X5      5      eU =R                   U-  sl         U =R                  U-  sl        U =R                  U-  sl        U =R
                  U-  sl        g)aC  
Shift the focus of the range according to the shift values (*col_shift*, *row_shift*).

:type col_shift: int
:param col_shift: number of columns to be moved by, can be negative
:type row_shift: int
:param row_shift: number of rows to be moved by, can be negative
:raise: :class:`ValueError` if any row or column index < 1
r   z1Invalid shift value: col_shift={0}, row_shift={1}N)r   r   r   r   r   r   )r   	col_shift	row_shifts      r    shiftCellRange.shift   sv     LL9$)||i'1,PWWXamnn	!	!	!	!r#   c                 8    U R                  U5        UR                  U R                  :g  =(       dY    U R                  UR                  :g  =(       d9    UR                  U R                  :g  =(       d    U R
                  UR
                  :g  $ ! [         a     gf = f)z
Test whether the ranges are not equal.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range
:return: ``True`` if *range* != *other*.
T)rD   r   r   r   r   r   rB   s     r    __ne__CellRange.__ne__   s    	e$
 MMT\\) -||u}},-}},- ||u}},		
  		s   B 
BBc                 .    U R                  U5      (       + $ )z
Test whether the ranges are equal.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range
:return: ``True`` if *range* == *other*.
)r^   rB   s     r    __eq__CellRange.__eq__   s     ;;u%%%r#   c                 F    U R                  U5        UR                  U 5      $ )z
Test whether every cell in this range is also in *other*.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range
:return: ``True`` if *range* <= *other*.
rD   _CellRange__supersetrB   s     r    issubsetCellRange.issubset   s#     	% %%r#   c                 T    U R                  U5      =(       a    U R                  U5      $ )z
Test whether *other* contains every cell of this range, and more.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range
:return: ``True`` if *range* < *other*.
)__le__r^   rB   s     r    __lt__CellRange.__lt__   !     {{5!8dkk%&88r#   c                 8   U R                   UR                   s=:*  =(       a&    UR                  s=:*  =(       a    U R                  :*  Os  =(       aJ    U R                  UR                  s=:*  =(       a&    UR                  s=:*  =(       a    U R                  :*  $ s  $ rM   )r   r   r   r   rB   s     r    
__supersetCellRange.__superset   sh    \\U]]KKemmKKt||K M\\U]]KKemmKKt||K	
 L	
r#   c                 F    U R                  U5        U R                  U5      $ )z
Test whether every cell in *other* is in this range.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range
:return: ``True`` if *range* >= *other* (or *other* in *range*).
rd   rB   s     r    
issupersetCellRange.issuperset   s!     	% u%%r#   c                 F    U R                  U5      nU R                  U5      $ )z?
Check whether the range contains a particular cell coordinate
)rH   re   r   r+   crs      r    __contains__CellRange.__contains__  s!     ^^E"r""r#   c                 T    U R                  U5      =(       a    U R                  U5      $ )z
Test whether this range contains every cell in *other*, and more.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range
:return: ``True`` if *range* > *other*.
)__ge__r^   rB   s     r    __gt__CellRange.__gt__  rl   r#   c                    U R                  U5        U R                  UR                  :  a  XpU R                  UR                  :  =(       d9    U R                  UR
                  :  =(       d    UR                  U R
                  :  $ )a&  
Return ``True`` if this range has no cell in common with *other*.
Ranges are disjoint if and only if their intersection is the empty range.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range.
:return: ``True`` if the range has no cells in common with other.
)rD   r'   r   r   r   r   rB   s     r    
isdisjointCellRange.isdisjoint  sh     	%  ;;%%u}}, 0<<%--/0==4<</	1r#   c                 x   U R                  U5      (       a  [        SR                  X5      5      e[        U R                  UR                  5      n[        U R                  UR                  5      n[        U R                  UR                  5      n[        U R                  UR                  5      n[        XBUUS9$ )a  
Return a new range with cells common to this range and *other*

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range.
:return: the intersecting sheet range.
:raise: :class:`ValueError` if the *other* range doesn't intersect
    with this range.
zRange {0} doesn't intersect {0}r%   )
r}   r   r   r   r   r   r   r   r   r   r   rC   r   r   r   r   s         r    intersectionCellRange.intersection*  s     ??5!!>EEdRSSdllEMM2dllEMM2dllEMM2dllEMM27!(* 	*r#   c                 N   U R                  U5        [        U R                  UR                  5      n[        U R                  UR                  5      n[        U R
                  UR
                  5      n[        U R                  UR                  5      n[        XBUX0R                  S9$ )aW  
Return the minimal superset of this range and *other*. This new range
will contain all cells from this range, *other*, and any additional
cells required to form a rectangular ``CellRange``.

:type other: openpyxl.worksheet.cell_range.CellRange
:param other: Other sheet range.
:return: a ``CellRange`` that is a superset of this and *other*.
rU   )	rD   r   r   r   r   r   r   r   r   r   s         r    unionCellRange.unionB  sz     	% dllEMM2dllEMM2dllEMM2dllEMM27!(

< 	<r#   c              #   b   #    U R                    H  nUS:X  a  M  [        X5      nX4v   M     g7f)z3
For use as a dictionary elsewhere in the library.
r   N)	__attrs__getattr)r   xvs      r    __iter__CellRange.__iter__X  s0      AG| A$J	  s   -/c                     U =R                   U-  sl         U =R                  U-  sl        U =R                  U-  sl        U =R                  U-  sl        g)aV  
Expand the range by the dimensions provided.

:type right: int
:param right: expand range to the right by this number of cells
:type down: int
:param down: expand range down by this number of cells
:type left: int
:param left: expand range to the left by this number of cells
:type up: int
:param up: expand range up by this number of cells
Nr%   )r   rightdownleftups        r    expandCellRange.expandc  s<     	r#   c                     U =R                   U-  sl         U =R                  U-  sl        U =R                  U-  sl        U =R                  U-  sl        g)ao  
Shrink the range by the dimensions provided.

:type right: int
:param right: shrink range from the right by this number of cells
:type down: int
:param down: shrink range from the top by this number of cells
:type left: int
:param left: shrink range from the left by this number of cells
:type up: int
:param up: shrink range from the bottom by this number of cells
Nr%   )r   r   bottomr   tops        r    shrinkCellRange.shrinkv  s<     	r#   c                 z    U R                   S-   U R                  -
  nU R                  S-   U R                  -
  nXS.$ )zBReturn the size of the range as a dictionary of rows and columns. r   )columnsr1   )r   r   r   r   )r   r6   r1   s      r    sizeCellRange.size  s;     ||a$,,.||a$,,.,,r#   c                     [        U R                  U R                  S-   5       Vs/ s H  oR                  U4PM     sn$ s  snf )z=A list of cell coordinates that comprise the top of the ranger   )r.   r   r   r   r   r0   s     r    r   CellRange.top  9     05T\\4<<PQ>/RS/Rs#/RSSS   A c                     [        U R                  U R                  S-   5       Vs/ s H  oR                  U4PM     sn$ s  snf )z@A list of cell coordinates that comprise the bottom of the ranger   )r.   r   r   r   r   s     r    r   CellRange.bottom  r   r   c                     [        U R                  U R                  S-   5       Vs/ s H  oU R                  4PM     sn$ s  snf )zCA list of cell coordinates that comprise the left-side of the ranger   )r.   r   r   r   r   r/   s     r    r   CellRange.left  9     05T\\4<<PQ>/RS/Rdll#/RSSSr   c                     [        U R                  U R                  S-   5       Vs/ s H  oU R                  4PM     sn$ s  snf )zDA list of cell coordinates that comprise the right-side of the ranger   )r.   r   r   r   r   s     r    r   CellRange.right  r   r   )r   r   r   r   r   )NNNNNN)r   r   )r   r   r   r   )0rI   
__module____qualname____firstlineno____doc__r   intr   r   r   r   r!   propertyr'   r+   r1   r6   r;   rD   rJ   rO   rR   rV   r[   r^   ra   rf   ri   rj   re   rq   ry   rv   rz   r}   r   __and__r   __or__r   r   r   r   r   r   r   r   __static_attributes__ r#   r    r   r      s   . S9Gs;GS9Gs;G AE37K, F F 
 
  N N N N a a

R[N90"(
*&
& F9

& F#91(** G<& F&& - - T T
 T T
 T T
 T Tr#   r   c                       \ rS rSr\" \S9r\" 5       4S jrS r	S r
S rS rS rS	 rS
 rS rS rS rS rS rS rSrg)MultiCellRangei  )r   c                     [        U[        5      (       a)  UR                  5        Vs/ s H  n[        U5      PM     nn[	        U5      U l        g s  snf rM   )r>   strsplitr   setranges)r   r   rs      r    r!   MultiCellRange.__init__  s=    fc"",2LLN;NqilNF;&k <s   Ac                 x    [        U[        5      (       a  [        U5      nU R                   H
  nX::  d  M
    g   g)NTF)r>   r   r   r   )r   r+   r   s      r    rv   MultiCellRange.__contains__  s4    eS!!e$EAz  r#   c                     SR                  U R                  5        Vs/ s H  n[        U5      PM     sn5      nSU R                  R                   SU S3$ s  snf )N <z [z]>)joinsortedr   rH   rI   r   r   r   s      r    rJ   MultiCellRange.__repr__  sN    4;;=9=a3q6=9:4>>**+2fXR88 :s   Ac                     SR                  U R                  5        Vs/ s H  n[        U5      PM     sn5      nU$ s  snf )Nr   )r   r   r   r   s      r    rR   MultiCellRange.__str__  s3    DKKM:MqCFM:; ;s   <c                 *    [        [        U 5      5      $ rM   )rN   r   r&   s    r    rO   MultiCellRange.__hash__  s    CIr#   c           	      B    [        U R                  [        SSSS5      S9$ )z
Return a sorted list of items
r   r   r   r   )key)r   r   r   r&   s    r    r   MultiCellRange.sorted  s!     dkkz)Y	S\']^^r#   c                     Un[        U[        5      (       a  [        U5      nO [        U[        5      (       d  [        S5      eX ;  a  U R                  R                  U5        gg)z$
Add a cell coordinate or CellRange
zYou can only add CellRangesN)r>   r   r   r   r   addrt   s      r    r   MultiCellRange.add  sS     eS!!5!BE9--:;;>KKOOB r#   c                 (    U R                  U5        U $ rM   )r   r   r+   s     r    __iadd__MultiCellRange.__iadd__  s    r#   c                     [        U[        5      (       a  U R                  U5      nU R                  UR                  :H  $ rM   )r>   r   rH   r   rB   s     r    ra   MultiCellRange.__eq__  s0    uc""NN5)E{{ell**r#   c                     X:X  + $ rM   r   rB   s     r    r^   MultiCellRange.__ne__  s      r#   c                 ,    [        U R                  5      $ rM   )boolr   r&   s    r    __bool__MultiCellRange.__bool__  s    DKK  r#   c                 z    [        U[        5      (       d  [        U5      nU R                  R                  U5        g rM   )r>   r   r   remover   s     r    r   MultiCellRange.remove  s+    %++e$E5!r#   c              #   :   #    U R                    H  nUv   M	     g 7frM   r   )r   ru   s     r    r   MultiCellRange.__iter__  s     ++BH s   c                 l    U R                    Vs1 s H  n[        U5      iM     nn[        U5      $ s  snf rM   )r   r   r   r   s      r    rV   MultiCellRange.__copy__  s.    #';;/;a$q';/f%% 0s   1r   N)rI   r   r   r   r   r   r   r   r!   rv   rJ   rR   rO   r   r   r   ra   r^   r   r   r   rV   r   r   r#   r    r   r     s\     )4F "e "9

_
 
+!!"
&r#   r   N)r   operatorr   openpyxl.descriptorsr   r   openpyxl.descriptors.sequencer   !openpyxl.descriptors.serialisabler   openpyxl.utilsr	   r
   r   r   r   r   r   r#   r    <module>r      sB      ' ' 8 : TT TTnW&V W&r#   