
    ;OOf%6                        d dl mZmZ d dlmZ d dlmZmZmZ d dl	Z	ej                  Z
e
j                  Ze
j                  Ze
j                  Ze
j                  Ze
j                  Ze
j                   Zd Zd e       vr e       ZnJ d       dadad	 Zd
 Zd Z ee       d Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z# G d de$      Z%d Z&d Z'd Z(d Z) G d de*      Z+d Z, G d  d!e-      Z.y)"    )divisionprint_function)escape)bytes	text_type
text_typesNc                  x   dd l } | j                         }	 	 | j                  | j                  d       | j                         d   xs d	 	 | j                  | j                  |       S # | j                  $ r Y Fw xY w# | j                  $ r Y S w xY w# t
        $ rg}|j                  rU|j                  d   j                  d      r7Y d }~	 | j                  | j                  |       y# | j                  $ r Y yw xY w d }~ww xY w# 	 | j                  | j                  |       w # | j                  $ r Y w w xY wxY w)Nr       zunknown locale)locale	getlocale	setlocaleLC_ALLError
ValueErrorargs
startswith)r   initiales      K/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/urwid/util.pydetect_encodingr   )   s(    G	V]]B/ !!$**	V]]G4 || 		 || 		  66affQi**+;<	V]]G4|| 			 	V]]G4|| 		s   A( B A=(A:7B 9A::B =BB	D*C=D 
C' 'C98C9<C==DD D9D$#D9$D63D95D66D9detected_encodingz
It worked!Tc                    | j                         } | dv rt        j                  d       dan3| dv rt        j                  d       dant        j                  d       dada	 | rd	j                  |        | ay
y
# t        $ r Y y
w xY w)z~
    Set the byte encoding to assume when processing strings and the
    encoding to use when converting unicode strings.
    )zutf-8utf8utfr   F)zeuc-jpzeuc-krzeuc-cnzeuc-twgb2312gbkbig5zcn-gbuhceucjpeuckreuccneuctwcncbwideTnarrowasciir
   N)lowerstr_utilset_byte_encoding_use_dec_special_target_encodingencodeLookupError)encodings    r   set_encodingr0   H   s    
 ~~H --""6* 	 ; 
;
 	""6*""8, JJx '  s   #A: :	BBc                  *    t         j                         S )z
    Get the mode Urwid is using when processing text strings.
    Returns 'narrow' for 8-bit encodings, 'wide' for CJK encodings
    or 'utf8' for UTF-8 encodings.
    )r)   get_byte_encoding     r   get_encoding_moder5   j   s     %%''r4   c                 ^   t         r2t        |       t        k(  r 	 | j                  t        j
                        } t        |       t        k(  rL| j                  t        j                  t        j                  z   d      } t        j                  | t        d      } t!        | t"              sJ t        j                  j                  d      }t        j                  j                  d      }| j%                  |      }t!        |d   t"              sJ |d   j                  |t#                     }g }g }|r-|j'                  |       |j'                  dt)        |      f       t)        |      dk(  r||fS |dd D ]&  }	t!        |	t"              sJ t!        |t"              sJ |	j%                  |d      }
t)        |
      dk(  r]|
d   }t!        |t"              sJ |j'                  |       t+        |t        j,                  j                  d      t)        |      f       |
\  }}|j                  |t#                     }|r6|j'                  |       t+        |t        j,                  t)        |      f       |s|j'                  |       t+        |dt)        |      f       ) t#               j/                  |      }||fS # t        $ rh t        t        j                  t        j                        D ]9  \  }}| j                  |t        j                  |z   t        j                  z         } ; Y w xY w)z:
    Return (encoded byte string, character set rle).
    r
   replacer'   r   Nr   )r+   typer   	translater   DEC_SPECIAL_CHARMAPNotImplementedErrorzipDEC_SPECIAL_CHARSALT_DEC_SPECIAL_CHARSr7   SOSIcodecsr-   r,   
isinstancer   splitappendlenrle_append_modifyDEC_TAGjoin)scaltr?   r@   sissis0soutcoutsnslsinsonoutstrs                 r   apply_target_encodingrU   s   s    DGy0	<V779A Aw)IIfii		)3/MM!-y9a			'	"B			'	"B
''"+Cc!fe$$$q6>>"eg&DDDTd3t9%'
3x{Tz!"g 6"e$$$"e$$$XXb!_r7a<Q%Cc5)))KKdV^^%:%:7%CSX$NOSkk"eg&KKdV^^SX$>?KKdT3s8$45#6& W\\$F4<a # 	<f66002 <3IIq&))C-		"9;<	<s   J; ;A-L,+L,c                  $    t         xr	 t         dk7  S )zi
    Return True if python is able to convert non-ascii unicode strings
    to the current encoding.
    r'   )r,   r3   r4   r   supports_unicoderW      s    
 ; 0G ;;r4   c                     |}dx}}|dkD  r,t        | |||      \  }}||k  rd}t        | |||dz         \  }}||z
  |z
  }	t        | |||	      \  }
}||	k  rd}||
||fS )a	  
    Calculate the result of trimming text.
    start_offs -- offset into text to treat as screen column 0
    end_offs -- offset into text to treat as the end of the line
    start_col -- screen column to trim at the left
    end_col -- screen column to trim at the right

    Returns (start, end, pad_left, pad_right), where:
    start -- resulting start offset
    end -- resulting end offset
    pad_left -- 0 for no pad or 1 for one space to be added
    pad_right -- 0 for no pad or 1 for one space to be added
    r   r   )calc_text_pos)text
start_offsend_offs	start_colend_colspospad_left	pad_rightscrunposs              r   calc_trim_textre      s     DHy1} $h	Cb	>H$dJ)A+(HD"
I

(CT438GC	Cx	3)--r4   c                    t        | dt        |       ||      \  }}}}t        |||      }	t        |||      }
|r)t        ||dz
        }t	        |	|df       t	        |
d       |r&t        ||      }t        |	|df       t        |
d       t               j                  |      | || z   t               j                  |      z   |	|
fS )z<
    Return ( trimmed text, trimmed attr, trimmed cs ).
    r   r   )Nr   )re   rE   
rle_subseg
rle_get_atrle_prepend_modifyrF   r   rjust)rZ   attrcsr]   r^   r_   eposr`   ra   attrtrcstrals               r   trim_text_attr_csrq      s     '5aTIw'1#D$)tT+Fr4'DtAv'FRG-D)-t%6B7,4,GMM(#d4o5i !"($0 0r4   c                 J    d}|dk  ry| D ]  \  }}||z   |kD  r|c S ||z  } y)z-
    Return the attribute at offset pos.
    r   Nr3   )rlerd   xarc   s        r   rh   rh      sD     	
A
Qw 3S53;H	S r4   c                     g }d}| D ]P  \  }}|r||k\  r||z  }||z  }||z  }||z  }d}||k\  r |S ||z   |kD  r||z
  }||z  }|j                  ||f       R |S )z$Return a sub segment of an rle list.r   rD   )rs   startendlrt   ru   rc   s          r   rg   rg     s    
A	A 3|SJA5LCE8
 H	 S53;a%C	S	1c( Hr4   c                 p    d}| D ].  }t        |      t        k(  sJ t        |              |\  }}||z  }0 |S )z]
    Return the number of characters covered by a run length
    encoded attribute list.
    r   )r8   tuplerepr)rs   rc   vru   rs        r   rle_lenr     sL     C Aw%*c*1q Jr4   c                 d    |\  }}| s	||fg| dd y| d   \  }}||k(  r|||z   f| d<   y||fg| dd y)z
    Append (a, r) (unpacked from *a_r*) to BEGINNING of rle.
    Merge with first run when possible

    MODIFIES rle parameter contents. Returns None.
    Nr   r3   )rs   a_rru   r   rp   rc   s         r   ri   ri   $  sU     DAqa&Aa&C7AYCFAxC!Hr4   c                 t    |\  }}| r| d   d   |k7  r| j                  ||f       y| d   \  }}|||z   f| d<   y)z
    Append (a, r) (unpacked from *a_r*) to the rle list rle.
    Merge with last run when possible.

    MODIFIES rle parameter contents. Returns None.
    r   Nrw   )rs   r   ru   r   lalrs         r   rF   rF   6  sO     DAq#b'!*/

QqEGEBr"Q$iCGr4   c                 8    |syt        | |d          | |dd z  } y)z
    Append attribute list rle2 to rle.
    Merge last run of rle with first run of rle2 when possible.

    MODIFIES attr parameter contents. Returns None.
    Nr   r   rF   )rs   rle2s     r   rle_join_modifyr   D  s'     c47#48OCr4   c                    dx}}| r|sg S | d   \  }}|d   \  }}g }|rm|rkt        ||      }	t        |||f|	f       ||	z  }|dk(  r|t        |       k  r| |   \  }}|dz  }||	z  }|dk(  r|t        |      k  r||   \  }}|dz  }|r|rk|S )a  
    Merge the runs of rle1 and rle2 like this:
    eg.
    rle1 = [ ("a", 10), ("b", 5) ]
    rle2 = [ ("Q", 5), ("P", 10) ]
    rle_product: [ (("a","Q"), 5), (("a","P"), 5), (("b","P"), 5) ]

    rle1 and rle2 are assumed to cover the same total run.
    r   r   )minrF   rE   )
rle1r   i1i2a1r1a2r2rz   r   s
             r   rle_productr   P  s     KBtBY!WFB!WFB
A
BK12wqk+
a7r3t9}"XFB!GB
a7r3t9}"XFB!GB  Hr4   c                 d    g }g }| D ]$  \  \  }}}t        |||f       t        |||f       & ||fS )z!
    Inverse of rle_product.
    r   )rs   r   r   r   r   r   s         r   
rle_factorr   n  sM     DD +R!4"a*4"a*+ :r4   c                       e Zd Zy)TagMarkupExceptionN)__name__
__module____qualname__r3   r4   r   r   r   z  s    r4   r   c                 p    t        | d      \  }}|d   dd j                  |      }|r|d   d   |d= ||fS )z:Return (text string, attribute list) for tagmarkup passed.Nr   r   )_tagmarkup_recurserH   )tmtlrp   rZ   s       r   decompose_tagmarkupr   |  sL      D)FBa5!9>>"D	bfQirF8Or4   c                    t        |       t        k(  rLg }g }| D ]?  }t        ||      \  }}|r"|d   \  }}|d   \  }	}
||	k(  r|	||
z   f|d<   |d= ||z  }||z  }A ||fS t        |       t        k(  r-t	        |       dk7  rt        d|       | \  }}t        ||      S t        | t        t        fz         st        d| z        | g|t	        |       fgfS )zsReturn (text list, attribute list) for tagmarkup passed.

    tm -- tagmarkup
    attr -- current attribute or Noner   r      z3Tuples must be in the form (attribute, tagmarkup): zInvalid markup element: %r)	r8   listr   r|   rE   r   rB   r   r   )r   rk   rtlralelementr   rp   	last_attrlast_runtop_attrtop_runs              r   r   r     s    Bx4 
	G'$8FB&)"g#	8$&qE!'('G);<CG22IC2IC
	 CxBx5r7a<$`b%deeg!7D22b*x/0 !=!BCC 44R/"""r4   c                 x    t        |       t        k(  xr' t        |       dk(  xr | d   j                  d      dk\  S )N   r   mouse)r8   r|   rE   findevs    r   is_mouse_eventr     s5    8uFR!F1

70CQ0FFr4   c                 *    | j                  d      dk\  S )Npressr   )r   r   s    r   is_mouse_pressr     s    777Qr4   c                   "     e Zd ZdZ fdZ xZS )	MetaSuperzadding .__superc                     t         t        |   |||       t        | d|z        rt	        d      t        | d|z  t        |              y )Nz
_%s__superz/Class has same name as one of its super classes)superr   __init__hasattrAttributeErrorsetattr)clsnamebasesd	__class__s       r   r   zMetaSuper.__init__  sF    i&tUA63t+, !RSS\D(%*5r4   )r   r   r   __doc__r   __classcell__)r   s   @r   r   r     s    6 6r4   r   c                 P    t        | |dz
  z  dz  |dz
  z         }|dz
  dz  }||z  S )aW  
    Scale val in the range [0, val_range-1] to an integer in the range
    [0, out_range-1].  This implementation uses the "round-half-up" rounding
    method.

    >>> "%x" % int_scale(0x7, 0x10, 0x10000)
    '7777'
    >>> "%x" % int_scale(0x5f, 0x100, 0x10)
    '6'
    >>> int_scale(2, 6, 101)
    40
    >>> int_scale(1, 3, 4)
    2
    r   r   )int)val	val_range	out_rangenumdems        r   	int_scaler     s=     cYq[!A%15
6CaK1C#:r4   c                   "    e Zd ZdZd Zd Zd Zy)StoppingContextzContext manager that calls ``stop`` on a given object on exit.  Used to
    make the ``start`` method on `MainLoop` and `BaseScreen` optionally act as
    context managers.
    c                     || _         y N)_wrapped)selfwrappeds     r   r   zStoppingContext.__init__  s	    r4   c                     | S r   r3   )r   s    r   	__enter__zStoppingContext.__enter__  s    r4   c                 8    | j                   j                          y r   )r   stop)r   exc_infos     r   __exit__zStoppingContext.__exit__  s    r4   N)r   r   r   r   r   r   r   r3   r4   r   r   r     s     r4   r   )/
__future__r   r   urwidr   urwid.compatr   r   r   rA   r)   rY   
calc_widthis_wide_charmove_next_charmove_prev_charwithin_double_byter   localsr   r,   r+   r0   r5   rU   rW   re   rq   rh   rg   r   ri   rF   r   r   r   	Exceptionr   r   r   r   r   r8   r   r   objectr   r3   r4   r   <module>r      s$  . 0  5 5 ?? &&  
$$((((00 , fh&')l1  D(8z  !<.>0*, $
<	 * )
##NG
6 6*f r4   