
    ;OOf(                         d dl mZmZ d dlZd dlmZmZmZmZ  ej                  d      Z
 ej                   ed            Zdag dad Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zedk(  r e        yy)    )divisionprint_functionN)bytesBord2	text_typez^[ -~]*$)&)~      )   r   )i  r
   )i  r   )i  r
   )i  r   )i  r
   )io  r   )i  r
   )i  r   )i  r
   )i_     )i+  r
   )ia  r   )i   r
   )i   r   )i(#  r
   )i*#  r   )i+  r
   )i>0  r   )i?0  r
   )i0  r   )i0  r   )iM  r   )iM  r
   )i  r   )i  r
   )ij  r   )i  r
   )i#  r   )ik  r   )i  r
   )i`  r   )i  r
   )i  r   )i r
   )i r   )i r
   c                 H    | dk(  s| dk(  ryt         D ]  \  }}| |k  s|c S  y)z5Return the screen column width for unicode ordinal o.      r   r
   )widths)onumwids      S/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/urwid/old_str_util.py	get_widthr   Q   s8     	Cx18 S8J     c                 $   t        | t              sJ |        t        | |         }|dz  s||dz   fS t        d      |dz   f}t	        |       }||z
  }|dk  r|S |dz  dk(  r7t        | |dz            }|dz  dk7  r|S |dz  dz  |d	z  z  }|dk  r|S ||dz   fS |d
k  r|S |dz  dk(  r[t        | |dz            }|dz  dk7  r|S t        | |dz            }|dz  dk7  r|S |dz  dz  |d	z  dz  z  |d	z  z  }|dk  r|S ||d
z   fS |dk  r|S |dz  dk(  rt        | |dz            }|dz  dk7  r|S t        | |dz            }|dz  dk7  r|S t        | |dz            }|dz  dk7  r|S |dz  dz  |d	z  dz  z  |d	z  dz  z  |d	z  z  }|dk  r|S ||dz   fS |S )zH
    Return (ordinal at pos, next position) for UTF-8 encoded text.
       r
   ?r               ?         r      i               i   )
isinstancer   r   ordlen)	textposb1errorltb2r   b3b4s	            r   
decode_oner1   [   s1    dE"(D("	d3iB93q5yHc!eOE	TB	CB	Av	DyD$s1u+9Lg\BtG$t8L#a%x	Av	DyD$s1u+9L$s1u+9Lg]bg\*BtG4u9L#a%x	Av	DyD$s1u+9L$s1u+9L$s1u+9Lg]bg]+bg\:BtGDw;L#a%xLr   c                 (    t        | |         |dz   fS )z7
    decode_one implementation for unicode strings
    r
   )r'   )r)   is     r   decode_one_unir4      s     tAw<1r   c                     t        | t              sJ |        t        d      |dz
  f}|}|dk\  r@t        | |         dz  dk7  rt	        | |      \  }}||dz
  fS |dz  }||dz
  k(  r|S |dk\  r?yy)z
    Return (ordinal at pos, next position) for UTF-8 encoded text.
    pos is assumed to be on the trailing byte of a utf-8 sequence.
    r   r
   r   r   r   r"   N)r&   r   r'   r   r1   )r)   r*   r,   pr   nexts         r   decode_one_rightr8      s    
 dE"(D("Hc!eOEA
q&Q=% $+GAtac6M	A!8L q&r   c                     | dv sJ | a y )N)utf8narrowwide_byte_encoding)encs    r   set_byte_encodingr@      s    ,,,,Nr   c                      t         S )Nr=    r   r   get_byte_encodingrC      s    r   c                    ||k  sJ t        ||f             t        | t              xr	 t        dk(  }t        | t               }|s|rNt        t
        g|   }|}d}d}	||k  r0 || |      \  }
}	t        |
      }||z   |kD  r||fS |	}||z  }||k  r0||fS t        |       t        k(  sJ t        |              ||z   }||k\  r|||z
  fS t        dk(  rt        | ||      dk(  r|dz  }|||z
  fS )a9  
    Calculate the closest position to the screen column pref_col in text
    where start_offs is the offset into text assumed to be screen column 0
    and end_offs is the end of the range to search.

    text may be unicode or a byte string in the target _byte_encoding

    Returns (position, actual_col).
    r:   r   r
   r<   r   )	reprr&   r   r>   r1   r4   r   typewithin_double_byte)r)   
start_offsend_offspref_colutfsunisdecoder3   scnr   ws               r   calc_text_posrQ      s*    !?4X(>#??!dE"?~'?D$&&Dtn-d3(l$?DAq!Ath"uA!GB (l "u:*T
*8AH}*,,,dJ2a7FAa
l?r   c                 n   ||k  sJ t        ||f             t        | t              xr	 t        dk(  }t        | t               }|rt        j                  |       r|rUt        j                  |       s@t        t        g|   }|}d}d}||k  r$ || |      \  }	}t        |	      }
|}||
z  }||k  r$|S ||z
  S )am  
    Return the screen column width of text between start_offs and end_offs.

    text may be unicode or a byte string in the target _byte_encoding

    Some characters are wide (take two columns) and others affect the
    previous character (take zero columns).  Use the widths table above
    to calculate the screen column width of text[start_offs:end_offs]
    r:   r   r
   )
rE   r&   r   r>   SAFE_ASCII_REmatchSAFE_ASCII_BYTES_REr1   r4   r   )r)   rH   rI   rK   rL   rM   r3   rN   rO   r   rP   s              r   
calc_widthrV      s     !?4X(>#??!dE"?~'?D$&&D]((.288>n-d3(l$?DAq!AA!GB	 (l
 	j  r   c                     t        | t              rt        | |         }t        |      dk(  S t        | t              sJ t
        dk(  rt        | |      \  }}t        |      dk(  S t
        dk(  rt        | ||      dk(  S y)z
    Test if the character at offs within text is wide.

    text may be unicode or a byte string in the target _byte_encoding
    r   r:   r<   r
   F)r&   r   r'   r   r   r>   r1   rG   )r)   offsr   rO   s       r   is_wide_charrY      s     $	"T
O|q  dE"""$%1|q  !$d3q88r   c                 &   ||k  sJ t        | t              r|dz
  S t        | t              sJ t        dk(  r5|dz
  }t	        | |         dz  dk(  r|dz  }t	        | |         dz  dk(  r|S t        dk(  rt        | ||dz
        dk(  r|dz
  S |dz
  S )z?
    Return the position of the character before end_offs.
    r
   r:   r   r   r<   r   r&   r   r   r>   r   rG   r)   rH   rI   r   s       r   move_prev_charr]      s        $	"zdE"""QJ47mD D(FA 47mD D($6tHQJ% #$%%zA:r   c                 4   ||k  sJ t        | t              r|dz   S t        | t              sJ t        dk(  r?|dz   }||k  r3t	        | |         dz  dk(  r|dz  }||k  rt	        | |         dz  dk(  r|S t        dk(  rt        | ||      dk(  r|dz   S |dz   S )z@
    Return the position of the character after start_offs.
    r
   r:   r   r   r<   r   r[   r\   s       r   move_next_charr_     s        $	"!|dE"""qLjT$q']4/47FA jT$q']4/47$6tJ% #$%%1}a<r   c                 "   t        | t              sJ t        | |         }|dk\  r4|dk  r/||k(  ryt        | |dz
           dk\  rt        | ||dz
        dk(  ryy|dk  ry|dz
  }||k\  rt        | |         dk  rn|dz  }||k\  r||z
  dz  ryy)aj  Return whether pos is within a double-byte encoded character.

    text -- byte string in question
    line_start -- offset of beginning of line (< pos)
    pos -- offset in question

    Return values:
    0 -- not within dbe char, or double_byte_encoding == False
    1 -- pos is on the 1st half of a dbe char
    2 -- pos is on the 2nd half of a dbe char
    @      r   r
      r   r   )r&   r   r   rG   )r)   
line_startr*   vr3   s        r   rG   rG   $  s     dE"""T#YADyQX*QSU$!$
CE:a?4xQA
z/Q=4	Q z/
 	a1}r   c                  :   dd l } g }d }| j                  j                         D ]  }|d d dk(  r|j                         }|j	                  dd      \  }}|j	                  dd      \  }}|j	                  dd      d   }d|v r|j	                  d      d   }t        |d	      }|d
v rd}	n	|dv rd}	nd}	||j                  d|	f       |	}||	k(  r||	f|d<   |j                  ||	f       |	} t        d       |dd  D ]  }
t        d|
d        t        d       y )Nr   r
   #;z #  .z..   )	COMBININGMODIFIERz	<control>)WFr   z
widths = [	,])sysstdin	readlinesstripsplitintappendprint)rt   outlastlinehexrestr   word1r   lr   s              r   process_east_asian_widthr   J  s9   
CD		##% 8s?Hzz|::c!$D::eA&D

3q!!$#:))D/!$C#rl88AJAA<JJ1vD19AhCGJJa"D58 
,W n	#Jr   __main__)
__future__r   r   reurwid.compatr   r   r   r   compilerS   rU   r>   r   r   r1   r4   r8   r@   rC   rQ   rV   rY   r]   r_   rG   r   __name__rB   r   r   <module>r      s   . 0 	 2 2

;' bjj:/ '
V2h 
"H!<"$$"L#J z r   