示例#1
0
 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)
示例#2
0
文件: fanchat.py 项目: david415/tubes
 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)
示例#3
0
文件: rpn.py 项目: ralphm/tubes
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
示例#4
0
文件: fanchat.py 项目: david415/tubes
    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()))
示例#5
0
文件: rpn.py 项目: ralphm/tubes
def calculatorSeries():
    from twisted.tubes.tube import series
    from twisted.tubes.framing import bytesToLines, linesToBytes

    return series(
        bytesToLines(),
        linesToNumbersOrOperators,
        CalculatingTube(Calculator()),
        numbersToLines,
        linesToBytes()
    )
示例#6
0
    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)
示例#7
0
文件: fanchat.py 项目: david415/tubes
    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)
示例#8
0
def mathFlow(fount, drain):
    fount.flowTo(
        series(packedPrefixToStrings(16), StringsToBoxes(),
               BoxConsumer(Math()), BoxesToData(), drain))
示例#9
0
文件: amptube.py 项目: david415/tubes
def mathFlow(fount, drain):
    fount.flowTo(series(packedPrefixToStrings(16), StringsToBoxes(),
                        BoxConsumer(Math()), BoxesToData(), drain))
示例#10
0
    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()))
示例#11
0
def reverseFlow(fount, drain):
    from twisted.tubes.framing import bytesToLines, linesToBytes
    lineReverser = series(bytesToLines(), Reverser(), linesToBytes())
    fount.flowTo(lineReverser).flowTo(drain)