You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2015/06/22 14:57:05 UTC
[02/34] qpid-proton git commit: PROTON-490: futurize examples
PROTON-490: futurize examples
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/aae1d20a
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/aae1d20a
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/aae1d20a
Branch: refs/heads/master
Commit: aae1d20a42dcaded08b8daec4cf43bd5e1fde970
Parents: 677729a
Author: Ken Giusti <kg...@apache.org>
Authored: Thu Apr 16 14:57:08 2015 -0400
Committer: Ken Giusti <kg...@apache.org>
Committed: Mon Apr 20 12:46:20 2015 -0400
----------------------------------------------------------------------
examples/python/abstract_server.py | 3 ++-
examples/python/client.py | 3 ++-
examples/python/client_http.py | 3 ++-
examples/python/db_ctrl.py | 7 ++++---
examples/python/db_recv.py | 3 ++-
examples/python/db_send.py | 11 ++++++-----
examples/python/direct_recv.py | 3 ++-
examples/python/direct_send.py | 3 ++-
examples/python/helloworld.py | 3 ++-
examples/python/helloworld_blocking.py | 3 ++-
examples/python/helloworld_direct.py | 3 ++-
examples/python/helloworld_direct_tornado.py | 3 ++-
examples/python/helloworld_tornado.py | 3 ++-
examples/python/messenger/async.py | 3 ++-
examples/python/messenger/client.py | 7 ++++---
examples/python/messenger/recv.py | 7 ++++---
examples/python/messenger/recv_async.py | 11 ++++++-----
examples/python/messenger/send.py | 3 ++-
examples/python/messenger/send_async.py | 9 +++++----
examples/python/messenger/server.py | 5 +++--
examples/python/proton_server.py | 3 ++-
examples/python/queue_browser.py | 3 ++-
examples/python/reactor/cat.py | 3 ++-
examples/python/reactor/count-randomly.py | 9 +++++----
examples/python/reactor/counter.py | 7 ++++---
examples/python/reactor/delegates.py | 5 +++--
examples/python/reactor/echo.py | 5 +++--
examples/python/reactor/global-logger.py | 9 +++++----
examples/python/reactor/goodbye-world.py | 5 +++--
examples/python/reactor/handlers.py | 7 ++++---
examples/python/reactor/hello-world.py | 3 ++-
examples/python/reactor/reactor-logger.py | 7 ++++---
examples/python/reactor/recv.py | 3 ++-
examples/python/reactor/scheduling.py | 7 ++++---
examples/python/reactor/tornado-hello-world.py | 3 ++-
examples/python/reactor/unhandled.py | 3 ++-
examples/python/recurring_timer.py | 5 +++--
examples/python/recurring_timer_tornado.py | 5 +++--
examples/python/selected_recv.py | 3 ++-
examples/python/server.py | 5 +++--
examples/python/server_direct.py | 7 ++++---
examples/python/server_tx.py | 5 +++--
examples/python/simple_recv.py | 3 ++-
examples/python/simple_send.py | 3 ++-
examples/python/sync_client.py | 3 ++-
examples/python/tx_recv.py | 3 ++-
examples/python/tx_recv_interactive.py | 11 ++++++-----
examples/python/tx_send.py | 3 ++-
48 files changed, 141 insertions(+), 93 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/abstract_server.py
----------------------------------------------------------------------
diff --git a/examples/python/abstract_server.py b/examples/python/abstract_server.py
index 2d0de32..fed7fb2 100755
--- a/examples/python/abstract_server.py
+++ b/examples/python/abstract_server.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton_server import Server
class Application(Server):
@@ -27,7 +28,7 @@ class Application(Server):
def on_request(self, request, reply_to):
response = request.upper()
self.send(response, reply_to)
- print "Request from: %s" % reply_to
+ print("Request from: %s" % reply_to)
try:
Application("localhost:5672", "examples").run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/client.py
----------------------------------------------------------------------
diff --git a/examples/python/client.py b/examples/python/client.py
index a116175..18dc81a 100755
--- a/examples/python/client.py
+++ b/examples/python/client.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton import Message
from proton.handlers import MessagingHandler
@@ -43,7 +44,7 @@ class Client(MessagingHandler):
self.next_request()
def on_message(self, event):
- print "%s => %s" % (self.requests.pop(0), event.message.body)
+ print("%s => %s" % (self.requests.pop(0), event.message.body))
if self.requests:
self.next_request()
else:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/client_http.py
----------------------------------------------------------------------
diff --git a/examples/python/client_http.py b/examples/python/client_http.py
index cd0d63f..bf65639 100755
--- a/examples/python/client_http.py
+++ b/examples/python/client_http.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import tornado.ioloop
import tornado.web
from proton import Message
@@ -51,7 +52,7 @@ class Client(MessagingHandler):
def on_message(self, event):
if self.sent:
request, handler = self.sent.pop(0)
- print "%s => %s" % (request, event.message.body)
+ print("%s => %s" % (request, event.message.body))
handler(event.message.body)
self.do_request()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/db_ctrl.py
----------------------------------------------------------------------
diff --git a/examples/python/db_ctrl.py b/examples/python/db_ctrl.py
index b28e0eb..04770ce 100755
--- a/examples/python/db_ctrl.py
+++ b/examples/python/db_ctrl.py
@@ -18,11 +18,12 @@
# under the License.
#
+from __future__ import print_function
import sqlite3
import sys
if len(sys.argv) < 3:
- print "Usage: %s [init|insert|list] db" % sys.argv[0]
+ print("Usage: %s [init|insert|list] db" % sys.argv[0])
else:
conn = sqlite3.connect(sys.argv[2])
with conn:
@@ -35,7 +36,7 @@ else:
cursor.execute("SELECT * FROM records")
rows = cursor.fetchall()
for r in rows:
- print r
+ print(r)
elif sys.argv[1] == "insert":
while True:
l = sys.stdin.readline()
@@ -43,4 +44,4 @@ else:
conn.execute("INSERT INTO records(description) VALUES (?)", (l.rstrip(),))
conn.commit()
else:
- print "Unrecognised command: %s" % sys.argv[1]
+ print("Unrecognised command: %s" % sys.argv[1])
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/db_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/db_recv.py b/examples/python/db_recv.py
index d8dd7bc..8c79049 100755
--- a/examples/python/db_recv.py
+++ b/examples/python/db_recv.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton.handlers import MessagingHandler
from proton.reactor import ApplicationEvent, Container, EventInjector
@@ -58,7 +59,7 @@ class Recv(MessagingHandler):
self.received += 1
self.last_id = id
self.db.insert(id, event.message.body, ApplicationEvent("record_inserted", delivery=event.delivery))
- print "inserted message %s" % id
+ print("inserted message %s" % id)
else:
self.release(event.delivery)
else:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/db_send.py
----------------------------------------------------------------------
diff --git a/examples/python/db_send.py b/examples/python/db_send.py
index 6464fa6..99558d5 100755
--- a/examples/python/db_send.py
+++ b/examples/python/db_send.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
import Queue
import time
@@ -49,7 +50,7 @@ class Send(MessagingHandler):
def on_records_loaded(self, event):
if self.records.empty():
if event.subject == self.load_count:
- print "Exhausted available data, waiting to recheck..."
+ print("Exhausted available data, waiting to recheck...")
# check for new data after 5 seconds
self.container.schedule(5, self)
else:
@@ -57,7 +58,7 @@ class Send(MessagingHandler):
def request_records(self):
if not self.records.full():
- print "loading records..."
+ print("loading records...")
self.load_count += 1
self.db.load(self.records, event=ApplicationEvent("records_loaded", link=self.sender, subject=self.load_count))
@@ -71,13 +72,13 @@ class Send(MessagingHandler):
id = record['id']
self.sender.send(Message(id=id, durable=True, body=record['description']), tag=str(id))
self.sent += 1
- print "sent message %s" % id
+ print("sent message %s" % id)
self.request_records()
def on_settled(self, event):
id = int(event.delivery.tag)
self.db.delete(id)
- print "settled message %s" % id
+ print("settled message %s" % id)
self.confirmed += 1
if self.confirmed == self.target:
event.connection.close()
@@ -88,7 +89,7 @@ class Send(MessagingHandler):
self.sent = self.confirmed
def on_timer_task(self, event):
- print "Rechecking for data..."
+ print("Rechecking for data...")
self.request_records()
parser = optparse.OptionParser(usage="usage: %prog [options]",
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/direct_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/direct_recv.py b/examples/python/direct_recv.py
index 92f712c..1c6bf36 100755
--- a/examples/python/direct_recv.py
+++ b/examples/python/direct_recv.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton.handlers import MessagingHandler
from proton.reactor import Container
@@ -37,7 +38,7 @@ class Recv(MessagingHandler):
# ignore duplicate message
return
if self.expected == 0 or self.received < self.expected:
- print event.message.body
+ print(event.message.body)
self.received += 1
if self.received == self.expected:
event.receiver.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/direct_send.py
----------------------------------------------------------------------
diff --git a/examples/python/direct_send.py b/examples/python/direct_send.py
index 0bfad17..f551e1e 100755
--- a/examples/python/direct_send.py
+++ b/examples/python/direct_send.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton import Message
from proton.handlers import MessagingHandler
@@ -43,7 +44,7 @@ class Send(MessagingHandler):
def on_accepted(self, event):
self.confirmed += 1
if self.confirmed == self.total:
- print "all messages confirmed"
+ print("all messages confirmed")
event.connection.close()
self.acceptor.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/helloworld.py
----------------------------------------------------------------------
diff --git a/examples/python/helloworld.py b/examples/python/helloworld.py
index d741f5e..d73a4cb 100755
--- a/examples/python/helloworld.py
+++ b/examples/python/helloworld.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
@@ -38,7 +39,7 @@ class HelloWorld(MessagingHandler):
event.sender.close()
def on_message(self, event):
- print event.message.body
+ print(event.message.body)
event.connection.close()
Container(HelloWorld("localhost:5672", "examples")).run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/helloworld_blocking.py
----------------------------------------------------------------------
diff --git a/examples/python/helloworld_blocking.py b/examples/python/helloworld_blocking.py
index 62b6105..049f148 100755
--- a/examples/python/helloworld_blocking.py
+++ b/examples/python/helloworld_blocking.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.utils import BlockingConnection
from proton.handlers import IncomingMessageHandler
@@ -27,7 +28,7 @@ receiver = conn.create_receiver("examples")
sender = conn.create_sender("examples")
sender.send(Message(body=u"Hello World!"));
msg = receiver.receive(timeout=30)
-print msg.body
+print(msg.body)
receiver.accept()
conn.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/helloworld_direct.py
----------------------------------------------------------------------
diff --git a/examples/python/helloworld_direct.py b/examples/python/helloworld_direct.py
index 2ad78a7..d6374a2 100755
--- a/examples/python/helloworld_direct.py
+++ b/examples/python/helloworld_direct.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
@@ -36,7 +37,7 @@ class HelloWorld(MessagingHandler):
event.sender.close()
def on_message(self, event):
- print event.message.body
+ print(event.message.body)
def on_accepted(self, event):
event.connection.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/helloworld_direct_tornado.py
----------------------------------------------------------------------
diff --git a/examples/python/helloworld_direct_tornado.py b/examples/python/helloworld_direct_tornado.py
index 2466f80..9ef2ed7 100755
--- a/examples/python/helloworld_direct_tornado.py
+++ b/examples/python/helloworld_direct_tornado.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.handlers import MessagingHandler
from proton_tornado import Container
@@ -36,7 +37,7 @@ class HelloWorld(MessagingHandler):
event.sender.close()
def on_message(self, event):
- print event.message.body
+ print(event.message.body)
def on_accepted(self, event):
event.connection.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/helloworld_tornado.py
----------------------------------------------------------------------
diff --git a/examples/python/helloworld_tornado.py b/examples/python/helloworld_tornado.py
index d4b32cf..3cb2ad1 100755
--- a/examples/python/helloworld_tornado.py
+++ b/examples/python/helloworld_tornado.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.handlers import MessagingHandler
from proton_tornado import Container
@@ -38,7 +39,7 @@ class HelloWorld(MessagingHandler):
event.sender.close()
def on_message(self, event):
- print event.message.body
+ print(event.message.body)
event.connection.close()
Container(HelloWorld("localhost:5672", "examples")).run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/messenger/async.py
----------------------------------------------------------------------
diff --git a/examples/python/messenger/async.py b/examples/python/messenger/async.py
index 14fc4c9..b3f5c45 100755
--- a/examples/python/messenger/async.py
+++ b/examples/python/messenger/async.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys
from proton import *
@@ -72,7 +73,7 @@ class CallbackAdapter:
self.messenger.accept(t)
except:
ex = sys.exc_info()[1]
- print "Exception:", ex
+ print("Exception:", ex)
self.messenger.reject(t)
def send(self, message, on_status=None):
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/messenger/client.py
----------------------------------------------------------------------
diff --git a/examples/python/messenger/client.py b/examples/python/messenger/client.py
index 3146e45..62fc16e 100755
--- a/examples/python/messenger/client.py
+++ b/examples/python/messenger/client.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse
from proton import *
@@ -48,8 +49,8 @@ if opts.reply_to[:2] == "~/":
mng.recv(1)
try:
mng.get(msg)
- print msg.address, msg.subject
- except Exception, e:
- print e
+ print(msg.address, msg.subject)
+ except Exception as e:
+ print(e)
mng.stop()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/messenger/recv.py
----------------------------------------------------------------------
diff --git a/examples/python/messenger/recv.py b/examples/python/messenger/recv.py
index e19ddad..5771bd7 100755
--- a/examples/python/messenger/recv.py
+++ b/examples/python/messenger/recv.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse
from proton import *
@@ -46,9 +47,9 @@ while True:
while mng.incoming:
try:
mng.get(msg)
- except Exception, e:
- print e
+ except Exception as e:
+ print(e)
else:
- print msg.address, msg.subject or "(no subject)", msg.properties, msg.body
+ print(msg.address, msg.subject or "(no subject)", msg.properties, msg.body)
mng.stop()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/messenger/recv_async.py
----------------------------------------------------------------------
diff --git a/examples/python/messenger/recv_async.py b/examples/python/messenger/recv_async.py
index ba4f063..b38c31a 100755
--- a/examples/python/messenger/recv_async.py
+++ b/examples/python/messenger/recv_async.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse
from async import *
@@ -31,25 +32,25 @@ if not args:
class App(CallbackAdapter):
def on_start(self):
- print "Started"
+ print("Started")
for a in args:
- print "Subscribing to:", a
+ print("Subscribing to:", a)
self.messenger.subscribe(a)
self.messenger.recv()
def on_recv(self, msg):
- print "Received:", msg
+ print("Received:", msg)
if msg.body == "die":
self.stop()
if msg.reply_to:
self.message.clear()
self.message.address = msg.reply_to
self.message.body = "Reply for: %s" % msg.body
- print "Replied:", self.message
+ print("Replied:", self.message)
self.send(self.message)
def on_stop(self):
- print "Stopped"
+ print("Stopped")
a = App(Messenger())
a.run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/messenger/send.py
----------------------------------------------------------------------
diff --git a/examples/python/messenger/send.py b/examples/python/messenger/send.py
index 139f6e8..f40e7b1 100755
--- a/examples/python/messenger/send.py
+++ b/examples/python/messenger/send.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse
from proton import *
@@ -39,6 +40,6 @@ for m in args:
mng.put(msg)
mng.send()
-print "sent:", ", ".join(args)
+print("sent:", ", ".join(args))
mng.stop()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/messenger/send_async.py
----------------------------------------------------------------------
diff --git a/examples/python/messenger/send_async.py b/examples/python/messenger/send_async.py
index 304aceb..50f7a68 100755
--- a/examples/python/messenger/send_async.py
+++ b/examples/python/messenger/send_async.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse
from async import *
@@ -33,7 +34,7 @@ if not args:
class App(CallbackAdapter):
def on_start(self):
- print "Started"
+ print("Started")
self.message.clear()
self.message.address = opts.address
self.message.reply_to = opts.reply_to
@@ -45,19 +46,19 @@ class App(CallbackAdapter):
self.messenger.recv()
def on_status(self, status):
- print "Status:", status
+ print("Status:", status)
if not opts.reply_to or opts.reply_to[0] != "~":
args.pop(0)
if not args: self.stop()
def on_recv(self, msg):
- print "Received:", msg
+ print("Received:", msg)
if opts.reply_to and opts.reply_to[0] == "~":
args.pop(0)
if not args: self.stop()
def on_stop(self):
- print "Stopped"
+ print("Stopped")
a = App(Messenger())
a.run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/messenger/server.py
----------------------------------------------------------------------
diff --git a/examples/python/messenger/server.py b/examples/python/messenger/server.py
index 01196be..8c25879 100755
--- a/examples/python/messenger/server.py
+++ b/examples/python/messenger/server.py
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse
from proton import *
@@ -38,7 +39,7 @@ def dispatch(request, response):
if request.subject:
response.subject = "Re: %s" % request.subject
response.properties = request.properties
- print "Dispatched %s %s" % (request.subject, request.properties)
+ print("Dispatched %s %s" % (request.subject, request.properties))
msg = Message()
reply = Message()
@@ -50,7 +51,7 @@ while True:
if mng.incoming > 0:
mng.get(msg)
if msg.reply_to:
- print msg.reply_to
+ print(msg.reply_to)
reply.address = msg.reply_to
reply.correlation_id = msg.correlation_id
reply.body = msg.body
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/proton_server.py
----------------------------------------------------------------------
diff --git a/examples/python/proton_server.py b/examples/python/proton_server.py
index b92261c..c2520c1 100755
--- a/examples/python/proton_server.py
+++ b/examples/python/proton_server.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -38,7 +39,7 @@ class Server(MessagingHandler):
self.relay = self.container.create_sender(self.conn, None)
def on_connection_close(self, endpoint, error):
- if error: print "Closed due to %s" % error
+ if error: print("Closed due to %s" % error)
self.conn.close()
def run(self):
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/queue_browser.py
----------------------------------------------------------------------
diff --git a/examples/python/queue_browser.py b/examples/python/queue_browser.py
index ad4d393..34d2377 100755
--- a/examples/python/queue_browser.py
+++ b/examples/python/queue_browser.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton.reactor import Container, Copy
from proton.handlers import MessagingHandler
@@ -30,7 +31,7 @@ class Recv(MessagingHandler):
event.container.create_receiver(conn, "examples", options=Copy())
def on_message(self, event):
- print event.message
+ print(event.message)
if event.receiver.queued == 0 and event.receiver.drained:
event.connection.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/cat.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/cat.py b/examples/python/reactor/cat.py
index 57f4515..82ebd27 100755
--- a/examples/python/reactor/cat.py
+++ b/examples/python/reactor/cat.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import sys, os
from proton.reactor import Reactor
@@ -42,7 +43,7 @@ class Echo:
# to be read, or the end of stream has been reached.
data = os.read(sel.fileno(), 1024)
if data:
- print data,
+ print(data, end=' ')
else:
sel.terminate()
event.reactor.update(sel)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/count-randomly.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/count-randomly.py b/examples/python/reactor/count-randomly.py
index d9a32c6..fb3709a 100755
--- a/examples/python/reactor/count-randomly.py
+++ b/examples/python/reactor/count-randomly.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time, random
from proton.reactor import Reactor
@@ -34,7 +35,7 @@ class Counter:
def on_timer_task(self, event):
self.count += 1
- print self.count
+ print(self.count)
if not self.done():
event.reactor.schedule(0.25, self)
@@ -46,7 +47,7 @@ class Program:
def on_reactor_init(self, event):
self.start = time.time()
- print "Hello, World!"
+ print("Hello, World!")
# Save the counter instance in an attribute so we can refer to
# it later.
@@ -60,12 +61,12 @@ class Program:
def on_timer_task(self, event):
# keep on shouting until we are done counting
- print "Yay, %s!" % random.randint(10, 100)
+ print("Yay, %s!" % random.randint(10, 100))
if not self.counter.done():
event.reactor.schedule(0.5, self)
def on_reactor_final(self, event):
- print "Goodbye, World! (after %s long seconds)" % (time.time() - self.start)
+ print("Goodbye, World! (after %s long seconds)" % (time.time() - self.start))
# In hello-world.py we said the reactor exits when there are no more
# events to process. While this is true, it's not actually complete.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/counter.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/counter.py b/examples/python/reactor/counter.py
index 1ef45f0..7c8167a 100755
--- a/examples/python/reactor/counter.py
+++ b/examples/python/reactor/counter.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Reactor
@@ -29,7 +30,7 @@ class Counter:
def on_timer_task(self, event):
self.count += 1
- print self.count
+ print(self.count)
if self.count < self.limit:
# A recurring task can be acomplished by just scheduling
# another event.
@@ -39,7 +40,7 @@ class Program:
def on_reactor_init(self, event):
self.start = time.time()
- print "Hello, World!"
+ print("Hello, World!")
# Note that unlike the previous scheduling example, we pass in
# a separate object for the handler. This means that the timer
@@ -48,7 +49,7 @@ class Program:
event.reactor.schedule(0.25, Counter(10))
def on_reactor_final(self, event):
- print "Goodbye, World! (after %s long seconds)" % (time.time() - self.start)
+ print("Goodbye, World! (after %s long seconds)" % (time.time() - self.start))
# In hello-world.py we said the reactor exits when there are no more
# events to process. While this is true, it's not actually complete.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/delegates.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/delegates.py b/examples/python/reactor/delegates.py
index 813ceba..1a8e1e9 100755
--- a/examples/python/reactor/delegates.py
+++ b/examples/python/reactor/delegates.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Reactor
@@ -28,12 +29,12 @@ from proton.reactor import Reactor
class Hello:
def on_reactor_init(self, event):
- print "Hello, World!"
+ print("Hello, World!")
class Goodbye:
def on_reactor_final(self, event):
- print "Goodbye, World!"
+ print("Goodbye, World!")
class Program:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/echo.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/echo.py b/examples/python/reactor/echo.py
index 4675f5d..17529d9 100755
--- a/examples/python/reactor/echo.py
+++ b/examples/python/reactor/echo.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import sys, os
from proton.reactor import Reactor
@@ -42,7 +43,7 @@ class Echo:
# to be read, or the end of stream has been reached.
data = os.read(sel.fileno(), 1024)
if data:
- print data,
+ print(data, end=' ')
else:
sel.terminate()
event.reactor.update(sel)
@@ -54,7 +55,7 @@ class Program:
# selectable stays alive until it reads the end of stream
# marker. This will keep the whole reactor running until we
# type Control-D.
- print "Type whatever you want and then use Control-D to exit:"
+ print("Type whatever you want and then use Control-D to exit:")
event.reactor.selectable(Echo(sys.stdin))
r = Reactor(Program())
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/global-logger.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/global-logger.py b/examples/python/reactor/global-logger.py
index bc3bc56..3cbe11c 100755
--- a/examples/python/reactor/global-logger.py
+++ b/examples/python/reactor/global-logger.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Reactor
@@ -30,21 +31,21 @@ from proton.reactor import Reactor
class Logger:
def on_unhandled(self, name, event):
- print "LOG:", name, event
+ print("LOG:", name, event)
class Task:
def on_timer_task(self, event):
- print "Mission accomplished!"
+ print("Mission accomplished!")
class Program:
def on_reactor_init(self, event):
- print "Hello, World!"
+ print("Hello, World!")
event.reactor.schedule(0, Task())
def on_reactor_final(self, event):
- print "Goodbye, World!"
+ print("Goodbye, World!")
r = Reactor(Program())
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/goodbye-world.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/goodbye-world.py b/examples/python/reactor/goodbye-world.py
index 44bcf7c..f251c8a 100755
--- a/examples/python/reactor/goodbye-world.py
+++ b/examples/python/reactor/goodbye-world.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton.reactor import Reactor
# So far the reactive hello-world doesn't look too different from a
@@ -30,7 +31,7 @@ class Program:
# As before we handle the reactor init event.
def on_reactor_init(self, event):
- print "Hello, World!"
+ print("Hello, World!")
# In addition to an initial event, the reactor also produces an
# event when it is about to exit. This may not behave much
@@ -40,7 +41,7 @@ class Program:
# regardless of what other paths the main logic of our program
# might take.
def on_reactor_final(self, event):
- print "Goodbye, World!"
+ print("Goodbye, World!")
r = Reactor(Program())
r.run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/handlers.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/handlers.py b/examples/python/reactor/handlers.py
index ed3a94d..ee8d807 100755
--- a/examples/python/reactor/handlers.py
+++ b/examples/python/reactor/handlers.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Reactor
@@ -25,12 +26,12 @@ from proton.reactor import Reactor
class World:
def on_reactor_init(self, event):
- print "World!"
+ print("World!")
class Goodbye:
def on_reactor_final(self, event):
- print "Goodbye, World!"
+ print("Goodbye, World!")
class Hello:
@@ -42,7 +43,7 @@ class Hello:
# The parent handler always receives the event first.
def on_reactor_init(self, event):
- print "Hello",
+ print("Hello", end=' ')
r = Reactor(Hello())
r.run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/hello-world.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/hello-world.py b/examples/python/reactor/hello-world.py
index c685c73..f1708db 100755
--- a/examples/python/reactor/hello-world.py
+++ b/examples/python/reactor/hello-world.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton.reactor import Reactor
# The proton reactor provides a general purpose event processing
@@ -31,7 +32,7 @@ class Program:
# The reactor init event is produced by the reactor itself when it
# starts.
def on_reactor_init(self, event):
- print "Hello, World!"
+ print("Hello, World!")
# When you construct a reactor, you give it a handler.
r = Reactor(Program())
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/reactor-logger.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/reactor-logger.py b/examples/python/reactor/reactor-logger.py
index c07e9b9..2d3f9de 100755
--- a/examples/python/reactor/reactor-logger.py
+++ b/examples/python/reactor/reactor-logger.py
@@ -18,21 +18,22 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Reactor
class Logger:
def on_unhandled(self, name, event):
- print "LOG:", name, event
+ print("LOG:", name, event)
class Program:
def on_reactor_init(self, event):
- print "Hello, World!"
+ print("Hello, World!")
def on_reactor_final(self, event):
- print "Goodbye, World!"
+ print("Goodbye, World!")
# You can pass multiple handlers to a reactor when you construct it.
# Each of these handlers will see every event the reactor sees. By
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/recv.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/recv.py b/examples/python/reactor/recv.py
index aa56472..c6f07f1 100755
--- a/examples/python/reactor/recv.py
+++ b/examples/python/reactor/recv.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.reactor import Reactor
from proton.handlers import CHandshaker, CFlowController
@@ -41,7 +42,7 @@ class Program:
# compliment the similar thing on send
rcv = event.receiver
if rcv and self.message.recv(rcv):
- print self.message
+ print(self.message)
event.delivery.settle()
r = Reactor(Program())
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/scheduling.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/scheduling.py b/examples/python/reactor/scheduling.py
index f822f68..8956821 100755
--- a/examples/python/reactor/scheduling.py
+++ b/examples/python/reactor/scheduling.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Reactor
@@ -25,7 +26,7 @@ class Program:
def on_reactor_init(self, event):
self.start = time.time()
- print "Hello, World!"
+ print("Hello, World!")
# We can schedule a task event for some point in the future.
# This will cause the reactor to stick around until it has a
@@ -42,10 +43,10 @@ class Program:
def on_timer_task(self, event):
task = event.context # xxx: don't have a task property on event yet
- print task.something_to_say, "my task is complete!"
+ print(task.something_to_say, "my task is complete!")
def on_reactor_final(self, event):
- print "Goodbye, World! (after %s long seconds)" % (time.time() - self.start)
+ print("Goodbye, World! (after %s long seconds)" % (time.time() - self.start))
r = Reactor(Program())
r.run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/tornado-hello-world.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/tornado-hello-world.py b/examples/python/reactor/tornado-hello-world.py
index fa8ca83..d06cd1b 100755
--- a/examples/python/reactor/tornado-hello-world.py
+++ b/examples/python/reactor/tornado-hello-world.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import tornado.ioloop
from tornado_app import TornadoApp
@@ -32,7 +33,7 @@ class Program:
# The reactor init event is produced by the reactor itself when it
# starts.
def on_reactor_init(self, event):
- print "Hello, World!"
+ print("Hello, World!")
# The TornadoApp integrates a Reactor into tornado's ioloop.
TornadoApp(Program())
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/reactor/unhandled.py
----------------------------------------------------------------------
diff --git a/examples/python/reactor/unhandled.py b/examples/python/reactor/unhandled.py
index 3734a71..9ab2212 100755
--- a/examples/python/reactor/unhandled.py
+++ b/examples/python/reactor/unhandled.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Reactor
@@ -28,7 +29,7 @@ class Program:
# if it exists. This can be useful not only for debugging, but for
# logging and for delegating/inheritance.
def on_unhandled(self, name, event):
- print name, event
+ print(name, event)
r = Reactor(Program())
r.run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/recurring_timer.py
----------------------------------------------------------------------
diff --git a/examples/python/recurring_timer.py b/examples/python/recurring_timer.py
index a39791d..b59dbe1 100755
--- a/examples/python/recurring_timer.py
+++ b/examples/python/recurring_timer.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton.reactor import Container, Handler
class Recurring(Handler):
@@ -29,7 +30,7 @@ class Recurring(Handler):
self.container.schedule(self.period, self)
def on_timer_task(self, event):
- print "Tick..."
+ print("Tick...")
self.container.schedule(self.period, self)
try:
@@ -37,6 +38,6 @@ try:
container.run()
except KeyboardInterrupt:
container.stop()
- print
+ print()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/recurring_timer_tornado.py
----------------------------------------------------------------------
diff --git a/examples/python/recurring_timer_tornado.py b/examples/python/recurring_timer_tornado.py
index 1f1c0e7..07ebd26 100755
--- a/examples/python/recurring_timer_tornado.py
+++ b/examples/python/recurring_timer_tornado.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import time
from proton.reactor import Handler
from proton_tornado import TornadoLoop
@@ -31,7 +32,7 @@ class Recurring(Handler):
self.container.schedule(time.time() + self.period, subject=self)
def on_timer(self, event):
- print "Tick..."
+ print("Tick...")
self.container.schedule(time.time() + self.period, subject=self)
try:
@@ -39,6 +40,6 @@ try:
container.run()
except KeyboardInterrupt:
container.stop()
- print
+ print()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/selected_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/selected_recv.py b/examples/python/selected_recv.py
index 351d4ef..2ea704b 100755
--- a/examples/python/selected_recv.py
+++ b/examples/python/selected_recv.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton.reactor import Container, Selector
from proton.handlers import MessagingHandler
@@ -30,7 +31,7 @@ class Recv(MessagingHandler):
event.container.create_receiver(conn, "examples", options=Selector(u"colour = 'green'"))
def on_message(self, event):
- print event.message.body
+ print(event.message.body)
try:
Container(Recv()).run()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/server.py
----------------------------------------------------------------------
diff --git a/examples/python/server.py b/examples/python/server.py
index 62aa162..3b0a085 100755
--- a/examples/python/server.py
+++ b/examples/python/server.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
@@ -30,7 +31,7 @@ class Server(MessagingHandler):
self.senders = {}
def on_start(self, event):
- print "Listening on", self.url
+ print("Listening on", self.url)
self.container = event.container
self.conn = event.container.connect(self.url)
self.receiver = event.container.create_receiver(self.conn, self.address)
@@ -41,7 +42,7 @@ class Server(MessagingHandler):
self.relay = self.container.create_sender(self.conn, None)
def on_message(self, event):
- print "Received", event.message
+ print("Received", event.message)
sender = self.relay or self.senders.get(event.message.reply_to)
if not sender:
sender = self.container.create_sender(self.conn, event.message.reply_to)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/server_direct.py
----------------------------------------------------------------------
diff --git a/examples/python/server_direct.py b/examples/python/server_direct.py
index 18a20f3..a9910f1 100755
--- a/examples/python/server_direct.py
+++ b/examples/python/server_direct.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import generate_uuid, Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
@@ -29,7 +30,7 @@ class Server(MessagingHandler):
self.senders = {}
def on_start(self, event):
- print "Listening on", self.url
+ print("Listening on", self.url)
self.container = event.container
self.acceptor = event.container.listen(self.url)
@@ -47,10 +48,10 @@ class Server(MessagingHandler):
event.link.target.address = event.link.remote_target.address
def on_message(self, event):
- print "Received", event.message
+ print("Received", event.message)
sender = self.senders.get(event.message.reply_to)
if not sender:
- print "No link for reply"
+ print("No link for reply")
return
sender.send(Message(address=event.message.reply_to, body=event.message.body.upper(),
correlation_id=event.message.correlation_id))
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/server_tx.py
----------------------------------------------------------------------
diff --git a/examples/python/server_tx.py b/examples/python/server_tx.py
index 96b83cb..51e734c 100755
--- a/examples/python/server_tx.py
+++ b/examples/python/server_tx.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
from proton import Message
from proton.reactor import Container
from proton.handlers import MessagingHandler, TransactionHandler
@@ -35,10 +36,10 @@ class TxRequest(TransactionHandler):
event.transaction.commit()
def on_transaction_committed(self, event):
- print "Request processed successfully"
+ print("Request processed successfully")
def on_transaction_aborted(self, event):
- print "Request processing aborted"
+ print("Request processing aborted")
class TxServer(MessagingHandler):
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/simple_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/simple_recv.py b/examples/python/simple_recv.py
index abe30cd..5322500 100755
--- a/examples/python/simple_recv.py
+++ b/examples/python/simple_recv.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton.handlers import MessagingHandler
from proton.reactor import Container
@@ -37,7 +38,7 @@ class Recv(MessagingHandler):
# ignore duplicate message
return
if self.expected == 0 or self.received < self.expected:
- print event.message.body
+ print(event.message.body)
self.received += 1
if self.received == self.expected:
event.receiver.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/simple_send.py
----------------------------------------------------------------------
diff --git a/examples/python/simple_send.py b/examples/python/simple_send.py
index 4158272..75ab550 100755
--- a/examples/python/simple_send.py
+++ b/examples/python/simple_send.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton import Message
from proton.handlers import MessagingHandler
@@ -43,7 +44,7 @@ class Send(MessagingHandler):
def on_accepted(self, event):
self.confirmed += 1
if self.confirmed == self.total:
- print "all messages confirmed"
+ print("all messages confirmed")
event.connection.close()
def on_disconnected(self, event):
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/sync_client.py
----------------------------------------------------------------------
diff --git a/examples/python/sync_client.py b/examples/python/sync_client.py
index 82cd85f..95a5650 100755
--- a/examples/python/sync_client.py
+++ b/examples/python/sync_client.py
@@ -23,6 +23,7 @@ Demonstrates the client side of the synchronous request-response pattern
(also known as RPC or Remote Procecure Call) using proton.
"""
+from __future__ import print_function
import optparse
from proton import Message, Url, ConnectionException, Timeout
@@ -48,7 +49,7 @@ try:
"And the mome raths outgrabe."]
for request in REQUESTS:
response = client.call(Message(body=request))
- print "%s => %s" % (request, response.body)
+ print("%s => %s" % (request, response.body))
finally:
client.connection.close()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/tx_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/tx_recv.py b/examples/python/tx_recv.py
index 641f0a2..4baddcf 100755
--- a/examples/python/tx_recv.py
+++ b/examples/python/tx_recv.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton import Url
from proton.reactor import Container
@@ -40,7 +41,7 @@ class TxRecv(MessagingHandler, TransactionHandler):
self.transaction = None
def on_message(self, event):
- print event.message.body
+ print(event.message.body)
self.transaction.accept(event.delivery)
self.current_batch += 1
if self.current_batch == self.batch_size:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/tx_recv_interactive.py
----------------------------------------------------------------------
diff --git a/examples/python/tx_recv_interactive.py b/examples/python/tx_recv_interactive.py
index d08ff2b..2c1d9a7 100755
--- a/examples/python/tx_recv_interactive.py
+++ b/examples/python/tx_recv_interactive.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import sys
import threading
from proton.reactor import ApplicationEvent, Container
@@ -35,19 +36,19 @@ class TxRecv(MessagingHandler, TransactionHandler):
self.transaction = None
def on_message(self, event):
- print event.message.body
+ print(event.message.body)
self.transaction.accept(event.delivery)
def on_transaction_declared(self, event):
self.transaction = event.transaction
- print "transaction declared"
+ print("transaction declared")
def on_transaction_committed(self, event):
- print "transaction committed"
+ print("transaction committed")
self.container.declare_transaction(self.conn, handler=self)
def on_transaction_aborted(self, event):
- print "transaction aborted"
+ print("transaction aborted")
self.container.declare_transaction(self.conn, handler=self)
def on_commit(self, event):
@@ -71,7 +72,7 @@ try:
thread.daemon=True
thread.start()
- print "Enter 'fetch', 'commit' or 'abort'"
+ print("Enter 'fetch', 'commit' or 'abort'")
while True:
line = sys.stdin.readline()
if line:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aae1d20a/examples/python/tx_send.py
----------------------------------------------------------------------
diff --git a/examples/python/tx_send.py b/examples/python/tx_send.py
index 0f1da5a..5e30174 100755
--- a/examples/python/tx_send.py
+++ b/examples/python/tx_send.py
@@ -18,6 +18,7 @@
# under the License.
#
+from __future__ import print_function
import optparse
from proton import Message, Url
from proton.reactor import Container
@@ -64,7 +65,7 @@ class TxSend(MessagingHandler, TransactionHandler):
def on_transaction_committed(self, event):
self.committed += self.current_batch
if self.committed == self.total:
- print "all messages committed"
+ print("all messages committed")
event.connection.close()
else:
self.current_batch = 0
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org