
    ;OOfC                     v    d dl mZmZ d dlmZmZ d Z G d de      Z G d de      Z	d Z
ed	k(  r e
        y
y
)    )divisionprint_function)PYTHON3xrangec                       fd}|S )Nc                 @     | g|i |}| j                          |S N	_modified)selfargskwargsrvalfns       U/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/urwid/monitored_list.pycall_modified_wrapperz-_call_modified.<locals>.call_modified_wrapper   s&    $(((     )r   r   s   ` r   _call_modifiedr      s     ! r   c                   ~   e Zd ZdZd Zd Zd Z eej                        Z	 eej                        Z
es eej                        Z eej                        Z eej                        Z eej                        Z eej                         Zes eej"                        Z eej$                        Z eej&                        Z eej(                        Z eej*                        Z eej,                        Z eej.                        Z eej0                        Z eed      r eej4                        Zyy)MonitoredListz
    This class can trigger a callback any time its contents are changed
    with the usual list operations append, extend, etc.
    c                      y r	   r   r   s    r   r   zMonitoredList._modified'       r   c                     || _         y)a;  
        Assign a callback function with no parameters that is called any
        time the list is modified.  Callback's return value is ignored.

        >>> import sys
        >>> ml = MonitoredList([1,2,3])
        >>> ml.set_modified_callback(lambda: sys.stdout.write("modified\n"))
        >>> ml
        MonitoredList([1, 2, 3])
        >>> ml.append(10)
        modified
        >>> len(ml)
        4
        >>> ml += [11, 12, 13]
        modified
        >>> ml[:] = ml[:2] + ml[-2:]
        modified
        >>> ml
        MonitoredList([1, 2, 12, 13])
        Nr
   r   callbacks     r   set_modified_callbackz#MonitoredList.set_modified_callback*   s    * "r   c                 L    | j                   j                  dt        |       dS )N())	__class____name__listr   s    r   __repr__zMonitoredList.__repr__A   s    >>22DJ??r   clearN)r#   
__module____qualname____doc__r   r   r%   r   r$   __add____delitem__r   __delslice____iadd____imul____rmul____setitem____setslice__appendextendinsertpopremovereversesorthasattrr&   r   r   r   r   r   "   s   ".@ T\\*G !1!12K%d&7&78dmm,Hdmm,Hdmm,H !1!12K%d&7&78DKK(FDKK(FDKK(F

"CDKK(FT\\*G$))$DtWtzz* r   r   c                       e Zd ZdZ fdZd Zd Zd Z eeed      Z	d Z
d	 Zd
 Zd ZddZ fdZ fdZesd Zd Z fdZ fdZ fdZ fdZd fd	Z fdZ fdZ fdZ eed      r	 fdZ xZS  xZS )MonitoredFocusListz
    This class can trigger a callback any time its contents are modified,
    before and/or after modification, and any time the focus index is changed.
    c                 n    |j                  dd      }t        t        |   |i | || _        d | _        y)a  
        This is a list that tracks one item as the focus item.  If items
        are inserted or removed it will update the focus.

        >>> ml = MonitoredFocusList([10, 11, 12, 13, 14], focus=3)
        >>> ml
        MonitoredFocusList([10, 11, 12, 13, 14], focus=3)
        >>> del(ml[1])
        >>> ml
        MonitoredFocusList([10, 12, 13, 14], focus=2)
        >>> ml[:2] = [50, 51, 52, 53]
        >>> ml
        MonitoredFocusList([50, 51, 52, 53, 13, 14], focus=4)
        >>> ml[4] = 99
        >>> ml
        MonitoredFocusList([50, 51, 52, 53, 99, 14], focus=4)
        >>> ml[:] = []
        >>> ml
        MonitoredFocusList([], focus=None)
        focusr   c                      y r	   r   )mlindices	new_itemss      r   <lambda>z-MonitoredFocusList.__init__.<locals>.<lambda>x   s    r   N)r5   superr;   __init___focus_focus_modified)r   arglargdr=   r"   s       r   rD   zMonitoredFocusList.__init__^   s9    * !$ $0$?$?Br   c                 f    | j                   j                  dt        |       d| j                  dS )Nr    z, focus=r!   )r"   r#   r$   r=   r   s    r   r%   zMonitoredFocusList.__repr__z   s%    NN##T$Z= 	=r   c                      | sy| j                   S )z
        Return the index of the item "in focus" or None if
        the list is empty.

        >>> MonitoredFocusList([1,2,3], focus=2)._get_focus()
        2
        >>> MonitoredFocusList()._get_focus()
        N)rE   r   s    r   
_get_focuszMonitoredFocusList._get_focus~   s     {{r   c                     | sd| _         y|dk  s|t        |       k\  rt        d|      |t        |      k7  rt        d|      t        |      }|| j                   k7  r| j	                  |       || _         y)a  
        index -- index into this list, any index out of range will
            raise an IndexError, except when the list is empty and
            the index passed is ignored.

        This function may call self._focus_changed when the focus
        is modified, passing the new focus position to the
        callback just before changing the old focus setting.
        That method may be overridden on the
        instance with set_focus_changed_callback().

        >>> ml = MonitoredFocusList([9, 10, 11])
        >>> ml._set_focus(2); ml._get_focus()
        2
        >>> ml._set_focus(0); ml._get_focus()
        0
        >>> ml._set_focus(-2)
        Traceback (most recent call last):
        ...
        IndexError: focus index is out of range: -2
        r   Nzfocus index is out of range: zinvalid focus index: )rE   len
IndexErrorint_focus_changed)r   indexs     r   
_set_focuszMonitoredFocusList._set_focus   su    , DK19T*%IJJCJ%ABBE
DKK&r   z
        Get/set the focus index.  This value is read as None when the list
        is empty, and may only be set to a value between 0 and len(self)-1
        or an IndexError will be raised.
        )docc                      y r	   r   )r   	new_focuss     r   rP   z!MonitoredFocusList._focus_changed   r   r   c                     || _         y)a  
        Assign a callback to be called when the focus index changes
        for any reason.  The callback is in the form:

        callback(new_focus)
        new_focus -- new focus index

        >>> import sys
        >>> ml = MonitoredFocusList([1,2,3], focus=1)
        >>> ml.set_focus_changed_callback(lambda f: sys.stdout.write("focus: %d\n" % (f,)))
        >>> ml
        MonitoredFocusList([1, 2, 3], focus=1)
        >>> ml.append(10)
        >>> ml.insert(1, 11)
        focus: 2
        >>> ml
        MonitoredFocusList([1, 11, 2, 3, 10], focus=2)
        >>> del ml[:2]
        focus: 0
        >>> ml[:0] = [12, 13, 14]
        focus: 3
        >>> ml.focus = 5
        focus: 5
        >>> ml
        MonitoredFocusList([12, 13, 14, 2, 3, 10], focus=5)
        N)rP   r   s     r   set_focus_changed_callbackz-MonitoredFocusList.set_focus_changed_callback   s    6 'r   c                      y r	   r   )r   r@   rA   s      r   _validate_contents_modifiedz.MonitoredFocusList._validate_contents_modified   s    r   c                     || _         y)a  
        Assign a callback function to handle validating changes to the list.
        This may raise an exception if the change should not be performed.
        It may also return an integer position to be the new focus after the
        list is modified, or None to use the default behaviour.

        The callback is in the form:

        callback(indices, new_items)
        indices -- a (start, stop, step) tuple whose range covers the
            items being modified
        new_items -- an iterable of items replacing those at range(*indices),
            empty if items are being removed, if step==1 this list may
            contain any number of items
        N)rY   r   s     r   set_validate_contents_modifiedz1MonitoredFocusList.set_validate_contents_modified   s      ,4(r   c                    t        |      }|j                  t        |             x\  }}}}t        t        t        |             }| j	                  ||      }	|	|	S | j
                  }	|dk(  r$||z   |	cxk  r|k  rn n|}	||	k  rN|	|||z
  z
  z  }	nB|s@|	t        |||      v r|	dz  }	|	t        t        t        |t        |	|      |                  z  }	t        |	t        |       |z   |z
  dz
        S )a  
        Default behaviour is to move the focus to the item following
        any removed items, unless that item was simply replaced.

        Failing that choose the last item in the list.

        returns focus position for after change is applied
           )rM   r@   r$   r   rY   rE   min)
r   slcrA   num_new_itemsstartstopstepr@   num_removedr=   s
             r   "_adjust_focus_on_contents_modifiedz5MonitoredFocusList._adjust_focus_on_contents_modified   s    I&)kk#d)&<<tTG$vw/0100)DL19}$44u}$,77 !F5$55QJE T&E40@$"GHII5#d)m3kA1DEEr   c                     t        |t              r| j                  |      }n"| j                  t        ||dz   xs d            }t        t        |   |      }| j                  |       |S )a  
        >>> ml = MonitoredFocusList([0,1,2,3,4], focus=2)
        >>> del ml[3]; ml
        MonitoredFocusList([0, 1, 2, 4], focus=2)
        >>> del ml[-1]; ml
        MonitoredFocusList([0, 1, 2], focus=2)
        >>> del ml[0]; ml
        MonitoredFocusList([1, 2], focus=1)
        >>> del ml[1]; ml
        MonitoredFocusList([1], focus=0)
        >>> del ml[0]; ml
        MonitoredFocusList([], focus=None)
        >>> ml = MonitoredFocusList([5,4,6,4,5,4,6,4,5], focus=4)
        >>> del ml[1::2]; ml
        MonitoredFocusList([5, 6, 5, 6, 5], focus=2)
        >>> del ml[::2]; ml
        MonitoredFocusList([6, 6], focus=1)
        >>> ml = MonitoredFocusList([0,1,2,3,4,6,7], focus=2)
        >>> del ml[-2:]; ml
        MonitoredFocusList([0, 1, 2, 3, 4], focus=2)
        >>> del ml[-4:-2]; ml
        MonitoredFocusList([0, 3, 4], focus=1)
        >>> del ml[:]; ml
        MonitoredFocusList([], focus=None)
        r]   N)
isinstanceslicere   rC   r;   r+   rR   )r   yr=   r   r"   s       r   r+   zMonitoredFocusList.__delitem__  sf    4 a;;A>E;;E!!t= E':1=r   c                     t        |t              r| j                  ||      }n$| j                  t        ||dz   xs d      |g      }t        t        |   ||      }| j                  |       |S )aj  
        >>> def modified(indices, new_items):
        ...     print("range%r <- %r" % (indices, new_items))
        >>> ml = MonitoredFocusList([0,1,2,3], focus=2)
        >>> ml.set_validate_contents_modified(modified)
        >>> ml[0] = 9
        range(0, 1, 1) <- [9]
        >>> ml[2] = 6
        range(2, 3, 1) <- [6]
        >>> ml.focus
        2
        >>> ml[-1] = 8
        range(3, 4, 1) <- [8]
        >>> ml
        MonitoredFocusList([9, 1, 6, 8], focus=2)
        >>> ml[1::2] = [12, 13]
        range(1, 4, 2) <- [12, 13]
        >>> ml[::2] = [10, 11]
        range(0, 4, 2) <- [10, 11]
        >>> ml[-3:-1] = [21, 22, 23]
        range(1, 3, 1) <- [21, 22, 23]
        >>> ml
        MonitoredFocusList([10, 21, 22, 23, 13], focus=2)
        >>> ml[:] = []
        range(0, 5, 1) <- []
        >>> ml
        MonitoredFocusList([], focus=None)
        r]   N)rg   rh   re   rC   r;   r0   rR   )r   iri   r=   r   r"   s        r   r0   zMonitoredFocusList.__setitem__1  sk    : a;;AqAE;;E!QqS[D<QTUSVWE':1a@r   c                 8    | j                  t        ||            S r	   )r+   rh   )r   rk   js      r   r,   zMonitoredFocusList.__delslice__W  s    ##E!AJ//r   c                 :    | j                  t        ||      |      S r	   )r0   rh   )r   rk   rm   ri   s       r   r1   zMonitoredFocusList.__setslice__Z  s    ##E!QK33r   c                    |dkD  r>| j                  t        t        |       t        |             t        |       |dz
  z        }n$| j                  t        dt        |                   }t        t
        |   |      }| j                  |       |S )a  
        >>> def modified(indices, new_items):
        ...     print("range%r <- %r" % (indices, list(new_items)))
        >>> ml = MonitoredFocusList([0,1,2], focus=2)
        >>> ml.set_validate_contents_modified(modified)
        >>> ml *= 3
        range(3, 3, 1) <- [0, 1, 2, 0, 1, 2]
        >>> ml
        MonitoredFocusList([0, 1, 2, 0, 1, 2, 0, 1, 2], focus=2)
        >>> ml *= 0
        range(0, 9, 1) <- []
        >>> print(ml.focus)
        None
        r   r]   )re   rh   rM   r$   rC   r;   r.   rR   )r   nr=   r   r"   s       r   r.   zMonitoredFocusList.__imul__]  s}     q5;;c$iT+T$Z1-=?E ;;E!SY<OPE'7:r   c                     | j                  t        t        |       t        |             |g      }t        t        |   |      }| j                  |       |S )a  
        >>> def modified(indices, new_items):
        ...     print("range%r <- %r" % (indices, new_items))
        >>> ml = MonitoredFocusList([0,1,2], focus=2)
        >>> ml.set_validate_contents_modified(modified)
        >>> ml.append(6)
        range(3, 3, 1) <- [6]
        )re   rh   rM   rC   r;   r2   rR   )r   itemr=   r   r"   s       r   r2   zMonitoredFocusList.appendu  sN     77#d)SY'$1'5d;r   c                     | j                  t        t        |       t        |             |      }t        t        |   |      }| j                  |       |S )a,  
        >>> def modified(indices, new_items):
        ...     print("range%r <- %r" % (indices, list(new_items)))
        >>> ml = MonitoredFocusList([0,1,2], focus=2)
        >>> ml.set_validate_contents_modified(modified)
        >>> ml.extend((6,7,8))
        range(3, 3, 1) <- [6, 7, 8]
        )re   rh   rM   rC   r;   r3   rR   )r   itemsr=   r   r"   s       r   r3   zMonitoredFocusList.extend  sL     77#d)SY'0'5e<r   c                     | j                  t        ||      |g      }t        t        |   ||      }| j                  |       |S )aS  
        >>> ml = MonitoredFocusList([0,1,2,3], focus=2)
        >>> ml.insert(-1, -1); ml
        MonitoredFocusList([0, 1, 2, -1, 3], focus=2)
        >>> ml.insert(0, -2); ml
        MonitoredFocusList([-2, 0, 1, 2, -1, 3], focus=3)
        >>> ml.insert(3, -3); ml
        MonitoredFocusList([-2, 0, 1, -3, 2, -1, 3], focus=4)
        )re   rh   rC   r;   r4   rR   )r   rQ   rr   r=   r   r"   s        r   r4   zMonitoredFocusList.insert  sH     77eU8KF'5eTBr   c                     | j                  t        ||dz   xs d            }t        t        |   |      }| j                  |       |S )a  
        >>> ml = MonitoredFocusList([-2,0,1,-3,2,3], focus=4)
        >>> ml.pop(3); ml
        -3
        MonitoredFocusList([-2, 0, 1, 2, 3], focus=3)
        >>> ml.pop(0); ml
        -2
        MonitoredFocusList([0, 1, 2, 3], focus=2)
        >>> ml.pop(-1); ml
        3
        MonitoredFocusList([0, 1, 2], focus=2)
        >>> ml.pop(2); ml
        2
        MonitoredFocusList([0, 1], focus=1)
        r]   N)re   rh   rC   r;   r5   rR   )r   rQ   r=   r   r"   s       r   r5   zMonitoredFocusList.pop  sL      77e!GOt9 '259r   c                     | j                  |      }| j                  t        ||dz   xs d            }t        t        |   |      }| j                  |       |S )aF  
        >>> ml = MonitoredFocusList([-2,0,1,-3,2,-1,3], focus=4)
        >>> ml.remove(-3); ml
        MonitoredFocusList([-2, 0, 1, 2, -1, 3], focus=3)
        >>> ml.remove(-2); ml
        MonitoredFocusList([0, 1, 2, -1, 3], focus=2)
        >>> ml.remove(3); ml
        MonitoredFocusList([0, 1, 2, -1], focus=2)
        r]   N)rQ   re   rh   rC   r;   r6   rR   )r   valuerQ   r=   r   r"   s        r   r6   zMonitoredFocusList.remove  sZ     

5!77e!GOt9 '5e<r   c                     t         t        |          }| j                  t	        dt        |       | j                  z
  dz
               |S )z
        >>> ml = MonitoredFocusList([0,1,2,3,4], focus=1)
        >>> ml.reverse(); ml
        MonitoredFocusList([4, 3, 2, 1, 0], focus=3)
        r   r]   )rC   r;   r7   rR   maxrM   rE   )r   r   r"   s     r   r7   zMonitoredFocusList.reverse  s?     '68As4y4;;6:;<r   c                     | sy| | j                      }t        t        |   di |}| j	                  | j                  |             |S )z
        >>> ml = MonitoredFocusList([-2,0,1,-3,2,-1,3], focus=4)
        >>> ml.sort(); ml
        MonitoredFocusList([-3, -2, -1, 0, 1, 2, 3], focus=5)
        Nr   )rE   rC   r;   r8   rR   rQ   )r   r   rx   r   r"   s       r   r8   zMonitoredFocusList.sort  sH     T[[!'3=f=

5)*r   r&   c                     | j                  t        dd            }t        t        |          }| j                  |       |S Nr   )re   rh   rC   r;   r&   rR   )r   r=   r   r"   s      r   r&   zMonitoredFocusList.clear  s:    ;;E!QKHE+T8:DOOE"Kr   )r   )) r#   r'   r(   r)   rD   r%   rK   rR   propertyr=   rP   rW   rY   r[   re   r+   r0   r   r,   r1   r.   r2   r3   r4   r5   r6   r7   r8   r9   r$   r&   __classcell__)r"   s   @r   r;   r;   Y   s    C8= D Z 2 E':4$"FL!F#J 	0	40 ," tW	 	 r   r;   c                  ,    dd l } | j                          y r}   )doctesttestmod)r   s    r   _testr     s    OOr   __main__N)
__future__r   r   urwid.compatr   r   r   r$   r   r;   r   r#   r   r   r   <module>r      sG   , 0 (!4+D 4+nM Mf Z	G r   