def newParticipantFlow(self, fount, drain): commandFount = fount.flowTo( series(OnStop(lambda: self.participants.remove(participant)), bytesToLines(), linesToCommands)) commandDrain = series(commandsToLines, linesToBytes(), drain) participant = Participant(self, commandFount, commandDrain) self.participants.append(participant)
def newParticipantFlow(self, fount, drain): commandFount = fount.flowTo( series(OnStop(lambda: self.participants.remove(participant)), bytesToLines(), linesToCommands) ) commandDrain = series(commandsToLines, linesToBytes(), drain) participant = Participant(self, commandFount, commandDrain) self.participants.append(participant)
def promptingCalculatorSeries(): from twisted.tubes.fan import Thru from twisted.tubes.tube import series from twisted.tubes.framing import bytesToLines, linesToBytes full = series(bytesToLines(), Thru([series(linesToNumbersOrOperators, CalculatingTube(Calculator()), numbersToLines, linesToBytes()), series(Prompter())])) return full
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()))
def calculatorSeries(): from twisted.tubes.tube import series from twisted.tubes.framing import bytesToLines, linesToBytes return series( bytesToLines(), linesToNumbersOrOperators, CalculatingTube(Calculator()), numbersToLines, linesToBytes() )
def __init__(self, hub, requestsFount, responsesDrain): self._hub = hub self._participation = {} self._in = In() self._router = Router() self._participating = {} # self._in is both commands from our own client and also messages from # other clients. requestsFount.flowTo(self._in.newDrain()) self._in.fount.flowTo(series(self, self._router.drain)) self.client = self._router.newRoute() self.client.flowTo(responsesDrain)
def mathFlow(fount, drain): fount.flowTo( series(packedPrefixToStrings(16), StringsToBoxes(), BoxConsumer(Math()), BoxesToData(), drain))
def mathFlow(fount, drain): fount.flowTo(series(packedPrefixToStrings(16), StringsToBoxes(), BoxConsumer(Math()), BoxesToData(), drain))
def reverseFlow(fount, drain): from twisted.tubes.framing import bytesToLines, linesToBytes lineReverser = series(bytesToLines(), Reverser(), linesToBytes()) fount.flowTo(lineReverser).flowTo(drain)