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/06 20:28:37 UTC

[4/5] qpid-proton git commit: made Wrapper work on objects that don't have attachments

made Wrapper work on objects that don't have attachments


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/e12a2ab2
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/e12a2ab2
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/e12a2ab2

Branch: refs/heads/master
Commit: e12a2ab2944823a992ff75abee68ad309d72030a
Parents: 8b0b25a
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Tue Jan 6 14:21:10 2015 -0500
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Tue Jan 6 14:27:51 2015 -0500

----------------------------------------------------------------------
 proton-c/bindings/python/proton/wrapper.py | 33 +++++++++++++++++++------
 1 file changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e12a2ab2/proton-c/bindings/python/proton/wrapper.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/wrapper.py b/proton-c/bindings/python/proton/wrapper.py
index 7f3f421..2911d3a 100644
--- a/proton-c/bindings/python/proton/wrapper.py
+++ b/proton-c/bindings/python/proton/wrapper.py
@@ -18,9 +18,22 @@
 #
 from cproton import *
 
+class EmptyAttrs:
+
+    def __contains__(self, name):
+        return False
+
+    def __getitem__(self, name):
+        raise KeyError(name)
+
+    def __setitem__(self, name, value):
+        raise TypeError("does not support item assignment")
+
+EMPTY_ATTRS = EmptyAttrs()
+
 class Wrapper(object):
 
-    def __init__(self, impl_or_constructor, get_context):
+    def __init__(self, impl_or_constructor, get_context=None):
         init = False
         if callable(impl_or_constructor):
             # we are constructing a new object
@@ -31,13 +44,17 @@ class Wrapper(object):
             impl = impl_or_constructor
             pn_incref(impl)
 
-        record = get_context(impl)
-        attrs = pn_void2py(pn_record_get(record, PYCTX))
-        if attrs is None:
-            attrs = {}
-            pn_record_def(record, PYCTX, PN_PYREF)
-            pn_record_set(record, PYCTX, pn_py2void(attrs))
-            init = True
+        if get_context:
+            record = get_context(impl)
+            attrs = pn_void2py(pn_record_get(record, PYCTX))
+            if attrs is None:
+                attrs = {}
+                pn_record_def(record, PYCTX, PN_PYREF)
+                pn_record_set(record, PYCTX, pn_py2void(attrs))
+                init = True
+        else:
+            attrs = EMPTY_ATTRS
+            init = False
         self.__dict__["_impl"] = impl
         self.__dict__["_attrs"] = attrs
         if init: self._init()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org