
    ;OOf2                         d dl mZmZ d dlZd dlZ G d de      Zd Z G d de      Z	 G d d	e      Z
 e
       Zej                  Zej                  Zej                   Zej$                  Zej(                  Zy)
    )divisionprint_functionNc                   "     e Zd ZdZ fdZ xZS )MetaSignalszl
    register the list of signals in the class variable signals,
    including signals in superclasses.
    c           	      >   |j                  dg       }| j                  D ]  }|j                  t        |dg                t	        t        |D cg c]  }|d f c}      j                               }||d<   t        | |       t        t        | +  |||       y c c}w )Nsignals)get	__bases__extendgetattrlistdictkeysregister_signalsuperr   __init__)clsnamebasesdr   
superclassx	__class__s          N/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/urwid/signals.pyr   zMetaSignals.__init__!   s    %%	2&-- 	?JNN7:y"=>	?tw7!aX78==?@)W%k3(ua8 8s   B)__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      s    9 9    r   c                 P    t        | |      rt        | |      S t        | ||       |S N)hasattrr   setattr)objr   values      r   setdefaultattrr'   *   s*    sDsD!!CuLr    c                       e Zd ZdZg Zy)KeyzX
    Minimal class, whose only purpose is to produce objects with a
    unique hash
    N)r   r   r   r   	__slots__ r    r   r)   r)   1   s     Ir    r)   c                   F    e Zd ZdZd Zd ZddZddZddZd Z	d	 Z
d
 Zy)Signals_urwid_signalsc                     i | _         y r"   
_supported)selfs    r   r   zSignals.__init__;   s	    r    c                 "    || j                   |<   y)a  
        :param sig_class: the class of an object that will be sending signals
        :type sig_class: class
        :param signals: a list of signals that may be sent, typically each
                        signal is represented by a string
        :type signals: signal names

        This function must be called for a class before connecting any
        signal callbacks or emitting any signals from that class' objects
        Nr0   )r2   sig_clsr   s      r   registerzSignals.register>   s     $+ r    Nc                 t    |j                   } j                  j                  |g       vrt        dd|      t	               t        | j                  i       }|j                  g       }	t        j                  |       fd}
 j                  |||
      }|	j                  |||f       S )a7  
        :param obj: the object sending a signal
        :type obj: object
        :param name: the signal to listen for, typically a string
        :type name: signal name
        :param callback: the function to call when that signal is sent
        :type callback: function
        :param user_arg: deprecated additional argument to callback (appended
                         after the arguments passed when the signal is
                         emitted). If None no arguments will be added.
                         Don't use this argument, use user_args instead.
        :param weak_args: additional arguments passed to the callback
                          (before any arguments passed when the signal
                          is emitted and before any user_args).

                          These arguments are stored as weak references
                          (but converted back into their original value
                          before passing them to callback) to prevent
                          any objects referenced (indirectly) from
                          weak_args from being kept alive just because
                          they are referenced by this signal handler.

                          Use this argument only as a keyword argument,
                          since user_arg might be removed in the future.
        :type weak_args: iterable
        :param user_args: additional arguments to pass to the callback,
                          (before any arguments passed when the signal
                          is emitted but after any weak_args).

                          Use this argument only as a keyword argument,
                          since user_arg might be removed in the future.
        :type user_args: iterable

        When a matching signal is sent, callback will be called. The
        arguments it receives will be the user_args passed at connect
        time (as individual arguments) followed by all the positional
        parameters sent with the signal.

        As an example of using weak_args, consider the following snippet:

        >>> import urwid
        >>> debug = urwid.Text('')
        >>> def handler(widget, newtext):
        ...    debug.set_text("Edit widget changed to %s" % newtext)
        >>> edit = urwid.Edit('')
        >>> key = urwid.connect_signal(edit, 'change', handler)

        If you now build some interface using "edit" and "debug", the
        "debug" widget will show whatever you type in the "edit" widget.
        However, if you remove all references to the "debug" widget, it
        will still be kept alive by the signal handler. This because the
        signal handler is a closure that (implicitly) references the
        "edit" widget. If you want to allow the "debug" widget to be
        garbage collected, you can create a "fake" or "weak" closure
        (it's not really a closure, since it doesn't reference any
        outside variables, so it's just a dynamic function):

        >>> debug = urwid.Text('')
        >>> def handler(weak_debug, widget, newtext):
        ...    weak_debug.set_text("Edit widget changed to %s" % newtext)
        >>> edit = urwid.Edit('')
        >>> key = urwid.connect_signal(edit, 'change', handler, weak_args=[debug])

        Here the weak_debug parameter in print_debug is the value passed
        in the weak_args list to connect_signal. Note that the
        weak_debug value passed is not a weak reference anymore, the
        signals code transparently dereferences the weakref parameter
        before passing it to print_debug.

        Returns a key associated by this signal handler, which can be
        used to disconnect the signal later on using
        urwid.disconnect_signal_by_key. Alternatively, the signal
        handler can also be disconnected by calling
        urwid.disconnect_signal, which doesn't need this key.
        zNo such signal z for object c                 p            }|r	 t        |j                  i          = y y # t        $ r Y y w xY wr"   )r   _signal_attrKeyError)weakrefokeyr   obj_weakr2   s     r   weakref_callbackz)Signals.connect.<locals>.weakref_callback   sG    
A4#4#4b9$?D    s   ) 	55)r   r1   r	   	NameErrorr)   r'   r8   
setdefaultr:   ref_prepare_user_argsappend)r2   r%   r   callbackuser_arg	weak_args	user_argsr4   r   handlersr>   r<   r=   s   ` `        @@r   connectzSignals.connectK   s    Z --t**7B77s   e d&7&7<%%dB/ ;;s#	 ++IyBRS	h)<=
r    c                 j    |xs g D cg c]  }t        j                  ||       c}|xs g z   S c c}w r"   )r:   rA   )r2   rF   rG   rD   as        r   rB   zSignals._prepare_user_args   s/    3<?DQAx(D	UWXXDs   0c                     t        || j                  i       }||vry||   }| j                  ||      }|D ]%  }	|	dd |||fk(  s| j                  |||	d         c S  y)aI  
        :param obj: the object to disconnect the signal from
        :type obj: object
        :param name: the signal to disconnect, typically a string
        :type name: signal name
        :param callback: the callback function passed to connect_signal
        :type callback: function
        :param user_arg: the user_arg parameter passed to connect_signal
        :param weak_args: the weak_args parameter passed to connect_signal
        :param user_args: the weak_args parameter passed to connect_signal

        This function will remove a callback from the list connected
        to a signal with connect_signal(). The arguments passed should
        be exactly the same as those passed to connect_signal().

        If the callback is not connected or already disconnected, this
        function will simply do nothing.
        N   r   )r'   r8   rB   disconnect_by_key)
r2   r%   r   rD   rE   rF   rG   r   rH   hs
             r   
disconnectzSignals.disconnect   s    & !d&7&7<w4= ++IyA	  	?Au8Y77--c41>>	?r    c                     t        || j                  i       }|j                  |g       }|D cg c]  }|d   |us| c}|dd yc c}w )an  
        :param obj: the object to disconnect the signal from
        :type obj: object
        :param name: the signal to disconnect, typically a string
        :type name: signal name
        :param key: the key for this signal handler, as returned by
                    connect_signal().
        :type key: Key

        This function will remove a callback from the list connected
        to a signal with connect_signal(). The key passed should be the
        value returned by connect_signal().

        If the callback is not connected or already disconnected, this
        function will simply do nothing.
        r   N)r'   r8   r	   )r2   r%   r   r<   r   rH   rO   s          r   rN   zSignals.disconnect_by_key   sI    " !d&7&7<;;tR("*>Qad#oq>>s
   AAc                     d}t        || j                  i       }|j                  |g       }|D ]  \  }}}	}
|| j                  ||	|
|      z  }  |S )a  
        :param obj: the object sending a signal
        :type obj: object
        :param name: the signal to send, typically a string
        :type name: signal name
        :param \*args: zero or more positional arguments to pass to the signal
                      callback functions

        This function calls each of the callbacks connected to this signal
        with the args arguments as positional parameters.

        This function returns True if any of the callbacks returned True.
        F)r   r8   r	   _call_callback)r2   r%   r   argsresultr   rH   r<   rD   rE   rG   s              r   emitzSignals.emit   sg     #t00"5;;tR(2: 	O.C8Yd))(HiNNF	Or    c                     |rQg }|D ]8  }t        |t        j                        r |       }| y|j                  |       : |j	                  |       n|}|t        j                  ||f      }t         ||       S )NF)
isinstancer:   ReferenceTyperC   r   	itertoolschainbool)r2   rD   rE   rG   	emit_argsargs_to_passargs          r   rS   zSignals._call_callback  s    L  )c7#8#89%C{  %##C() 	* %L $??<(ELHl+,,r    )NNNr"   )r   r   r   r8   r   r5   rI   rB   rP   rN   rV   rS   r+   r    r   r-   r-   8   s3    #L+n`Y
 ?D?**-r    r-   )
__future__r   r   rZ   r:   typer   r'   objectr)   r-   _signalsrV   emit_signalr5   r   rI   connect_signalrP   disconnect_signalrN   disconnect_signal_by_keyr+   r    r   <module>rh      s|   , 0  9$ 9& o-f o-b 9mm##!!'' #55 r    