def connect(receiver, signal=Any, sender=Any, weak=1):
    """Connect receiver to sender for signal.
    
    If sender is Any, receiver will receive signal from any sender.
    If signal is Any, receiver will receive any signal from sender.
    If sender is None, receiver will receive signal from anonymous.
    If signal is Any and sender is None, receiver will receive any 
        signal from anonymous.
    If signal is Any and sender is Any, receiver will receive any 
        signal from any sender.
    If weak is true, weak references will be used."""
    if signal is None:
        raise DispatcherError, 'signal cannot be None'
    if signal is not Any:
        signal = str(signal)
    if weak: receiver = safeRef(receiver)
    senderkey = id(sender)
    signals = {}
    if connections.has_key(senderkey):
        signals = connections[senderkey]
    else:
        connections[senderkey] = signals
        # Keep track of senders for cleanup.
        if sender not in (None, Any):
            def remove(object, senderkey=senderkey):
                _removeSender(senderkey=senderkey)
            # Skip objects that can not be weakly referenced, which means
            # they won't be automatically cleaned up, but that's too bad.
            try:
                weakSender = weakref.ref(sender, remove)
                senders[senderkey] = weakSender
            except:
                pass
    receivers = []
    if signals.has_key(signal):
        receivers = signals[signal]
    else:
        signals[signal] = receivers
    try: receivers.remove(receiver)
    except ValueError: pass
    receivers.append(receiver)
Connect receiver to sender for signal.
    
    If sender is Any, receiver will receive signal from any sender.
    If signal is Any, receiver will receive any signal from sender.
    If sender is None, receiver will receive signal from anonymous.
    If signal is Any and sender is None, receiver will receive any 
        signal from anonymous.
    If signal is Any and sender is Any, receiver will receive any 
        signal from any sender.
    If weak is true, weak references will be used.
recipes/Python/87056_Global_Signal_Dispatching/recipe-87056.py