Esempio n. 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))
Esempio n. 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)),
           )
Esempio n. 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()
Esempio n. 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"),
            },
        ), )
Esempio n. 5
0
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"),
    )
Esempio n. 6
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"),
                        ),
                    )
                   )
Esempio n. 7
0
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))
Esempio n. 8
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"))
Esempio n. 9
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(),
    )
Esempio n. 10
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
        })
Esempio n. 11
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"),
        })
Esempio n. 12
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
Esempio n. 13
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()
    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"),
Esempio n. 15
0
def LoggingWakeableIntrospector(logfile="greylist-debug.log"):
    return Pipeline(
        WakeableIntrospector(),
        PureTransformer(lambda x: "*debug* THREADS" + str(x) + "\n"),
        Append(filename=logfile, hold_open=False),
    )
Esempio n. 16
0
 def ClientProtocol():
     return Pipeline(
                 SubscribeTo("GameEvents"),
                 PureTransformer(lambda x : "|".join([str(y) for y in x])+"X")
            )
Esempio n. 17
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()
Esempio n. 18
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,
Esempio n. 19
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"),
Esempio n. 20
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()
Esempio n. 21
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(),
Esempio n. 22
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()