Exemplo n.º 1
0
        def outgoing_tube_factory(connecting_fount, connecting_drain):
            client_filter = or_command_filter(self.client_allowed, self.client_allowed_prefixes)
            client_sieve = tubeFilter(client_filter.is_allowed)
            client_replace = replacerTubeFactory(self.client_replacements)
            proxy_client_sieve = series(bytesToLines(), client_replace, client_sieve, linesToBytes())

            client_fanout = Out()
            client_err_fount = client_fanout.newFount()
            client_sieve_fount = client_fanout.newFount()
            client_sieve_fount.flowTo(proxy_client_sieve).flowTo(connecting_drain)

            server_fanin = In()
            server_fanin.fount.flowTo(display_received("server")).flowTo(listening_drain)
            #server_fanin.fount.flowTo(listening_drain)
            server_fanin_proxy_drain = server_fanin.newDrain()
            server_fanin_err_drain = server_fanin.newDrain()

            error_sieve = tubeFilter(lambda item: not client_filter.is_allowed(item))
            replace_with_error_tube = lambda err_message: tubeMap(lambda item: err_message)
            proxy_error_sieve = series(bytesToLines(), error_sieve, replace_with_error_tube(self.filtered_msg), linesToBytes())
            client_err_fount.flowTo(series(proxy_error_sieve, server_fanin_err_drain))

            server_filter = or_command_filter(self.server_allowed, self.server_allowed_prefixes)
            server_sieve = tubeFilter(server_filter.is_allowed)
            proxy_server_sieve = series(bytesToLines(), server_sieve, linesToBytes())

            connecting_fount.flowTo(proxy_server_sieve).flowTo(server_fanin_proxy_drain)
            listening_fount.flowTo(series(display_received("client"), client_fanout.drain))
Exemplo n.º 2
0
class Channel(object):
    """
    A chat room.
    """
    def __init__(self, name):
        self._name = name
        self._out = Out()
        self._in = In()
        self._in.fount.flowTo(self._out.drain)


    def participate(self, participant):
        """
        Create a new drain of messages going to this channel and a new fount of
        messages coming from this channel, for the given participant.

        @param participant: the name of the participant joining.

        @return: a 2-tuple of (new fount, new drain)
        """
        @receiver(IMapping, IMapping,
                  name="->addSender({}, {})".format(participant.name,
                                                    self._name))
        def addSender(item):
            yield dict(item, sender=participant.name, channel=self._name)

        return (self._out.newFount(),
                series(addSender, self._in.newDrain()))
Exemplo n.º 3
0
class Channel(object):
    def __init__(self, name):
        self._name = name
        self._out = Out()
        self._in = In()
        self._in.fount.flowTo(self._out.drain)

    def participate(self, participant):
        @receiver(IMapping, IMapping)
        def addSender(item):
            yield dict(item, sender=participant, channel=self._name)

        return (self._out.newFount(), series(addSender, self._in.newDrain()))
Exemplo n.º 4
0
class Channel(object):
    def __init__(self, name):
        self._name = name
        self._out = Out()
        self._in = In()
        self._in.fount.flowTo(self._out.drain)

    def participate(self, participant):
        @receiver(IMapping, IMapping)
        def addSender(item):
            yield dict(item, sender=participant, channel=self._name)

        return (self._out.newFount(),
                series(addSender, self._in.newDrain()))
Exemplo n.º 5
0
 def __init__(self, name):
     self._name = name
     self._out = Out()
     self._in = In()
     self._in.fount.flowTo(self._out.drain)
Exemplo n.º 6
0
 def __init__(self, name):
     self._name = name
     self._out = Out()
     self._in = In()
     self._in.fount.flowTo(self._out.drain)