Exemplo n.º 1
0
 def __init__(self):
    super(testHarness,self).__init__()
    self.serverport = 4444
    self.server = SimpleServer(protocol=FortuneCookieProtocol, port=self.serverport)
    self.client = None
    self.display = ConsoleEchoer()
    self.displayerr = ConsoleEchoer()
Exemplo n.º 2
0
 def __init__(self):
     super(testHarness, self).__init__(
     )  # I wonder if this can get forced to be called automagically?
     self.serverport = 4444
     self.server = SimpleServer(protocol=FortuneCookieProtocol,
                                port=self.serverport)
     self.client = None
     self.display = ConsoleEchoer()
     self.displayerr = ConsoleEchoer()
Exemplo n.º 3
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"),
            },
        ), )
Exemplo n.º 4
0
def makeBasicSketcher(left=0, top=0, width=1024, height=768):
    return Graphline(
        CANVAS=Canvas(position=(left, top + 32), size=(width, height - 32)),
        PAINTER=Painter(),
        #CLEAR = ClearPage(left,top),
        CALIBRATE=Calibrate(),
        TWOWAY=TwoWaySplitter(),
        CALIBBUTTON=calibButton(left, top),
        FILEWRITER=WholeFileWriter(),
        DEBUG=ConsoleEchoer(),
        linkages={
            ("CANVAS", "eventsOut"): ("PAINTER", "inbox"),

            #("PAINTER", "outbox")    : ("CANVAS", "inbox"),
            ("PAINTER", "outbox"): ("TWOWAY", "inbox"),
            #("CLEAR", "outbox")       : ("CANVAS", "inbox"),
            ("CALIBRATE", "outbox"): ("CANVAS", "inbox"),
            #("CANVAS", "toApp") : ("CALIBRATE", "coords"),
            ("TWOWAY", "outbox"): ("CALIBRATE", "coords"),
            ("TWOWAY", "outbox2"): ("CANVAS", "inbox"),
            ("CALIBBUTTON", "outbox"): ("CALIBRATE", "inbox"),
            ("CALIBRATE", "finaldata"): ("FILEWRITER", "inbox"),
            ("FILEWRITER", "outbox"): ("CALIBRATE", "inbox"),
        },
    )
Exemplo n.º 5
0
        def main(self):
            chargen = Chargen()
            display = ConsoleEchoer()

            self.link((chargen, "outbox"), (display, "inbox"))
            self.addChildren(chargen, display)
            yield Axon.Ipc.newComponent(*(self.children))
            while 1:
                self.pause()
                yield 1
Exemplo n.º 6
0
        def main(self):
            receiver = Multicast_receiver("224.168.2.9", 1600)
            display = ConsoleEchoer()

            self.link((receiver, "outbox"), (display, "inbox"))
            self.addChildren(receiver, display)
            yield Axon.Ipc.newComponent(*(self.children))
            while 1:
                self.pause()
                yield 1
Exemplo n.º 7
0
 def __init__(self):
     super(NullPayloadPreFramer_testHarness,
           self).__init__()  # !!!! Must happen, if this method exists
     self.source = ReadFileAdaptor("Support/BlankFile.txt",
                                   readsize="1450",
                                   steptime=0)
     self.transform = NullPayloadPreFramer("TestSource",
                                           65536,
                                           chunksize=257)
     self.sink = ConsoleEchoer()
        def main(self):
            chargen = Chargen()
            sender = Multicast_transceiver("0.0.0.0", 0, "224.168.2.9", 1600)
            receiver = Multicast_transceiver("0.0.0.0", 1600, "224.168.2.9", 0)
            display = ConsoleEchoer()

            self.link((chargen, "outbox"), (sender, "inbox"))
            self.link((receiver, "outbox"), (display, "inbox"))
            self.addChildren(chargen, sender, receiver, display)
            yield Axon.Ipc.newComponent(*(self.children))
            while 1:
                self.pause()
                yield 1
Exemplo n.º 9
0
        def __init__(self):
            super(testComponent, self).__init__()

            self.source = fruitSource()
            self.pipe = Pipeline(PassThrough([]))
            self.dest = ConsoleEchoer()
            self.addChildren(self.source, self.pipe, self.dest)

            self.link((self.source, "outbox"), (self.pipe, "inbox"))
            self.link((self.source, "signal"), (self.pipe, "control"))

            self.link((self.pipe, "outbox"), (self.dest, "inbox"))
            self.link((self.pipe, "signal"), (self, "_control"))

            self.link((self, "_signal"), (self.dest, "control"))
Exemplo n.º 10
0
def clientconnectorwc(webcamBackplane="WEBCAM", port=1501):
    return Pipeline(
        #chunks_to_lines(),
        Graphline(
            WEBCAM=FilteringPubsubBackplane(webcamBackplane),
            CONVERTER=SurfaceToJpeg(),
            FRAMER=DataChunker(),
            CONSOLE=ConsoleEchoer(),
            DEFRAMER=DataDeChunker(),
            linkages={
                ("", "inbox"): ("DEFRAMER", "inbox"),
                ("DEFRAMER", "outbox"): ("CONVERTER", "inbox2"),
                ("CONVERTER", "outbox2"): ("WEBCAM", "inbox"),
                ("WEBCAM", "outbox"): ("CONVERTER", "inbox"),
                ("CONVERTER", "outbox"): ("FRAMER", "inbox"),
                ("FRAMER", "outbox"): ("", "outbox"),
            },
        ), )
Exemplo n.º 11
0
    def TargettedPeer_tests():
        from Axon.Scheduler import scheduler
        from Kamaelia.Util.Console import ConsoleEchoer
        from Kamaelia.Chassis.Pipeline import Pipeline
        from Kamaelia.Util.Chargen import Chargen
        from Kamaelia.Chassis.Graphline import Graphline

        server_addrs = [
            ("127.0.0.1", 1600),
            ("127.0.0.2", 1601),
            ("127.0.0.3", 1602),
            ("127.0.0.4", 1603),
        ]

        for server_addr, server_port in server_addrs:
            Pipeline(
                SimplePeer(localaddr=server_addr,
                           localport=server_port),  # Simple Servers
                LineSepFilter("SERVER:" + server_addr + " :: "),
                ConsoleEchoer()).activate()

        class TargetTesterSource(Axon.Component.component):
            Outboxes = ["changetarget", "outbox"]

            def __init__(self, targets):
                super(TargetTesterSource, self).__init__()
                self.targets = targets

            def main(self):
                while 1:
                    yield 1
                    for target in self.targets:
                        self.send(target, "changetarget")
                        for x in xrange(5):
                            self.send(
                                "HELLO (" + str(x) + ") TO " + str(target),
                                "outbox")

        Graphline(TESTSOURCE=TargetTesterSource(server_addrs),
                  SENDER=TargettedPeer(localaddr="127.0.0.1"),
                  linkages={
                      ("TESTSOURCE", "changetarget"): ("SENDER", "target"),
                      ("TESTSOURCE", "outbox"): ("SENDER", "inbox"),
                  }).run()
Exemplo n.º 12
0
    def PostboxPeer_tests():
        from Axon.Scheduler import scheduler
        from Kamaelia.Util.Console import ConsoleEchoer
        from Kamaelia.Chassis.Pipeline import Pipeline
        from Kamaelia.Util.Chargen import Chargen
        from Kamaelia.Chassis.Graphline import Graphline
        import random

        server_addrs = [
            ("127.0.0.1", 1601),
            ("127.0.0.2", 1602),
            ("127.0.0.3", 1603),
            ("127.0.0.4", 1604),
        ]

        for server_addr, server_port in server_addrs:
            Pipeline(
                SimplePeer(localaddr=server_addr,
                           localport=server_port),  # Simple Servers
                LineSepFilter("SERVER:" + server_addr + " :: "),
                ConsoleEchoer()).activate()

        class PostboxPeerSource(Axon.Component.component):
            def __init__(self, targets):
                super(PostboxPeerSource, self).__init__()
                self.targets = targets

            def main(self):
                while 1:
                    yield 1
                    target_addr, target_port = server_addrs[random.randint(
                        0, 3)]
                    data_to_send = "HELLO ! TO " + target_addr

                    message = (target_addr, target_port, data_to_send)

                    self.send(message, "outbox")

        Pipeline(
            PostboxPeerSource(server_addrs),
            PostboxPeer(localaddr="127.0.0.1"),
        ).run()
Exemplo n.º 13
0
def TopologyViewerServer(serverPort = 1500, **dictArgs):
    """\
    TopologyViewerServer([noServer][,serverPort],**args) -> new TopologyViewerServer component.

    Multiple-clients-at-a-time TCP socket Topology viewer server. Connect on the
    specified port and send topology change data for display by a
    TopologyViewer.

    Keyword arguments:
    
    - serverPort  -- None, or port number to listen on (default=1500)
    - args        -- all remaining keyword arguments passed onto TopologyViewer
    """
    FastRestartServer(protocol=Users, port=serverPort).activate()
#     SimpleServer(protocol=Users, port=serverPort).activate()
    return Pipeline( SubscribeTo("NODEEVENTS"),
                     chunks_to_lines(),
                     lines_to_tokenlists(),
                     TopologyViewer(**dictArgs),
                     ConsoleEchoer()
               )
Exemplo n.º 14
0
def main():
    # app = QtGui.QApplication(sys.argv)
    #myapp = MyForm(device_id=3)
    #myapp.show()
    #sys.exit(app.exec_())
    #
    #Pipe = Pipeline(CVCamera(),
    #                 #ColorFilter(settings=(100, 100, 100, 100, 100)),
    #                 Matelight()
    #).activate()

    MidiPipe = Graphline(
        CAM=CVCamera(),
        ML=Matelight(),
        MI=MidiInput(5),
        MR=MidiRouter({
            2: 'red',
            3: 'green',
            4: 'blue',
            14: 'brightness',
            15: 'gamma'
        }),
        LC=loopingCounter(1, 127),
        CF=ColorFilter(),
        CE=ConsoleEchoer(),
        linkages={
            ("MI", "outbox"): ("MR", "inbox"),
            #("MR", "red"): ("CF", "red"),
            ("LC", "outbox"): ("CF", "red"),
            ("MR", "green"): ("CF", "green"),
            ("MR", "blue"): ("CF", "blue"),
            ("MR", "brightness"): ("CF", "brightness"),
            ("MR", "gamma"): ("CF", "gamma"),
            ("CAM", "outbox"): ("CF", "inbox"),
            ("CF", "outbox"): ("ML", "inbox")
        }).activate()

    scheduler.run.runThreads()
Exemplo n.º 15
0
                                ('CONSOLE','outbox'):('SKETCHER','inbox'),
                              }
                     )

    camera = Graphline(
        LOCALWEBCAM=VideoCaptureSource(),
        WCCANVAS=ProperSurfaceDisplayer(displaysize=(190, 140),
                                        position=(1024 - 191, 32 + 2),
                                        bgcolour=(0, 0, 0),
                                        webcam=1),
        REMWCCANVAS=ProperSurfaceDisplayer(displaysize=(190, 140 * 4 + 4),
                                           position=(1024 - 191, 32 + 140 + 3),
                                           bgcolour=(0, 0, 0),
                                           webcam=2),
        CAM_SPLITTER=TwoWaySplitter(),
        CONSOLE=ConsoleEchoer(),
        linkages={
            ('', 'inbox'): ('REMWCCANVAS', 'inbox'),
            ('LOCALWEBCAM', 'outbox'): ('CAM_SPLITTER', 'inbox'),
            ('CAM_SPLITTER', 'outbox2'): ('WCCANVAS', 'inbox'),
            ('CAM_SPLITTER', 'outbox'): ('', 'outbox'),
        })

    # primary whiteboard
    Pipeline(SubscribeTo("WHITEBOARD"), TagAndFilterWrapper(mainsketcher),
             PublishTo("WHITEBOARD")).activate()

    # primary sound IO - tagged and filtered, so can't hear self
    Pipeline(
        SubscribeTo("AUDIO"),
        TagAndFilterWrapperKeepingTag(
Exemplo n.º 16
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.
"""
Simple Kamaelia Example that shows how to use a simple UDP Peer.
A UDP Peer actually sends and recieves however, so we could have
more fun example here with the two peers sending each other messages.

It's worth noting that these aren't "connected" peers in any shape
or form, and they're fixed who they're sending to, etc, which is why
it's a simple peer.
"""
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Chargen import Chargen
from Kamaelia.Internet.UDP import SimplePeer

server_addr = "127.0.0.1"
server_port = 1600

Pipeline(
    Chargen(),
    SimplePeer(receiver_addr=server_addr, receiver_port=server_port),
).activate()

Pipeline(SimplePeer(localaddr=server_addr, localport=server_port),
         ConsoleEchoer()).run()
# RELEASE: MH, MPS
Exemplo n.º 17
0
                      size=(500,322),
                      text_height=25),
    ).activate()

def Publisher(*args, **argd):
    return PublishTo("OPENCV_VOTES")

# For receiving Voting information from Matt's Open CV system

ServerCore(protocol = Publisher, port=1500,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
           ).activate()

Pipeline(
    SubscribeTo("OPENCV_VOTES"),
    ConsoleEchoer(forwarder=True),
    OpenCVAnalyser(),
    ConsoleEchoer(forwarder=True),
    PublishTo("USERRESPONSE"),
#    PureTransformer(lambda x: repr(x)+"\n"),
).activate()

Pipeline(
    SubscribeTo("PINGERCONTROL"),
    Pinger(sleep=5),
    PublishTo("SCHEDULECONTROL"),
).activate()

Pipeline(
    SubscribeTo("SCHEDULECONTROL"),
    Schedule(),
Exemplo n.º 18
0
                if event.button == 1:
                    self.grabbed = 0
                    self.scaling = Vector(1, 1, 1)
                    #activate
                    if self.identifier in event.hitobjects:
                        activate = True

            if activate:
                self.send(self.eventMsg, "outbox")


__kamaelia_components__ = (SimpleButton, )

if __name__ == '__main__':
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Chassis.Graphline import Graphline

    Graphline(button1=SimpleButton(size=(1, 1, 0.3),
                                   position=(-2, 0, -10),
                                   msg="PINKY"),
              button2=SimpleButton(size=(2, 2, 1),
                                   position=(5, 0, -15),
                                   msg="BRAIN"),
              echo=ConsoleEchoer(),
              linkages={
                  ("button1", "outbox"): ("echo", "inbox"),
                  ("button2", "outbox"): ("echo", "inbox")
              }).run()

# Licensed to the BBC under a Contributor Agreement: THF
#!/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()
Exemplo n.º 20
0
                for url, targetOutbox in self.urls:
                    self.send(url, targetOutbox)

            if not self.anyReady():
                self.pause()
  
            yield 1

if __name__ == '__main__':
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Util.OneShot import OneShot
    from atomhandler import FeedReaderComponent

    shot = OneShot()

    monitor = HTTPResourceMonitor()
    monitor.link((shot, 'outbox'), (monitor, 'monitor'))

    feedreader = FeedReaderComponent()
    printer = ConsoleEchoer()
    feedreader.link((feedreader, 'outbox'), (printer, 'inbox'))
    
    shot.send(('http://localhost:8080/profile/feed', feedreader))

    printer.activate()
    feedreader.activate()
    #shot.activate()
    monitor.run()

    
Exemplo n.º 21
0
            yield 1
        reply = self.recv()
        assert self.debugger.note("AuthCookieGetter.main", 5,
                                  "received BOS/auth cookie")
        yield reply[1]

    def extractBOSandCookie(self, data):
        snac = readSNAC(data)
        parsed = readTLVs(snac[1])
        assert parsed.has_key(0x05)
        BOS_server = parsed[0x05]
        BOS_server, port = BOS_server.split(':')
        port = int(port)
        auth_cookie = parsed[0x06]
        return BOS_server, port, auth_cookie


if __name__ == '__main__':
    from Kamaelia.Chassis.Graphline import Graphline
    from Kamaelia.Util.Console import ConsoleEchoer

    Graphline(auth=AuthCookieGetter(),
              oscar=OSCARClient('login.oscar.aol.com', 5190),
              cons=ConsoleEchoer(),
              linkages={
                  ("auth", "outbox"): ("oscar", "inbox"),
                  ("oscar", "outbox"): ("auth", "inbox"),
                  ("auth", "signal"): ("oscar", "control"),
                  ("auth", "_cookie"): ("cons", "inbox"),
              }).run()
Exemplo n.º 22
0
            while 1:
                while self.dataReady("inbox"):
                    req = self.recv("inbox")
                    if req[0] == "ADD":
                        param, dest = req[1], req[2]
                        outboxes[dest] = self.addOutbox("outbox")
                        linkages[dest] = self.link((self, outboxes[dest]),
                                                   dest)
                        params[dest] = param

                for dest in params.keys():
                    self.send(params[dest], outboxes[dest])

                yield 1

    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Chassis.Pipeline import Pipeline

    Pipeline(
        Subscribe("SERVICE1", 5),
        ConsoleEchoer(),
    ).activate()

    Pipeline(
        Subscribe("SERVICE1", 1),
        ConsoleEchoer(),
    ).activate()

    RegisterService(DummyService(), {"SERVICE1": "inbox"}).run()
Exemplo n.º 23
0
This component ignores anything arriving at its "inbox" inbox.

If a shutdownMicroprocess message is received on the "control" inbox, it is sent
on to the "signal" outbox and the component will terminate.
"""

from Axon.Introspector import Introspector as _AxonIntrospector

class Introspector(_AxonIntrospector):
    pass

__kamaelia_components__  = ( Introspector, )


if __name__ == '__main__':
   import Axon
   
   i = Introspector()
   i.activate()
   from Kamaelia.Util.Console import ConsoleEchoer
   e = ConsoleEchoer()
   e.activate()
   i.link((i,"outbox"), (e, "inbox"))
   
   print "You should see the Introspector find that it and a ConsoleEchoer component exist."
   print "We both have inbox, control, signal and outbox postboxes"
   print "The Introspector's outbox is linked to the ConsoleEchoer's inbox"
   print
   Axon.Scheduler.scheduler.run.runThreads(slowmo=0)
Exemplo n.º 24
0
                    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"),
                  ("htmlprocessor", "outbox"): ("linkextractor", "inbox"),
                  ("linkextractor", "outbox"): ("linkcorrector", "links"),
                  ("linkcorrector", "outbox"): ("listsplitter", "inbox"),
                  ("listsplitter", "outbox"): ("prefixmatcher", "inbox"),
                  ("prefixmatcher", "outbox"): ("unseenonly", "inbox"),
                  ("unseenonly", "outbox"): ("splittertwo", "inbox"),
                  ("splittertwo", "toSplitterOne"): ("splitter", "inbox"),
Exemplo n.º 25
0
                         ("GRAMMAR", "outbox"): ("self", "outbox"),
                         ("QUANTISE", "drawing"): ("self", "drawing"),
                         ("ANALYSE", "drawing"): ("self", "drawing"),
                     })


if __name__ == "__main__":

    from Kamaelia.UI.Pygame.Display import PygameDisplay
    from Kamaelia.Util.Console import ConsoleEchoer

    width = 1024
    height = 384

    pgd = PygameDisplay(width=width, height=height).activate()
    PygameDisplay.setDisplayService(pgd)

    Graphline(
        CANVAS=Canvas(position=(0, 0), size=(width, height)),
        PEN=Pen(),
        STROKER=StrokeRecogniser(),
        OUTPUT=ConsoleEchoer(),
        linkages={
            ("CANVAS", "eventsOut"): ("PEN", "inbox"),
            ("PEN", "outbox"): ("CANVAS", "inbox"),
            ("PEN", "points"): ("STROKER", "inbox"),
            ("STROKER", "outbox"): ("OUTPUT", "inbox"),
            ("STROKER", "drawing"): ("CANVAS", "inbox"),
        },
    ).run()
Exemplo n.º 26
0
        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,
                linkages = {("READER", "outbox") : ("DECODER", "inbox"),
                            ("DECODER", "outbox") : ("LINKER", "inbox"),
Exemplo n.º 27
0
    def main(self):
        while 1:
            yield 1
            while self.dataReady("inbox"):
                msg = self.recv("inbox")
                self.forwardqueue.push(msg)

            while len(self.forwardqueue) >= self.chunksize:
                self.sendChunk()

            if self.nodelay:
                self.sendPartialChunk()

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished):
                    self.sendPartialChunk()
                    self.send(msg, "signal")
                    return
                elif isinstance(msg, shutdown):
                    self.send(msg, "signal")
                    return
            self.pause()


if __name__ == '__main__':
    from Kamaelia.Util.PipelineComponent import pipeline
    from Kamaelia.Util.Console import ConsoleEchoer, ConsoleReader

    pipeline(ConsoleReader(eol=""), Chunkifier(20), ConsoleEchoer()).run()
Exemplo n.º 28
0
        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
        def condition(x):
Exemplo n.º 29
0
def makeBasicSketcher(left=0, top=0, width=1024, height=768):
    return Graphline(
        CANVAS=Canvas(position=(left, top + 32 + 1),
                      size=(width - 192, (height - (32 + 15) - 1)),
                      bgcolour=(255, 255, 255),
                      notepad=notepad),
        PAINTER=Painter(),
        PALETTE=buildPalette(cols=colours,
                             order=colours_order,
                             topleft=(left + 64, top),
                             size=32),
        ERASER=Eraser(left, top),
        CLEAR=ClearPage(left + (64 * 5) + 32 * len(colours) + 1, top),
        SAVEDECK=SaveDeck(left + (64 * 8) + 32 * len(colours) + 1, top),
        LOADDECK=LoadDeck(left + (64 * 7) + 32 * len(colours) + 1, top),
        SMARTBOARD=SmartBoard(),
        DELETE=Delete(left + (64 * 6) + 32 * len(colours) + 1, top),
        CLOSEDECK=ClearScribbles(left + (64 * 9) + 32 * len(colours) + 1, top),
        QUIT=Quit(left + (64 * 10) + 32 * len(colours) + 1, top),
        PAGINGCONTROLS=PagingControls(left + 64 + 32 * len(colours) + 1, top),
        #LOCALPAGINGCONTROLS = LocalPagingControls(left+(64*6)+32*len(colours),top),
        LOCALPAGEEVENTS=LocalPageEventsFilter(),
        HISTORY=CheckpointSequencer(
            lambda X: [["LOAD", SLIDESPEC % (X, )]],
            lambda X: [["SAVE", SLIDESPEC % (X, )]],
            lambda X: [["CLEAR"]],
            initial=1,
            highest=num_pages,
            notepad=notepad,
        ),
        PAINT_SPLITTER=TwoWaySplitter(),
        #LOCALEVENT_SPLITTER = TwoWaySplitter(),
        DEBUG=ConsoleEchoer(),
        TICKER=Ticker(position=(left, top + height - 15),
                      background_colour=(220, 220, 220),
                      text_colour=(0, 0, 0),
                      text_height=(17),
                      render_right=(width),
                      render_bottom=(15)),
        linkages={
            ("CANVAS", "eventsOut"): ("PAINTER", "inbox"),
            ("PALETTE", "outbox"): ("PAINTER", "colour"),
            ("ERASER", "outbox"): ("PAINTER", "erase"),
            ("PAINTER", "outbox"): ("PAINT_SPLITTER", "inbox"),
            ("CLEAR", "outbox"): ("PAINT_SPLITTER", "inbox"),
            ("PAINT_SPLITTER", "outbox"): ("CANVAS", "inbox"),
            ("PAINT_SPLITTER", "outbox2"): ("", "outbox"),  # send to network
            ("SAVEDECK", "outbox"): ("CANVAS", "inbox"),
            ("LOADDECK", "outbox"): ("CANVAS", "inbox"),
            ("CLOSEDECK", "outbox"): ("CANVAS", "inbox"),
            ("DELETE", "outbox"): ("CANVAS", "inbox"),
            ("QUIT", "outbox"): ("CANVAS", "inbox"),

            #("LOCALPAGINGCONTROLS","outbox")  : ("LOCALEVENT_SPLITTER", "inbox"),
            #("LOCALEVENT_SPLITTER", "outbox2"): ("", "outbox"), # send to network
            #("LOCALEVENT_SPLITTER", "outbox") : ("LOCALPAGEEVENTS", "inbox"),
            ("", "inbox"): ("LOCALPAGEEVENTS", "inbox"),
            ("LOCALPAGEEVENTS", "false"): ("CANVAS", "inbox"),
            ("LOCALPAGEEVENTS", "true"): ("HISTORY", "inbox"),
            ("PAGINGCONTROLS", "outbox"): ("HISTORY", "inbox"),
            ("HISTORY", "outbox"): ("CANVAS", "inbox"),
            ("CANVAS", "outbox"): ("", "outbox"),
            ("CANVAS", "surfacechanged"): ("HISTORY", "inbox"),
            ("CANVAS", "toTicker"): ("TICKER", "inbox"),
            ("CANVAS", "toHistory"): ("HISTORY", "inbox"),
            ("SMARTBOARD", "colour"): ("PAINTER", "colour"),
            ("SMARTBOARD", "erase"): ("PAINTER", "erase"),
            ("SMARTBOARD", "toTicker"): ("TICKER", "inbox"),
        },
    )
Exemplo n.º 30
0
            'ADD NODE 6Node 6Node randompos -',
            'ADD NODE 7Node 7Node randompos sphere', 'ADD LINK 1Node 2Node',
            'ADD LINK 1Node 3Node', 'ADD LINK 1Node 4Node',
            'ADD LINK 1Node 5Node', 'ADD LINK 1Node 6Node',
            'ADD LINK 1Node 7Node',
            'ADD NODE 1Node:1Node 1Node:1Node randompos -',
            'ADD NODE 1Node:2Node 1Node:2Node randompos -',
            'ADD NODE 1Node:3Node 1Node:3Node randompos -',
            'ADD NODE 1Node:4Node 1Node:4Node randompos -',
            'ADD LINK 1Node:1Node 1Node:2Node',
            'ADD LINK 1Node:2Node 1Node:3Node',
            'ADD LINK 1Node:3Node 1Node:4Node',
            'ADD LINK 1Node:4Node 1Node:1Node',
            'ADD NODE 1Node:1Node:1Node 1Node:1Node:1Node randompos -',
            'ADD NODE 1Node:1Node:2Node 1Node:1Node:2Node randompos -',
            'ADD LINK 1Node:1Node:1Node 1Node:1Node:2Node',
            'ADD NODE 5Node:1Node 5Node:1Node randompos sphere',
            'ADD NODE 5Node:2Node 5Node:2Node randompos sphere',
            'ADD LINK 5Node:1Node 5Node:2Node'
        ]),
        TOKENS=lines_to_tokenlists(),
        VIEWER=TopologyViewer3D(),
        CONSOLEECHOER=ConsoleEchoer(),
        linkages={
            ("CONSOLEREADER", "outbox"): ("TOKENS", "inbox"),
            ("DATASOURCE", "outbox"): ("TOKENS", "inbox"),
            ("TOKENS", "outbox"): ("VIEWER", "inbox"),
            ("VIEWER", "outbox"): ("CONSOLEECHOER", "inbox"),
        }).run()

# Licensed to the BBC under a Contributor Agreement: CL
# 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.
# -------------------------------------------------------------------------
#
# Simple test harness for integrating TCP clients and servers in one system, sharing selector components etc.
#
#

import random
from Kamaelia.Protocol.FortuneCookieProtocol import FortuneCookieProtocol
from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Internet.TCPClient import TCPClient
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Chassis.Pipeline import Pipeline

from Kamaelia.Util.Introspector import Introspector

# Start the introspector and connect to a local visualiser
Pipeline(
    Introspector(),
    TCPClient("127.0.0.1", 1500),
).activate()

clientServerTestPort = random.randint(1501, 1599)

SimpleServer(protocol=FortuneCookieProtocol,
             port=clientServerTestPort).activate()

Pipeline(TCPClient("127.0.0.1", clientServerTestPort), ConsoleEchoer()).run()
Exemplo n.º 32
0
    import os
    
#    test="rate limit output"
#    test="rate limited input"
#    test="reached end of output"
#    test="outpipes"
    test="inpipes"
            
    if test=="rate limit output":
        Pipeline(
            UnixProcess("cat /dev/zero",32*1024*1024),
            LineSplit(),
            Chunk(10),
            RateLimiter(10),
            CumulateSize(),
            ConsoleEchoer(forwarder=True)
        ).run()

    elif test=="rate limited input":
        ratelimiter=RateLimiter(10)
        ratelimiter.inboxes['inbox'].setSize(None)
        Pipeline(
            ChargenComponent(),
            ratelimiter,
            UnixProcess("cat -",32),
            ConsoleEchoer(forwarder=True)
        ).run()

    elif test=="reached end of output":
        Pipeline(
            ChargenComponent(),