Exemple #1
0
time.sleep(1)
# time.sleep(5)

reverser = Handle(Reverser()).activate()

# There seems that there is not a big difference uncommenting this
# time.sleep(1)

reverser.put("hello world", "inbox")

# There seems that there is not a big difference uncommenting this
# time.sleep(1)

n = 0
print '*' * 30
initial = time.time()

while True:
    try:
        info = reverser.get("outbox")
    except:
        n += 1
        if n % 1000 == 0:
            current = time.time()
            if current - initial > 2:
                sys.exit(1)
    else:
        print n, info
        break
print '*' * 30
# -------------------------------------------------------------------------

# a slightly more complicated example of a TCP client, where we define an echo.

from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Protocol.EchoProtocol import EchoProtocol
from Kamaelia.Internet.TCPClient import TCPClient
from Axon.background import background
from Axon.Handle import Handle
import Queue
import time

background(slowmo=0.01).start()

PORT = 1900
# This starts an echo server in the background.
SimpleServer(protocol=EchoProtocol, port=PORT).activate()

# give the component time to commence listening on a port.
time.sleep(0.5)

echoClient = Handle(TCPClient(host="localhost", port=PORT)).activate()
while True:
    echoClient.put(raw_input(">>> "), "inbox")
    while 1:
        try:
            print echoClient.get("outbox")
            break
        except Queue.Empty:
            time.sleep(0.01)
# a slightly more complicated example of a TCP client, where we define an echo.

from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Protocol.EchoProtocol import EchoProtocol
from Kamaelia.Internet.TCPClient import TCPClient
from Axon.background import background
from Axon.Handle import Handle
import Queue
import time

background(slowmo=0.01).start()

PORT = 1900
# This starts an echo server in the background.
SimpleServer(protocol = EchoProtocol, port = PORT).activate()

# give the component time to commence listening on a port.
time.sleep(0.5)

echoClient = Handle(TCPClient(host = "localhost", port = PORT)).activate()
while True:
    echoClient.put(raw_input(">>> "),"inbox")
    while 1:
        try:
            print echoClient.get("outbox")
            break
        except Queue.Empty:
            time.sleep(0.01)

Exemple #4
0
    queue = Queue  # Python 3 compatibility change
except ImportError:
    # Python 3 compatibility change
    import queue
TD = Handle(
    TextDisplayer(position=(20, 90),
                  text_height=36,
                  screen_width=900,
                  screen_height=200,
                  background_color=(130, 0, 70),
                  text_color=(255, 255, 255))).activate()

TB = Handle(
    Textbox(position=(20, 340),
            text_height=36,
            screen_width=900,
            screen_height=400,
            background_color=(130, 0, 70),
            text_color=(255, 255, 255))).activate()

message = "hello\n"
while 1:
    time.sleep(1)
    try:
        data = TB.get("outbox")
        print(data)
        message = data
    except queue.Empty:
        pass
    TD.put(message, "inbox")
Exemple #5
0
TD = Handle(
         TextDisplayer(position=(20, 90),
                       text_height=36,
                       screen_width=900,
                       screen_height=200,
                       background_color=(130,0,70),
                       text_color=(255,255,255)
                      )
     ).activate()

TB = Handle(
        Textbox(position=(20, 340),
                text_height=36,
                screen_width=900,
                screen_height=400,
                background_color=(130,0,70),
                text_color=(255,255,255)
               )
     ).activate()

message = "hello\n"
while 1:
    time.sleep(1)
    try:
       data = TB.get("outbox")
       print (data)
       message = data
    except queue.Empty:
       pass
    TD.put(message, "inbox")
Exemple #6
0

class Reverser(Axon.Component.component):
    def main(self):
        while True:
            if self.dataReady('inbox'):
                item = self.recv('inbox')
                self.send(item[::-1], 'outbox') # strings have no "reverse" method, hence this indexing 'hack'.
            else: self.pause()
            yield 1


sys.stderr.write("""_Similar_ to Unix's "rev" tool, implemented using likefile., type stuff, it reverses it\n""")

reverser = Handle(Reverser()).activate()

while True:
    line = sys.stdin.readline()
    if line == "":
       break
    line = line.rstrip() # get rid of the newline (Doesn't just strip newline, so rev(rev()) would not work 'correctly')
    reverser.put(line, "inbox")

    while 1:
        try:
            enil = reverser.get("outbox")
            break
        except queue.Empty:
            time.sleep(0.1)
            
    print (enil) # This is doesn't necessarily put the right whitespace back
Exemple #7
0
    reverser = Handle(Pipeline(Reverser(), PublishTo("TEST"))).activate()

    collector = Handle(SubscribeTo("TEST")).activate()

    while True:
        line = sys.stdin.readline()
        if line == "":
            break
        line = line.rstrip()  # get rid of newline - looks odd otherwise :)

        reverser.put(line, "inbox")

        while 1:
            try:
                enil = collector.get("outbox")
                break
            except Queue.Empty:
                time.sleep(0.1)

        print "FROM SUBSCRIBE", enil

# Test 3
if 0:
    # This works
    background().start()
    Backplane("TEST").activate()

    reverser = Handle(Pipeline(Reverser(), PublishTo("TEST"))).activate()

    collector = Handle(Pipeline(SubscribeTo("TEST"))).activate()
Exemple #8
0
                item = self.recv('inbox')
                self.send(
                    item[::-1], 'outbox'
                )  # strings have no "reverse" method, hence this indexing 'hack'.
            else:
                self.pause()
            yield 1


sys.stderr.write(
    """_Similar_ to Unix's "rev" tool, implemented using likefile., type stuff, it reverses it\n"""
)

reverser = Handle(Reverser()).activate()

while True:
    line = sys.stdin.readline()
    if line == "":
        break
    line = line.rstrip(
    )  # get rid of the newline (Doesn't just strip newline, so rev(rev()) would not work 'correctly')
    reverser.put(line, "inbox")

    while 1:
        try:
            enil = reverser.get("outbox")
            break
        except queue.Empty:
            time.sleep(0.1)

    print(enil)  # This is doesn't necessarily put the right whitespace back
Exemple #9
0
    reverser = Handle(Pipeline(Reverser(), PublishTo("TEST"))).activate()

    collector = Handle(SubscribeTo("TEST")).activate()

    while True:
        line = sys.stdin.readline()
        if line == "":
            break
        line = line.rstrip()  # get rid of newline - looks odd otherwise :)

        reverser.put(line, "inbox")

        while 1:
            try:
                enil = collector.get("outbox")
                break
            except Queue.Empty:
                time.sleep(0.1)

        print "FROM SUBSCRIBE", enil

# Test 3
if 0:
    # This works
    background().start()
    Backplane("TEST").activate()

    reverser = Handle(Pipeline(Reverser(), PublishTo("TEST"))).activate()

    collector = Handle(Pipeline(SubscribeTo("TEST"))).activate()
Exemple #10
0
time.sleep(1)
# time.sleep(5)

reverser = Handle(Reverser()).activate()

# There seems that there is not a big difference uncommenting this
# time.sleep(1)

reverser.put("hello world", "inbox")

# There seems that there is not a big difference uncommenting this
# time.sleep(1)

n = 0
print '*' * 30
initial = time.time()

while True:
    try:
        info = reverser.get("outbox")
    except:
        n += 1
        if n % 1000 == 0:
            current = time.time()
            if current - initial > 2:
                sys.exit(1)
    else:
        print n, info
        break
print '*' * 30