You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2015/01/23 13:23:56 UTC
qpid-proton git commit: added a pure python IO handler
Repository: qpid-proton
Updated Branches:
refs/heads/master 5f5e93f47 -> c4d2c3cb0
added a pure python IO handler
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c4d2c3cb
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c4d2c3cb
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c4d2c3cb
Branch: refs/heads/master
Commit: c4d2c3cb084da40e35295adcdcfad912d6e029d0
Parents: 5f5e93f
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Fri Jan 23 07:23:29 2015 -0500
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Fri Jan 23 07:23:29 2015 -0500
----------------------------------------------------------------------
proton-c/bindings/python/proton/__init__.py | 4 +-
proton-c/bindings/python/proton/handlers.py | 70 +++++++++++++++++++++++-
2 files changed, 69 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4d2c3cb/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index e5d6a32..317a8b4 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -3323,7 +3323,7 @@ def dispatch(handler, method, *args):
if m:
return m(*args)
elif hasattr(handler, "on_unhandled"):
- return handler.on_unhandled(method, args)
+ return handler.on_unhandled(method, *args)
class EventBase(object):
@@ -3472,7 +3472,7 @@ class Event(Wrapper, EventBase):
class Handler(object):
- def on_unhandled(self, method, args):
+ def on_unhandled(self, method, *args):
pass
class _cadapter:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4d2c3cb/proton-c/bindings/python/proton/handlers.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/handlers.py b/proton-c/bindings/python/proton/handlers.py
index 6659e34..7fe27c1 100644
--- a/proton-c/bindings/python/proton/handlers.py
+++ b/proton-c/bindings/python/proton/handlers.py
@@ -74,8 +74,7 @@ class ScopedHandler(Handler):
"""
scopes = ["delivery", "link", "session", "connection"]
- def on_unhandled(self, method, args):
- event = args[0]
+ def on_unhandled(self, method, event):
if event.type in [Event.CONNECTION_FINAL, Event.SESSION_FINAL, Event.LINK_FINAL]:
return
@@ -442,7 +441,7 @@ class TransactionalClientHandler(MessagingHandler, TransactionHandler):
super(TransactionalClientHandler, self).accept(delivery)
from proton import WrappedHandler
-from cproton import pn_flowcontroller, pn_handshaker
+from cproton import pn_flowcontroller, pn_handshaker, pn_iohandler
class CFlowController(WrappedHandler):
@@ -453,3 +452,68 @@ class CHandshaker(WrappedHandler):
def __init__(self):
WrappedHandler.__init__(self, pn_handshaker)
+
+class IOHandler(WrappedHandler):
+
+ def __init__(self):
+ WrappedHandler.__init__(self, pn_iohandler)
+
+class PythonIO:
+
+ def __init__(self):
+ self.selectables = []
+ self.delegate = IOHandler()
+
+ def on_unhandled(self, method, event):
+ event.dispatch(self.delegate)
+
+ def on_selectable_updated(self, event):
+ pass
+
+ def on_selectable_init(self, event):
+ self.selectables.append(event.context)
+
+ def on_selectable_final(self, event):
+ sel = event.context
+ if sel.is_terminal:
+ self.selectables.remove(sel)
+ sel.release()
+
+ def on_reactor_quiesced(self, event):
+ reactor = event.reactor
+
+ reading = []
+ writing = []
+ deadline = None
+ for sel in self.selectables:
+ if sel.reading:
+ reading.append(sel)
+ if sel.writing:
+ writing.append(sel)
+ if sel.deadline:
+ if deadline is None:
+ deadline = sel.deadline
+ else:
+ deadline = min(sel.deadline, deadline)
+
+ if deadline is not None:
+ timeout = deadline - time.time()
+ else:
+ timeout = reactor.timeout
+ if (timeout < 0): timeout = 0
+ timeout = min(timeout, reactor.timeout)
+ readable, writable, _ = select(reading, writing, [], timeout)
+
+ reactor.mark()
+
+ now = time.time()
+
+ for s in readable:
+ s.readable()
+ for s in writable:
+ s.writable()
+ for s in self.selectables:
+ if s.deadline and now > s.deadline:
+ s.expired()
+
+ reactor.yield_()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org