PROTON-997: Add support for subclassing of native handlers
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/54d380e0
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/54d380e0
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/54d380e0
Branch: refs/heads/master
Commit: 54d380e01bf4a0d1031dbd38c2e73db5656554ba
Parents: 1248200
Author: Bozo Dragojevic <bozzo@digiverse.si>
Authored: Tue Jul 21 18:56:39 2015 +0200
Committer: Bozo Dragojevic <bozzo@digiverse.si>
Committed: Wed Sep 16 15:40:05 2015 +0200
----------------------------------------------------------------------
proton-c/bindings/python/proton/__init__.py | 37 +++++++++++++++++++++++-
tests/python/proton_tests/reactor.py | 6 +++-
2 files changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/54d380e0/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 c68ab71..a97e9af 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -3862,7 +3862,38 @@ class _cadapter:
else:
self.on_error((exc, val, tb))
+class WrappedHandlersChildSurrogate:
+ def __init__(self, delegate):
+ self.handlers = []
+ self.delegate = weakref.ref(delegate)
+
+ def on_unhandled(self, method, event):
+ delegate = self.delegate()
+ if delegate:
+ dispatch(delegate, method, event)
+
+
+class WrappedHandlersProperty(object):
+ def __get__(self, obj, clazz):
+ if obj is None:
+ return None
+ return self.surrogate(obj).handlers
+
+ def __set__(self, obj, value):
+ self.surrogate(obj).handlers = value
+
+ def surrogate(self, obj):
+ key = "_surrogate"
+ objdict = obj.__dict__
+ surrogate = objdict.get(key, None)
+ if surrogate is None:
+ objdict[key] = surrogate = WrappedHandlersChildSurrogate(obj)
+ obj.add(surrogate)
+ return surrogate
+
class WrappedHandler(Wrapper):
+
+ handlers = WrappedHandlersProperty()
@staticmethod
def wrap(impl, on_error=None):
@@ -3872,9 +3903,13 @@ class WrappedHandler(Wrapper):
handler = WrappedHandler(impl)
handler.__dict__["on_error"] = on_error
return handler
-
+
def __init__(self, impl_or_constructor):
Wrapper.__init__(self, impl_or_constructor)
+ if list(self.__class__.__mro__).index(WrappedHandler) > 1:
+ # instantiate the surrogate
+ self.handlers.extend([])
+
def _on_error(self, info):
on_error = getattr(self, "on_error", None)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/54d380e0/tests/python/proton_tests/reactor.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/reactor.py b/tests/python/proton_tests/reactor.py
index e2e8850..b796ed2 100644
--- a/tests/python/proton_tests/reactor.py
+++ b/tests/python/proton_tests/reactor.py
@@ -18,7 +18,7 @@ from __future__ import absolute_import
# under the License.
#
-from .common import Test
+from .common import Test, SkipTest
from proton.reactor import Reactor
from proton.handlers import CHandshaker
@@ -257,6 +257,10 @@ class ExceptionTest(Test):
class HandlerDerivationTest(Test):
def setUp(self):
+ import platform
+ if platform.python_implementation() != "Jython":
+ # Exception propagation does not work currently for CPython
+ raise SkipTest()
self.reactor = Reactor()
def test_reactor_final_derived(self):
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
|