Exemple #1
0
def SimpleUserClientPrefab(**tcp_args):
    """Pipelines PureTransformer(informat) to
       SimpleIRCClientPrefab(**tcp_args) to
       PureTransformer(outformat)"""
    return Pipeline(PureTransformer(informat),
                    SimpleIRCClientPrefab(**tcp_args),
                    PureTransformer(outformat))
Exemple #2
0
def TimeService(**argd):
    return Pipeline(
              DataSource([time.time()]),
              PureTransformer(lambda x: time.localtime(x)),
              PureTransformer(lambda x: [y for y in x]),
              PureTransformer(lambda x: simplejson.dumps(x)),
           )
Exemple #3
0
def SimpleAIMClient(screenname, password, buddyname):
    Pipeline(Textbox(position=(0, 400)),
             PureTransformer(lambda text: sendTo(buddyname, text)),
             AIMHarness(screenname, password),
             PureTransformer(lambda tup: outformat(tup, buddyname)),
             TextDisplayer()
             ).run()
Exemple #4
0
def clientconnectorwc(webcamBackplane="WEBCAM", port=1501):
    # Connects webcams to the network
    return Pipeline(
        Graphline(
            WEBCAM=FilteringPubsubBackplane(webcamBackplane),
            STRINGCONVERTER=PureTransformer(
                lambda x: pygame.image.tostring(x, "RGB")),
            SURFACECONVERTER=StringToSurface(190, 140),
            FRAMER=DataChunker(),
            CONSOLE=ConsoleEchoer(),
            DEFRAMER=DataDeChunker(),
            SIZER=PureTransformer(
                lambda x: pygame.transform.scale(x, (190, 140))
            ),  # This is a temporary fix - we should really be sending full resolution images
            # The issue is that to do this we need to send the original size as metadata and this needs more work to include
            linkages={
                # Receive data from the network - deframe and convert to image for display
                ("self", "inbox"): ("DEFRAMER", "inbox"),
                ("DEFRAMER", "outbox"): ("SURFACECONVERTER", "inbox"),
                # Send to display
                ("SURFACECONVERTER", "outbox"): ("WEBCAM", "inbox"),
                # Forward local images to the network - convert to strings and frame
                ("WEBCAM", "outbox"): ("SIZER", "inbox"),
                ("SIZER", "outbox"): ("STRINGCONVERTER", "inbox"),
                ("STRINGCONVERTER", "outbox"): ("FRAMER", "inbox"),
                # Send to network
                ("FRAMER", "outbox"): ("self", "outbox"),
            },
        ), )
Exemple #5
0
def NetInterpreter(*args, **argv):
    return Pipeline(
        PureTransformer(lambda x: str(x).rstrip()),
        PureTransformer(lambda x: str(x).replace("\r", "")),
        InterpreterTransformer(),
        PureTransformer(lambda x: str(x) + "\r\n>>> "),
    )
def ChatClient(*argc, **argd):
    peer = argd["peer"]
    peerport = argd["peerport"]
    return Pipeline(
        PureTransformer(lambda x: " %s:%s says %s" %
                        (str(peer), str(peerport), str(x))),
        PublishTo("CHAT"),  # Take data from client and publish to all clients
        # ----------------------
        SubscribeTo("CHAT"
                    ),  # Take data from other clients and send to our client
        PureTransformer(lambda x: "Chat:" + str(x).strip() + "\n"),
    )
Exemple #7
0
def IcecastStreamRemoveMetadata():
    def extraDataChunks(msg):
        if isinstance(msg, IceIPCDataChunk):
            return msg.data
        else:
            return None

    return PureTransformer(extraDataChunks)
Exemple #8
0
def HTTPDataStreamingClient(fullurl, method="GET", body=None, headers={}, username=None, password=None, proxy=None):
    # NOTE: username not supported yet
    # NOTE: password not supported yet

    headers = dict(headers)
    proto, host, port, path = parse_url(fullurl)
    if username is not None and password is not None:
        (header_field, header_value) = http_basic_auth_header(username, password)
        headers[header_field] = header_value

    if proxy != None:
        request = fullurl
        _, req_host , req_port, _ = parse_url(proxy)
    else:
        request = path
        req_host , req_port = host, port

    return Pipeline(
                    HTTPClientRequest(url=request, host=host, method=method, postbody=body, headers=headers),
                    TCPClient(req_host, req_port, wait_for_serverclose=True),
                    HTTPClientResponseHandler(suppress_header = True),
                   )

    # Leaving this here for a little while, since it is interesting/useful
    # Worth bearing in mind this next line will never execute

    return Pipeline(
                    HTTPClientRequest(url=request, host=host, method=method, postbody=body, headers=headers),
                    ComponentBoxTracer(
                        TCPClient(req_host, req_port, wait_for_serverclose=True),
                        Pipeline(
                            PureFilter(lambda x: x[0] == "outbox"),           # Only interested in data from the connection
                            PureTransformer(lambda x: x[1]),                  # Just want the data from the wire
                            PureTransformer(lambda x: base64.b64encode(x)+"\n"), # To ensure we capture data as chunked on the way in
                            SimpleFileWriter("tweets.b64.txt"),                # Capture for replay / debug
                        ),
                    ),
                    ComponentBoxTracer(
                        HTTPClientResponseHandler(suppress_header = True),
                        Pipeline(
                            PureFilter(lambda x: x[0] == "outbox"), # Only want the processed data here
                            PureTransformer(lambda x: x[1]), # Only want the raw data
                            SimpleFileWriter("tweets.raw.txt"),
                        ),
                    )
                   )
Exemple #9
0
def EchoEveryone(**kwargs):
    peer = str(kwargs.get("peer", "<>"))
    peerport = str(kwargs.get("peerport", "<>"))
    return Pipeline(
        PureTransformer(lambda x: "%s:%s says %s" % (peer, peerport, x)),
        PublishTo("CHAT_ONE"),
        # ------------
        SubscribeTo("CHAT_ONE"),
    )
def NiceTickerPrefab(**other_ticker_args):
    """Ticker that displays black text on a white background, and transforms
    any non-string arguments passed to it into strings.
    Do not pass in keywords text_height, line_spacing, background_colour,
    outline_colour, or text_colour."""
    return Pipeline(
        PureTransformer(lambda x: str(x)),
        Ticker(text_height=16,
               line_spacing=2,
               background_colour=(255, 255, 245),
               text_colour=(10, 10, 10),
               outline_colour=(0, 0, 0),
               **other_ticker_args))
Exemple #11
0
 def connect(self,args,pids):
     self.datacapture = Graphline(
                     DATA = HTTPDataStreamingClient(self.url,proxy=self.proxy,
                                                 username=self.username,
                                                 password=self.password,
                                                 headers = self.headers,
                                                 method="POST",
                                                 body=args),
                     FILTER = LineFilter(eol="\r\n",includeeol=True), # Including EOL to pass through blank lines and help failure detection
                     TRANSFORMER = PureTransformer(lambda x: [x,pids]),
                     #ECHOER = ConsoleEchoer(),
                     linkages = {("DATA", "outbox") : ("FILTER", "inbox"),
                                 ("FILTER", "outbox") : ("TRANSFORMER", "inbox"),
                                 ("TRANSFORMER", "outbox") : ("self", "outbox"),}
                 ).activate()
     self.link((self.datacapture, "outbox"), (self, "tweetsin"))
Exemple #12
0
def clientconnector(whiteboardBackplane="WHITEBOARD",
                    audioBackplane="AUDIO",
                    port=1500):
    return Pipeline(
        chunks_to_lines(),
        lines_to_tokenlists(),
        Graphline(
            ROUTER=Router(
                ((lambda T: T[0] == "SOUND"), "audio"),
                ((lambda T: T[0] != "SOUND"), "whiteboard"),
            ),
            WHITEBOARD=FilteringPubsubBackplane(whiteboardBackplane),
            AUDIO=Pipeline(
                SimpleDetupler(1),  # remove 'SOUND' tag
                SpeexDecode(3),
                FilteringPubsubBackplane(audioBackplane, dontRemoveTag=True),
                PureTransformer(lambda x: x[1]),
                #RawAudioMixer(),
                SpeexEncode(3),
                Entuple(prefix=["SOUND"], postfix=[]),
            ),
            linkages={
                # incoming messages go to a router
                ("self", "inbox"): ("ROUTER", "inbox"),
                # distribute messages to appropriate destinations
                ("ROUTER", "audio"): ("AUDIO", "inbox"),
                ("ROUTER", "whiteboard"): ("WHITEBOARD", "inbox"),
                # aggregate all output
                ("AUDIO", "outbox"): ("self", "outbox"),
                ("WHITEBOARD", "outbox"): ("self", "outbox"),
                # shutdown routing, not sure if this will actually work, but hey!
                ("self", "control"): ("ROUTER", "control"),
                ("ROUTER", "signal"): ("AUDIO", "control"),
                ("AUDIO", "signal"): ("WHITEBOARD", "control"),
                ("WHITEBOARD", "signal"): ("self", "signal")
            },
        ),
        tokenlists_to_lines(),
    )
Exemple #13
0
def SimpleIRCClientPrefab(host="127.0.0.1",
                          port=6667,
                          nick="kamaeliabot",
                          nickinfo="Kamaelia",
                          defaultChannel="#kamaeliatest",
                          IRC_Handler=IRC_Client,
                          Input_Handler=InputFormatter):
    return Graphline(
        CLIENT=TCPClient(host, port),
        PROTO=IRC_Handler(nick, nickinfo, defaultChannel),
        FORMAT=PureTransformer(Input_Handler),
        linkages={
            ("CLIENT", "outbox"): ("PROTO", "inbox"),
            ("PROTO", "outbox"): ("CLIENT", "inbox"),
            ("PROTO", "heard"):
            ("SELF",
             "outbox"),  #SELF refers to the Graphline. Passthrough linkage
            ("SELF", "inbox"): ("FORMAT", "inbox"),  #passthrough
            ("FORMAT", "outbox"): ("PROTO", "talk"),
            ("SELF", "control"): ("PROTO", "control"),  #passthrough
            ("PROTO", "signal"): ("CLIENT", "control"),
            ("CLIENT", "signal"): ("SELF", "signal"),  #passthrough
        })
Exemple #14
0
def ComplexIRCClientPrefab(host="127.0.0.1",
                           port=6667,
                           nick="kamaeliabot",
                           nickinfo="Kamaelia",
                           defaultChannel="#kamaeliatest",
                           IRC_Handler=IRC_Client):
    return Graphline(
        CLIENT=TCPClient(host, port),
        PROTO=IRC_Handler(nick, nickinfo, defaultChannel),
        FORMAT=PureTransformer(InputFormatter),
        SPLIT=Fanout(["toGraphline", "toTCP"]),
        linkages={
            ("CLIENT", "outbox"): ("PROTO", "inbox"),
            ("PROTO", "outbox"): ("SPLIT", "inbox"),
            ("PROTO", "heard"): ("SELF", "outbox"),  #passthrough
            ("SELF", "inbox"): ("FORMAT", "inbox"),  #passthrough
            ("FORMAT", "outbox"): ("PROTO", "talk"),
            ("SELF", "control"): ("PROTO", "control"),  #passthrough
            ("PROTO", "signal"): ("CLIENT", "control"),
            ("CLIENT", "signal"): ("SELF", "signal"),  #passthrough
            ("SPLIT", "toGraphline"): ("SELF", "sendCopy"),  #passthrough
            ("SPLIT", "toTCP"): ("CLIENT", "inbox"),
        })
Exemple #15
0
else:
    testing = False

if testing:
    Pipeline(
        SubscribeTo("DEBUGIN"),
        PublishTo("USERRESPONSE"),
    ).activate()
    Pipeline(
        Textbox(position=(250,48), size=(500,150)),
        PublishTo("DEBUGIN"),
    ).activate()

    Pipeline(
        SubscribeTo("OUIJAOUT"),
        PureTransformer(lambda x: str(x)+"\n"),
        TextDisplayer(position=(250,220), size=(500,150)),
    ).activate()

Pipeline(
    ConsoleReader(">> "),
    PureTransformer(lambda x: x[:-1]),
    PublishTo("PROGRAMME"),
).activate()

else:
    Pipeline(
        SubscribeTo("OUIJAOUT"),
        TextDisplayer(position=(250,48),
                      size=(500,322),
                      text_height=25),
Exemple #16
0
       """
        for child in self.childComponents():
            if child._isStopped():
                self.removeChild(child)  # deregisters linkages for us

        return 0 == len(self.childComponents())


if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Util.PureTransformer import PureTransformer
    Pipeline(
        DataSource([
            (1, "one"),
            (2, "two"),
            (3, "three"),
            (4, "four"),
            (5, "five"),
            (6, "six"),
        ]),
        DemuxRemuxTuple(  # Detuple
            PureTransformer(lambda x: x * x),  # Process First item from tuple
            PureTransformer(
                lambda x: x + " " + x),  # Process Second item from tuple
        ),  # Retuple
        PureTransformer(lambda x: repr(x) + "\n"),
        ConsoleEchoer(),
    ).run()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1)
#
# (1) Kamaelia Contributors are listed in the AUTHORS file and at
#     http://www.kamaelia.org/AUTHORS - please extend this file,
#     not this notice.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -------------------------------------------------------------------------
#
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Util.PureTransformer import PureTransformer
from Kamaelia.UI.Pygame.Text import Textbox

Pipeline(Textbox(size=(800, 300), position=(0, 0)),
         PureTransformer(lambda x: x + "\n"), ConsoleEchoer()).run()
Exemple #18
0
    def capture_one(self):
        self.snapshot = None
        self.snapshot = self.camera.get_image()

    def main(self):
        self.camera.start()
        while 1:
            self.capture_one()
            self.send(self.snapshot, "outbox")
            time.sleep(self.delay)


if __name__ == "__main__":

    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.File.Writing import SimpleFileWriter
    from Kamaelia.Codec.Dirac import DiracEncoder
    from Kamaelia.Video.PixFormatConversion import ToYUV420_planar
    from Kamaelia.Util.PureTransformer import PureTransformer
    Pipeline(
       VideoCaptureSource(),
       PureTransformer(lambda F : \
                 {"rgb" : pygame.image.tostring(F, "RGB"),
                          "size" : (352, 288),
                          "pixformat" : "RGB_interleaved",
                 }),
        ToYUV420_planar(),
        DiracEncoder(preset="CIF",  encParams={"num_L1":0}),
        SimpleFileWriter("X.drc"),
    ).run()
Exemple #19
0
        GameModel(),
        PublishTo("GameEvents"),
    ).activate()

else:
    B = ""
    def unmarshall(x):
        global B
        B = B+x
        if B.find("X") != -1:
            L = B[:B.find("X")]
            B = B[B.find("X")+1:]
            L = L.split("|")
            L[1] = int(L[1])
            L[2] = int(L[2])
            return L
        return (1,1,1)
    Pipeline(
        TCPClient(sys.argv[1], 1601),
        PureTransformer(lambda x : unmarshall(x)),
        PublishTo("GameEvents")
    ).activate()

Pipeline(
    SubscribeTo("GameEvents"),
    GameDisplay()
).run()



Exemple #20
0
            pass
        if self.dataReady("control"):
            self.send(self.recv("control"), "signal")
        else:
            self.send(Axon.Ipc.producerFinished(), "signal")


if __name__ == "__main__":
    from TaggingPluggableProcessor import TaggingPluggableProcessor
    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer
    from Kamaelia.Util.PureTransformer import PureTransformer

    TPP = TaggingPluggableProcessor()

    Pipeline(ConsoleReader(), PureTransformer(lambda x: int(x)), TPP,
             ConsoleEchoer()).activate()

    ConditionalTransformer(TPP, "EVEN", lambda x: x % 2 == 0,
                           lambda x: "Even ! " + str(x)).activate()

    def isodd(x):
        return x % 2 == 1

    def format_as_odd(x):
        return "Odd ! " + str(x)

    ConditionalTransformer(TPP, "ODD", isodd, format_as_odd).activate()

    class Divisible3(ConditionalTransformer):
        @staticmethod
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.PureTransformer import PureTransformer
    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.Chassis.Graphline import Graphline
    from Kamaelia.Chassis.Seq import Seq

    class Pauser(Axon.ThreadedComponent.threadedcomponent):
        def main(self):
            time.sleep(1)

    Graphline(DATASOURCE=Seq(Pauser(), DataSource([1, 2, 3, 4, 5, 6])),
              PROCESSOR=TaggingPluggableProcessor(),
              PROCESSORSOURCE=DataSource([
                  ("EVEN", lambda x: x % 2 == 0,
                   PureTransformer(lambda x: "Even ! " + str(x))),
                  ("ODD", lambda x: x % 2 == 1,
                   PureTransformer(lambda x: "Odd ! " + str(x))),
                  ("THREE", lambda x: x % 3 == 0,
                   PureTransformer(lambda x: "Divisible by 3 ! " + str(x))),
                  ("FOUR", lambda x: x % 4 == 0,
                   PureTransformer(lambda x: "Divisible by 3 ! " + str(x))),
              ]),
              CONSOLE=Pipeline(PureTransformer(lambda x: repr(x) + "\n"),
                               ConsoleEchoer()),
              linkages={
                  ("DATASOURCE", "outbox"): ("PROCESSOR", "inbox"),
                  ("DATASOURCE", "signal"): ("PROCESSOR", "control"),
                  ("PROCESSORSOURCE", "outbox"): ("PROCESSOR", "processor"),
                  ("PROCESSOR", "outbox"): ("CONSOLE", "inbox"),
                  ("PROCESSOR", "signal"): ("CONSOLE", "control"),
Exemple #22
0
        file = open(homedir + "/twitter-login.conf")
    except IOError, e:
        print ("Failed to load login data - exiting")
        sys.exit(0)

    raw_config = file.read()
    file.close()

    # Read Config
    config = cjson.decode(raw_config)
    bitlyusername = config['bitlyusername']
    bitlyapikey = config['bitlyapikey']
    proxy = config['proxy']

    READER = ConsoleReader()
    DECODER = PureTransformer(lambda x: cjson.decode(x))
    CLEANER = TweetCleaner(['user_mentions','urls','hashtags'])
    WRITER = ConsoleEchoer()
    FIXER = RetweetFixer()
    SPELLING = PureTransformer(lambda x: spellingFixer(x))
    LINKER = LinkResolver(bitlyusername,bitlyapikey)
    REQUESTER = HTTPGetter(proxy, "BBC R&D Grabber")

    if 0:
        Pipeline(READER,DECODER,CLEANER,WRITER).run()

    if 0:
        Pipeline(READER,DECODER,FIXER,WRITER).run()

    if 0:
        Graphline(READER=READER,DECODER=DECODER,LINKER=LINKER,REQUESTER=REQUESTER,WRITER=WRITER,
Exemple #23
0
            return x

    class ListSplit(component):
        def main(self):
            while 1:
                yield 1
                while self.dataReady("inbox"):
                    msg = self.recv("inbox")
                    for m in msg:
                        self.send(m, "outbox")
                self.pause()

    Graphline(usersuppliedurls=ConsoleReader(eol=""),
              splitter=Fanout(["toHTTPClient", "toCorrectRelativeLinks"]),
              splittertwo=Fanout(["toSplitterOne", "toEchoer"]),
              newlinesuffixadder=PureTransformer(lambda x: x + "\n"),
              httpclient=SimpleHTTPClient(),
              htmlprocessor=HTMLProcess(),
              linkextractor=ExtractLinks(),
              linkcorrector=CorrectRelativeLinks(),
              listsplitter=ListSplit(),
              prefixmatcher=PureTransformer(suffixMatchOnly),
              newurlechoer=ConsoleEchoer(),
              unseenonly=UnseenOnly(),
              linkages={
                  ("usersuppliedurls", "outbox"): ("unseenonly", "inbox"),
                  ("newurlechoer", "outbox"): ("splitter", "inbox"),
                  ("splitter", "toHTTPClient"): ("httpclient", "inbox"),
                  ("splitter", "toCorrectRelativeLinks"):
                  ("linkcorrector", "sourceurl"),
                  ("httpclient", "outbox"): ("htmlprocessor", "inbox"),
Exemple #24
0
            self.link((self, "inbox"), (self.chatter, "talk"), passthrough=1)
            self.link((self.chatter, "outbox"), (self.oscar, "inbox"))
            self.link((self.oscar, "outbox"), (self.chatter, "inbox"))
            self.link((self, "internal outbox"), (self.chatter, "inbox"))
            while len(queued):
                self.send(queued[0], "internal outbox")
                del(queued[0])
            assert self.debugger.note("AIMHarness.main", 5, "Everything linked up and initialized, starting normal operation")
            while True:  #FIXME:  Why do we keep running instead of dying?
                self.pause()
                yield 1

__kamaelia_components__ = (AIMHarness, )

if __name__ == '__main__':
    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.Util.Console import ConsoleEchoer, ConsoleReader
    from Kamaelia.Util.PureTransformer import PureTransformer

    def tuplefy(data):
        data = data.split()
        if len(data) > 1: 
            data = ("message", data[0], " ".join(data[1:]))
            return data
           
    Pipeline(ConsoleReader(),
             PureTransformer(tuplefy),
             AIMHarness("kamaelia1", "abc123"),
             ConsoleEchoer()
             ).run()
Exemple #25
0
    ["relabel", 8, "Handle Shutdown"],
    ["relabel", 9, "Loop pygame events"],
    ["relabel", 10, "handle event"],
    ["relabel", 11, "mouse dn 1"],
    ["relabel", 12, "mouse dn 2"],
    ["relabel", 13, "mouse dn 3"],
    ["get", "all"],
    ["get", "node", 10],
    ["get", "node", 11],
    ["get", "node", 9],
]

from Kamaelia.Util.Console import ConsoleEchoer
if 0:
    Pipeline(Source(iterable=topologies),
             PureTransformer(lambda x: ["replace", x]), MyBoxes()).run()

if 0:
    Pipeline(Source(iterable=grow_commands), MyBoxes()).run()

if 0:
    Pipeline(
        Source(iterable=relabel_commands, delay=0.3),
        MyBoxes(),
        PureTransformer(lambda x: str(x) + "\n"),
        ConsoleEchoer(),
    ).run()

if 0:
    import random
    from Kamaelia.UI.Pygame.Button import Button
Exemple #26
0
 def ClientProtocol():
     return Pipeline(
                 SubscribeTo("GameEvents"),
                 PureTransformer(lambda x : "|".join([str(y) for y in x])+"X")
            )
Exemple #27
0
        self.send(self.recv("control"), "signal")


from Kamaelia.Experimental.PythonInterpreter import InterpreterTransformer


def NetInterpreter(*args, **argv):
    return Pipeline(
        PureTransformer(lambda x: str(x).rstrip()),
        PureTransformer(lambda x: str(x).replace("\r", "")),
        InterpreterTransformer(),
        PureTransformer(lambda x: str(x) + "\r\n>>> "),
    )


ServerCore(protocol=NetInterpreter,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
           port=8765).activate()

Pipeline(
    PeriodicWakeup(interval=1),
    WakeableIntrospector(),
    PureTransformer(lambda x: str(len(x)) + " " + str(x) + "\n"),
    Uniq(),
    ConsoleEchoer(),
).activate()

ServerCore(protocol=Echo,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
           port=1234).run()
Exemple #28
0
                          "outbox")  # XXXX Note this is broken
            yield 1


Pipeline(
    KeyEvent(outboxes={"outbox": ""},
             key_events={pygame.K_q: ("start_up", "outbox")}),
    Quitter(),
).activate()

Backplane("PLAYERS").activate()

Pipeline(
    MyGamesEventsComponent(up="p", down="l", left="a", right="s"),
    BasicSprite("cat.png", name="cat", border=40),
    PureTransformer(lambda x: ("Cat ", x)),
    PublishTo("PLAYERS"),
).activate()

Pipeline(
    MyGamesEventsComponent(up="up", down="down", left="left", right="right"),
    BasicSprite("mouse.png", name="mouse", border=40),
    PureTransformer(lambda x: ("Mouse", x)),
    PublishTo("PLAYERS"),
).activate()

Pipeline(
    SubscribeTo("PLAYERS"),
    PlayerAnalyser(),
    Distancer(),
    ConsoleEchoer(),
Exemple #29
0
    def filtertest(self, item):
        return True

    def main(self):
        filterfunc = self.filterfunc  # cache function, and makes usage clearer
        while True:
            if not self.anyReady():
                self.pause()
            yield 1
            for item in self.Inbox("inbox"):
                if filterfunc(item):
                    self.send(item, "outbox")
            if self.dataReady("control"):
                self.send(self.recv("control"), "signal")
                break


if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Util.PureTransformer import PureTransformer

    Pipeline(
        DataSource([1, 2, 3, 4, 5, 6]),
        PureFilter(lambda x: (x % 2) == 0),
        PureTransformer(lambda x: str(x) + "\n"),
        ConsoleEchoer(),
    ).run()
Exemple #30
0
def LoggingWakeableIntrospector(logfile="greylist-debug.log"):
    return Pipeline(
        WakeableIntrospector(),
        PureTransformer(lambda x: "*debug* THREADS" + str(x) + "\n"),
        Append(filename=logfile, hold_open=False),
    )