Ejemplo n.º 1
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)),
           )
Ejemplo n.º 2
0
    def test_demuxer_with_fragmented_and_junk_laden_stream(self):
        """Test demuxer can cope with fragmented stream with junk between some packets."""

        from Kamaelia.Chassis.Pipeline import Pipeline
        from Kamaelia.Util.DataSource import DataSource
        from Kamaelia.Util.Console import ConsoleEchoer
        from Kamaelia.Device.DVB.SoftDemux import DVB_SoftDemuxer as SoftDemuxer

        # build a set of packets to pass through
        packet = " __________________________________ \n|  Hello there!                    /\n|                        %8d <\n|         Isn't this nice!!!       \\\n`-----------------------------------\n"

        src = []
        for i in range(0, 2000):
            src.append(packet % i)

        src.append(
            " __________________________________ \n|  This is...                  |   /\n|                              |  <\n|         the last packet!!!   |   \\\n`-----------------------------------\n"
        )

        # set up the pid filter to let all pids through to "outbox" outbox
        pidfilter = {}
        for i in range(0, 0x2000):
            pidfilter[i] = ["outbox"]

        Pipeline(
            DataSource(src),  # pump in packet payloads
            MakeTSPacket(),  # shove the barest packet header on the front
            InjectGarbage(),  # intersperse some garbage between packets
            Fragment(),  # rechunk/fragement the strings
            SoftDemuxer(pidfilter),
            ExtractPayload(),
            Expect(src, within=20.0
                   ),  # test we get what we expect, within a time limit
            #ConsoleEchoer(),
        ).run()
Ejemplo n.º 3
0
            if self.dataReady('inbox'):
                data = self.recv('inbox')
                self.outlist.append(data)
                if self.pass_thru:
                    self.send(data, 'outbox')
                count += 1

        if self.dataReady('control'):
            self.send(self.recv('control'), 'signal')
        else:
            self.send(producerFinished(self), 'signal')
        yield 1


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

    class mylist(list):
        def append(self, item):
            print ("Appending", item)
            super(mylist, self).append(item)

    R = mylist()
    Pipeline(
        DataSource([1,2,3,4]),
        DataSink(R)
    ).run()

    print (R)
    
Ejemplo n.º 4
0
__kamaelia_components__ = (RangeFilter, )

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

    print "Only items in ranges 1-5 and 8-12 should be output...\n\n"

    data = [
        (0, "shouldn't pass through"),
        (1, "YES!"),
        (2, "YES!"),
        (5, "YES!"),
        (6, "shouldn't pass through"),
        (7, "shouldn't pass through"),
        (8, "YES!"),
        (11, "YES!"),
        (12, "YES!"),
        (13, "shouldn't pass through"),
        (29, "shouldn't pass through"),
        (3, "YES!"),
    ]

    Pipeline(
        DataSource(data),
        RangeFilter([(1, 5), (8, 12)]),
        ConsoleEchoer(),
    ).run()
Ejemplo n.º 5
0
 DATASOURCE=DataSource([  # The first level
     'ADD NODE 1Node 1Node randompos teapot',
     'ADD NODE 2Node 2Node randompos -',
     'ADD NODE 3Node 3Node randompos sphere',
     'ADD NODE 4Node 4Node randompos -',
     'ADD NODE 5Node 5Node randompos sphere',
     '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',
     # The second level, children of 1Node
     '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',
     # The third level, children of 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',
     # The second level, children of 5Node
     'ADD NODE 5Node:1Node 5Node:1Node randompos sphere',
     'ADD NODE 5Node:2Node 5Node:2Node randompos sphere',
     'ADD LINK 5Node:1Node 5Node:2Node'
 ]),
Ejemplo n.º 6
0
 #                                 'ADD NODE 3Node 3Node randompos -', 'ADD NODE 4Node 4Node randompos -',
 #                                 'ADD LINK 1Node 2Node','ADD LINK 2Node 3Node', 'ADD LINK 3Node 4Node',
 #                                 'ADD LINK 4Node 1Node']),
 DATASOURCE=DataSource([
     'ADD NODE 1Node 1Node randompos teapot',
     'ADD NODE 2Node 2Node randompos -',
     'ADD NODE 3Node 3Node randompos sphere',
     'ADD NODE 4Node 4Node randompos -',
     'ADD NODE 5Node 5Node randompos sphere',
     '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(),
Ejemplo n.º 7
0
#     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.Util.DataSource import DataSource
from Kamaelia.Protocol.HTTP.HTTPClient import SingleShotHTTPClient, SimpleHTTPClient
from HTTPClient import SingleShotHTTPClient, SimpleHTTPClient
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.XML.SimpleXMLParser import SimpleXMLParser
from HTTPDataParser import HTTPDataParser

Pipeline(
    DataSource(["http://jibbering.com/foaf.rdf"]),
    SimpleHTTPClient(),
    #SingleShotHTTPClient("http://www.w3.org/2007/08/pyRdfa/extract?uri=http://apassant.net/about/#alex"),
    #SimpleXMLParser(),
    HTTPDataParser(),
    ConsoleEchoer()
).run()
Ejemplo n.º 8
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()
if __name__ == "__main__":
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Visualisation.PhysicsGraph.lines_to_tokenlists import lines_to_tokenlists
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer
    from GenericTopologyViewer import GenericTopologyViewer
    from Kamaelia.Chassis.Graphline import Graphline

    # Data can be from both DataSource and console inputs
    Graphline(
        CONSOLEREADER=ConsoleReader(),
        DATASOURCE=DataSource([
            "  person  mum   gender=female,photo=../Files/mum.jpg,width=80,height=80 ",
            '  ', """   
                    """,
            'person dad gender=male,shape=rect,width=80,height=80',
            '  person  son   gender=male,photo=../Files/son.gif,width=60,height=60',
            'person son photo=../Files/son1.gif', 'person daughter radius=20',
            'person daughter radius=100', ' childof  (  mum  , son  ) ',
            'childof(mum, daughter)', 'childof(dad, son)',
            'childof(dad, daughter)'
        ]),
        PARSER=RelationAttributeParser(),
        TOKENS=lines_to_tokenlists(),
        VIEWER=GenericTopologyViewer(),
        CONSOLEECHOER=ConsoleEchoer(),
        linkages={
            ("CONSOLEREADER", "outbox"): ("PARSER", "inbox"),
            ("DATASOURCE", "outbox"): ("PARSER", "inbox"),
            ("PARSER", "outbox"): ("TOKENS", "inbox"),
            ("TOKENS", "outbox"): ("VIEWER", "inbox"),
            ("VIEWER", "outbox"): ("CONSOLEECHOER", "inbox"),
Ejemplo n.º 10
0
m=audio 49170 RTP/AVP 0
m=video 51372 RTP/AVP 99
a=rtpmap:99 h263-1998/90000

v=0
o=bfcrd 1140190501 1140190501 IN IP4 132.185.224.80
s=BFC ONE [H.264/AVC]
i=Multicast trial service from the BBC! Get BFC FLURBLE here!
a=x-qt-text-nam:BFC FLURBLE [H.264/AVC]
a=x-qt-text-aut:BFC Research & Development
a=x-qt-text-cpy:Copyright (c) 2006 British Flurbling Corporation
u=http://www.bbc.co.uk/multicast/
e=Multicast Support <*****@*****.**>
t=0 0
c=IN IP4 233.122.227.151/32
m=video 5150 RTP/AVP 33
b=AS:1200000
a=type:broadcast
a=mux:m2t

v=0


""".splitlines()

    Pipeline(
        DataSource(sdp),
        SDPParser(),
        ConsoleEchoer(),
    ).run()
Ejemplo n.º 11
0
                command = parseEntity(item)
                nodes.append(command)

        for node in nodes:
            self.send(node, "outbox")
        for link in links:
            self.send(link, "outbox")
        yield 1
        yield 1
        self.send(self.shutdown_mess, "signal")


if __name__ == "__main__":
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Visualisation.PhysicsGraph.lines_to_tokenlists import lines_to_tokenlists
    from Kamaelia.Util.Console import ConsoleEchoer
    from RelationGenderVisualiser import RelationGenderVisualiser
    from Kamaelia.Chassis.Pipeline import Pipeline

    Pipeline(
        DataSource([
            '  person  mum   gender=Female ', '  ', """   
                    """, '  person  son  photo="Files/dad.gif"',
            'person daughter gender=Female', ' childof  (  mum  , son  ) ',
            'childof(mum, daughter)'
        ]),
        RelationGenderParser(),
        lines_to_tokenlists(),
        ConsoleEchoer(),
        #RelationGenderVisualiser(),
    ).run()
Ejemplo n.º 12
0
                        nodes.append((node_id, uri))

            for node in nodes:
                self.parentNode_id = node[0]
                uri = node[1]
                try:
                    self.fetch_data(uri, current_layer + 1)
                except:
                    pass


if __name__ == "__main__":
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer
    from TopologyViewer3DWithParams import TopologyViewer3DWithParams
    from Kamaelia.Chassis.Graphline import Graphline

    # Data can be from both DataSource and console inputs
    Graphline(
        CONSOLEREADER=ConsoleReader('>>>'),
        DATASOURCE=DataSource(["http://fooshed.net/foaf.rdf 2 10"]),
        PARSER=RDFParser(),
        VIEWER=TopologyViewer3DWithParams(),
        CONSOLEECHOER=ConsoleEchoer(),
        linkages={
            ("CONSOLEREADER", "outbox"): ("PARSER", "inbox"),
            ("DATASOURCE", "outbox"): ("PARSER", "inbox"),
            ("PARSER", "outbox"): ("VIEWER", "inbox"),
            ("VIEWER", "outbox"): ("CONSOLEECHOER", "inbox"),
            #("PARSER","outbox") : ("CONSOLEECHOER","inbox"),
        }).run()
Ejemplo n.º 13
0
    def main(self):
        """Main loop"""
        while 1:
            while self.dataReady("inbox"):
                items = self.recv("inbox")
                self.send( max(items), "outbox")
                
            while self.dataReady("control"):
                msg = self.recv("control")
                self.send(msg,"signal")
                if isinstance(msg,(producerFinished,shutdownMicroprocess)):
                    return
            
            self.pause()
            yield 1

__kamaelia_components__ = ( Max, )

            
if __name__ == "__main__":
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Chassis.Pipeline import Pipeline
    
    Pipeline( DataSource( [ (1,4,2,3), ('d','a','b','c'), ('xx','xxx') ] ),
              Max(),
              ConsoleEchoer(),
            ).run()

    
    
Ejemplo n.º 14
0
    proxy = os.environ["http_proxy"]
except KeyError:
    print "Not using a proxy. If you want to use a proxy, you need to do something like this"
    print "export http_proxy=http://www-cache.your.site.com:3128/"
    proxy = None

print username, password, proxy

pids = ["b00001", "b00002", "b00003"]
# keywords = [ "Sarah Jane", "CBBC"] #trending topics earlier

trends_url = "http://api.twitter.com/1/trends/current.json"
raw_trending = get_url(trends_url)
trending_cooked = cjson.decode(raw_trending)

print "Trending Topics", trending_cooked

trending_topics = [X["query"] for X in trending_cooked["trends"].values()[0]]

keywords = trending_topics

# request = [ pids, keywords ]
request = [keywords, pids]  # docstring wrong, should be this way round

Pipeline(
    DataSource([request]),
    TwitterStream(username=username, password=password, proxy=proxy),
    PureTransformer(lambda x: repr(x) + "\n"),
    ConsoleEchoer(),
).run()
 #                                 'ADD NODE 3Node 3Node randompos -', 'ADD NODE 4Node 4Node randompos -',
 #                                 'ADD LINK 1Node 2Node','ADD LINK 2Node 3Node', 'ADD LINK 3Node 4Node',
 #                                 'ADD LINK 4Node 1Node']),
 DATASOURCE=DataSource([
     'ADD NODE 1Node 1Node randompos teapot image=../Files/son.gif',
     'ADD NODE 2Node 2Node randompos - image=../Files/dad.gif',
     'ADD NODE 3Node 3Node randompos sphere image=../Files/mum.gif',
     'ADD NODE 4Node 4Node randompos - image=http://kamaelia.sourceforge.net/Kamaelia.gif',
     'ADD NODE 5Node 5Node randompos sphere image=../Files/dad.gif',
     'ADD NODE 6Node 6Node randompos - image=../Files/son.gif',
     'ADD NODE 7Node 7Node randompos sphere image=../Files/son1.gif',
     '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 - image=../Files/son.gif',
     'ADD NODE 1Node:2Node 1Node:2Node randompos - image=../Files/dad.gif',
     'ADD NODE 1Node:3Node 1Node:3Node randompos - image=../Files/mum.gif',
     'ADD NODE 1Node:4Node 1Node:4Node randompos - image=../Files/son1.gif',
     '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=TopologyViewer3DWithParams(),
 CONSOLEECHOER=ConsoleEchoer(),
Ejemplo n.º 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()
Ejemplo n.º 17
0
                if self.mustStop():
                    raise UserWarning("STOP")

                self.pause()
                yield 1


__kamaelia_components__ = (TwoWaySplitter, )

if __name__ == "__main__":
    from Kamaelia.Experimental.Chassis import Graphline, Pipeline
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.RateFilter import MessageRateLimit
    from Kamaelia.Util.Console import ConsoleEchoer

    Graphline(SRC=DataSource([str(i) + "\n" for i in range(0, 100)]),
              SPLIT=TwoWaySplitter(),
              DST1=Pipeline(
                  10,
                  MessageRateLimit(10, 5),
                  ConsoleEchoer(),
              ),
              DST2=Pipeline(
                  10,
                  MessageRateLimit(20, 5),
                  ConsoleEchoer(),
              ),
              linkages={
                  ("SRC", "outbox"): ("SPLIT", "inbox"),
                  ("SPLIT", "outbox"): ("DST1", "inbox"),
                  ("SPLIT", "outbox2"): ("DST2", "inbox"),
if __name__ == "__main__":
    import time

    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"),
Ejemplo n.º 19
0
if __name__=="__main__":
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Chassis.Pipeline import Pipeline
    
    print "Only items in ranges 1-5 and 8-12 should be output...\n\n"
    
    data = [
        (0, "shouldn't pass through"),
        (1, "YES!"),
        (2, "YES!"),
        (5, "YES!"),
        (6, "shouldn't pass through"),
        
        (7, "shouldn't pass through"),
        (8, "YES!"),
        (11, "YES!"),
        (12, "YES!"),
        (13, "shouldn't pass through"),
        
        (29, "shouldn't pass through"),
        (3, "YES!"),
    ]
    
    Pipeline( DataSource( data ),
              RangeFilter( [ (1,5), (8,12) ] ),
              ConsoleEchoer(),
            ).run()

    print
Ejemplo n.º 20
0
    def fragment(packets, minsize, maxsize):
        fragments = []
        tmp = ""
        reqd = random.randrange(minsize, maxsize + 1)
        for packet in packets:
            tmp = tmp + packet
            while len(tmp) >= reqd:
                fragments.append(tmp[:reqd])
                tmp = tmp[reqd:]
                reqd = random.randrange(minsize, maxsize + 1)
        if tmp:
            fragments.append(tmp)
        return fragments

    packets = [(DVB_RESYNC + ("%08d" % i) + " " * 179) for i in range(0, 100)]
    mushed = fragment(pad(packets, 0, 1000), 2, 588)

    Graphline(ONTEST=Pipeline(
        DataSource(mushed),
        AlignTSPackets(),
    ),
              SRC2=DataSource(packets),
              CMP=Comparator(),
              VALID=ConsoleEchoer(),
              linkages={
                  ("ONTEST", "outbox"): ("CMP", "inA"),
                  ("SRC2", "outbox"): ("CMP", "inB"),
                  ("CMP", "outbox"): ("VALID", "inbox"),
              }).run()
Ejemplo n.º 21
0
# 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.
'''
This file contains an example of using Kamaelia.Apps.SA.DSL.DataSink
'''

from Kamaelia.Util.DataSource import DataSource
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Apps.SA.DSL import DataSink


class mylist(list):
    def append(self, item):
        print "Appending", item
        super(mylist, self).append(item)


R = mylist()
Pipeline(DataSource([1, 2, 3, 4]), DataSink(R)).run()

print R
Ejemplo n.º 22
0
                    serialisedData = cjson.encode(data)
                    self.send(serialisedData, "outbox")

            yield 1

        self.send(self.shutdown_mess, "signal")


if __name__ == "__main__" and 0:
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Chassis.Graphline import Graphline

    # Data can be from both DataSource and console inputs
    Graphline(DATASOURCE=DataSource([['foo', {
        'bar': ('baz', None, 1.0, 2)
    }]]),
              JSONENCODER=JSONEncoder(),
              CONSOLEECHOER=ConsoleEchoer(),
              linkages={
                  ("DATASOURCE", "outbox"): ("JSONENCODER", "inbox"),
                  ("JSONENCODER", "outbox"): ("CONSOLEECHOER", "inbox"),
              }).run()


class JSONDecoder(component):
    """\
    JSONDecoder(...) -> new JSONDecoder component.
     
    Kamaelia component to decode data encoded by JSON coding.
    """
 #                                 'ADD NODE 3Node 3Node randompos -', 'ADD NODE 4Node 4Node randompos -',
 #                                 'ADD LINK 1Node 2Node','ADD LINK 2Node 3Node', 'ADD LINK 3Node 4Node',
 #                                 'ADD LINK 4Node 1Node']),
 DATASOURCE=DataSource([
     'ADD NODE 1Node 1Node randompos teapot image=../../../Docs/cat.gif',
     'ADD NODE 2Node 2Node randompos - image=../../../Docs/cat.gif',
     'ADD NODE 3Node 3Node randompos sphere image=../../../Docs/cat.gif',
     'ADD NODE 4Node 4Node randompos - image=http://kamaelia.sourceforge.net/Kamaelia.gif',
     'ADD NODE 5Node 5Node randompos sphere image=http://edit.kamaelia.org/Kamaelia.gif',
     '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 - image=../../../Docs/cat.gif',
     '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 - image=../../../Docs/cat.gif',
     '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 image=../../../Docs/cat.gif',
     'ADD NODE 5Node:2Node 5Node:2Node randompos sphere',
     'ADD LINK 5Node:1Node 5Node:2Node'
 ]),
 TOKENS=lines_to_tokenlists(),
 VIEWER=TopologyViewer3DWithParams(),
 CONSOLEECHOER=ConsoleEchoer(),
Ejemplo n.º 24
0
        for item in X:            
            if re.match('(.+)\((.+),(.+)\)',item): # relation
                command = parseRelation(item)
                links.append(command)
            else: # entity
                command = parseEntity(item)
                nodes.append(command)
        
        for node in nodes:
            self.send(node, "outbox")
        for link in links:
            self.send(link, "outbox")
        yield 1
        yield 1
        self.send(self.shutdown_mess,"signal")
        
if __name__ == "__main__":
    from Kamaelia.Util.DataSource import DataSource
    from Kamaelia.Visualisation.PhysicsGraph.lines_to_tokenlists import lines_to_tokenlists
    #from Kamaelia.Util.Console import ConsoleEchoer
    from Kamaelia.Visualisation.PhysicsGraph.TopologyViewer import TopologyViewer
    from Kamaelia.Chassis.Pipeline import Pipeline
        
    Pipeline(
        DataSource(['  person  mum  ', '  ', """   
                          """, '  person  son ', ' childof  (  mum  , son  ) ']),
        RelationParser(),
        lines_to_tokenlists(),
        #ConsoleEchoer(),
        TopologyViewer(),
    ).run()        
Ejemplo n.º 25
0
        With(item = TCPClient("www-cache", 8080),

             ProxyReq  = ProxyReq("kamaelia.svn.sourceforge.net", 443),
             ProxyResp = ProxyResp(),
             SSL_Maker = OneShot(),
             HTTPReq   = HTTPReq(Request),
             HTTPResp  = HTTPResp(Request),
             sequence = [ 
                { ("ProxyReq", "outbox")   : ("item", "inbox"), ("item", "outbox") : ("ProxyResponse", "inbox") },
                { ("SSL_Maker", "outbox") : ("item", "makessl") },
                { ("HTTPReq", "outbox")   : ("item", "inbox"), ("item", "outbox") : ("HTTPResponse", "inbox") },
             ]
        )

    if testing == 3:
        Pipeline( DataSource(["hello\n", "world\n"]),
                  Tagger("mytag"),
                  Sink("Hello")
        ).run()

    if testing == 4:

        With(item = Tagger("^^''--..__"),

             SourceOne  = DataSource(["hello\n", "world\n"]),
             SinkOne    = Sink("SinkOne"),
             MiddleStep = OneShot("MiddleStep"),
             FailStep   = FailingComponent("bla"),

             SourceTwo  = DataSource(["game\n", "over\n"]),
             SinkTwo    = Sink("SinkTwo"),