
    	h7                        S r SSKJr  SSKJrJr  SSKJrJr  SSK	r	SSK
Jr  \	R                  " S5      rS	rS
rSr\	R                  " S\-   S-   \	R"                  5      rSr\	R                  " SR)                  \\5      \	R"                  5      rS rS rS rS/\" \5      -   r\" SS9S 5       r\" \S5       V Vs0 s H  u  pX_M	     snn rSr\" SS9S 5       rS r S r!S r"S r#S r$S r%gs  snn f )zT
Collection of utilities used within the package and also available for client code
    )	lru_cache)chainproduct)ascii_uppercasedigitsN   )CellCoordinatesExceptionz^[$]?([A-Za-z]{1,3})[$]?(\d+)$z[A-Z]{1,3}:[A-Z]{1,3}:z\d+:\d+:zq
[$]?(?P<min_col>[A-Za-z]{1,3})?
[$]?(?P<min_row>\d+)?
(:[$]?(?P<max_col>[A-Za-z]{1,3})?
[$]?(?P<max_row>\d+)?)?
^$z7
(('(?P<quoted>([^']|'')*)')|(?P<notquoted>[^'^ ^!]*))!z{0}(?P<cells>{1})(?=,?)c                     [        U [        5      (       a  [        U 5      n [        U[        5      (       a  [        U5      n[        XS-   5       Vs/ s H  n[	        U5      PM     sn$ s  snf )z
Given the start and end columns, return all the columns in the series.

The start and end columns can be either column letters or 1-based
indexes.
r   )
isinstancestrcolumn_index_from_stringrangeget_column_letter)startendxs      E/var/www/html/env/lib/python3.13/site-packages/openpyxl/utils/cell.pyget_column_intervalr      s[     %(/#s&s+*/Qw*?@*?Qa *?@@@s   A)c                     [         R                  U 5      nU(       d  SU  S3n[        U5      eUR                  5       u  p4[	        U5      nU(       d  SU  S3n[        U5      eX44$ )z;Convert a coordinate string like 'B12' to a tuple ('B', 12)zInvalid cell coordinates ()zThere is no row 0 ()COORD_REmatchr	   groupsint)coord_stringr   msgcolumnrows        r   coordinate_from_stringr!   ,   sf    NN<(E*<.:&s++,,.KF
c(C#L>3&s++;    c                     [         R                  U 5      nU(       d  [        U  S35      eUR                  S5      nUR	                  5        H  u  p4U(       d  M  SU 3X#'   M     US   (       d
  US   (       a  SnOSnUR
                  " S0 UD6$ )	zDConvert a coordinate to an absolute coordinate string (B12 -> $B$12)z  is not a valid coordinate range r   max_colmax_rowz%{min_col}{min_row}:{max_col}{max_row}z{min_col}{min_row} )ABSOLUTE_REr   
ValueError	groupdictitemsformat)r   mdkvfmts         r   absolute_coordinater2   :   s    ,'AL>)IJKK	BA	1qc7AD  	|q|5"::??r"   r$   )maxsizec                 B   SU s=::  a  S::  d  O  [        SR                  U 5      5      e/ nU S:  a	  [        U    $ U (       aN  [        U S5      u  pUR	                  S[        U   5        U(       d  U S-  n UR	                  SS5        U (       a  MN  SR                  U5      $ )a  
Convert decimal column position to its ASCII (base 26) form.

Because column indices are 1-based, strides are actually pow(26, n) + 26
Hence, a correction is applied between pow(26, n) and pow(26, 2) + 26 to
prevent and additional column letter being prepended

"A" == 1 == pow(26, 0)
"Z" == 26 == pow(26, 0) + 26 // decimal equivalent 10
"AA" == 27 == pow(26, 1) + 1
"ZZ" == 702 == pow(26, 2) + 26 // decimal equivalent 100
r   ifG  zInvalid column index {0}   r   Zr$   )r)   r,   __decimal_to_alphadivmodinsertjoin)col_idxresult	remainders      r   r   r   N   s      5 3::7CDDF|!'**
#GR0a+I67qLGMM!S! ' 776?r"   )r   r5   i  c                 6   SU  S3n[        U 5      S:  a  [        U5      eSn[        U R                  5       5      n [	        U [
        5       H  u  p4 [        U   nX%U-  -  nM     SUs=:  a  S:  d  O  [        U5      eU$ ! [         a    [        U5      ef = f)z
Convert ASCII column name (base 26) to decimal with 1-based index

Characters represent descending multiples of powers of 26

"AFZ" == 26 * pow(26, 0) + 6 * pow(26, 1) + 1 * pow(26, 2)
'z<' is not a valid column name. Column names are from A to ZZZ   r   igG  )lenr)   reversedupperzip__powers__alpha_to_decimalKeyError)col	error_msgidxletterpowerposs         r   r   r   r   s     C5TUI
3x!|##
C
399;
CS(+	($V,C 	U{ , s?U?##J  	(Y''	(s   	BBc                    SR                  U 5      n[        R                  U 5      nU(       d  [        U5      eUR	                  5       u  p4pVnU(       ac  X64nXG4n	[        X-   5      (       dK  [        U5      (       a  [        U	5      (       a+  [        U	5      (       a  [        U5      (       a  [        U5      eUb  [        U5      nUb  [        U5      nUb  [        U5      nOUnUb  [        U5      nOUnX4Xg4$ )z
Convert a range string into a tuple of boundaries:
(min_col, min_row, max_col, max_row)
Cell coordinates will be converted into a range with the cell at both end
z&{0} is not a valid coordinate or range)	r,   r(   r   r)   r   allanyr   r   )
range_stringr   r-   min_colmin_rowsepr%   r&   colsrowss
             r   range_boundariesrW      s     3
9
9,
GC,'Ao./hhj+GcG
 IIc$iiIIc$iiS/!*73g,*73g,W--r"   c              #      ^#    [        U 5      u  pp4[        X$S-   5      n[        XS-   5       Vs/ s H  n[        U5      PM     nnU H  m[        U4S jU 5       5      v   M     gs  snf 7f)O
Get individual addresses for every cell in a range.
Yields one row at a time.
r   c              3   H   >#    U  H  nS R                  UT5      v   M     g7fz{0}{1}Nr,   ).0rH   r    s     r   	<genexpr>"rows_from_range.<locals>.<genexpr>        >#HOOC--   "N)rW   r   r   tuple)	rQ   rR   rS   r%   r&   rV   rH   rU   r    s	           @r   rows_from_rangerc      sk     
 *:,)G&GgA+&D.3Gq[.IJ.Isc".IDJ>>>>  Ks   -A-A((A-c              #      ^#    [        U 5      u  pp4[        X$S-   5      nS [        XS-   5       5       nU H  m[        U4S jU 5       5      v   M     g7f)rY   r   c              3   8   #    U  H  n[        U5      v   M     g 7f)N)r   )r]   rH   s     r   r^   "cols_from_range.<locals>.<genexpr>   s     H.Gsc"".Gs   c              3   H   >#    U  H  nS R                  TU5      v   M     g7fr[   r\   )r]   r    rH   s     r   r^   rf      r`   ra   N)rW   r   rb   )rQ   rR   rS   r%   r&   rV   rU   rH   s          @r   cols_from_rangerh      sS     
 *:,)G&Gg!)$DHeGQY.GHD>>>> s   AAc                     [        U 5       H  u  pU[        ;   d  M    O   U SW nXS n[        U5      [        U5      4$ )z:
Convert an Excel style coordinate to (row, column) tuple
N)	enumerater   r   r   )
coordinaterJ   crH   r    s        r   coordinate_to_tuplerm      sL     J'; ( Tc
C
T
Cs8-c222r"   c                     [         R                  U 5      nUc  [        S5      eUR                  S5      =(       d    UR                  S5      nUR                  S5      n[	        U5      nX$4$ )zW
Convert a worksheet range to the sheetname and maximum and minimum
coordinate indices
z)Value must be of the form sheetname!A1:E4quoted	notquotedcells)SHEETRANGE_REr   r)   grouprW   )rQ   r-   	sheetnamerq   
boundariess        r   range_to_tuplerv      sb    
 	L)AyDEE!9QWW[%9IGGGE!%(J  r"   c                 X    SU ;   a  U R                  SS5      n SR                  U 5      n U $ )z6
Add quotes around sheetnames if they contain spaces.
r?   z''z'{0}')replacer,   )rt   s    r   quote_sheetnamery      s2     i%%c40		*Ir"   )&__doc__	functoolsr   	itertoolsr   r   stringr   r   re
exceptionsr	   compiler   	COL_RANGE	ROW_RANGE
RANGE_EXPRVERBOSEr(   SHEET_TITLEr,   rr   r   r!   r2   listr7   r   rj   rF   rE   r   rW   rc   rh   rm   rv   ry   )rM   rK   s   00r   <module>r      s.     $ * 	 0 ::78(		
 jjz)3.

;:

8?? jj*A$ TD11 
4 @ 5>oq4QR4Q[Sfj4QR 
4 0(.V	?	?	3!s Ss   :C-