You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2023/03/07 23:24:22 UTC

[qpid-proton] branch main updated (3b0cfbc5a -> 789958cb3)

This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


    from 3b0cfbc5a PROTON-2676: Oops - fix PEP8 linter failures
     new b8b6e0567 PROTON-2095: Add debug API to print proton object
     new 789958cb3 PROTON-2690: Make offered & desired capabilities arrays on the wire

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 python/cproton.h            |  3 +++
 python/cproton.py           |  7 +++++++
 python/examples/server.py   |  4 ++--
 python/proton/_data.py      | 15 ++++++++++++++-
 python/proton/_endpoints.py | 20 ++++++++------------
 5 files changed, 34 insertions(+), 15 deletions(-)


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


[qpid-proton] 02/02: PROTON-2690: Make offered & desired capabilities arrays on the wire

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 789958cb3c9bf23079a9f88d3e31f5a6b3ccd8b1
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Tue Mar 7 17:55:17 2023 +0000

    PROTON-2690: Make offered & desired capabilities arrays on the wire
---
 python/examples/server.py   |  4 ++--
 python/proton/_data.py      | 15 ++++++++++++++-
 python/proton/_endpoints.py | 20 ++++++++------------
 3 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/python/examples/server.py b/python/examples/server.py
index 2e95f795c..4aca80dfc 100755
--- a/python/examples/server.py
+++ b/python/examples/server.py
@@ -20,7 +20,7 @@
 
 import optparse
 import sys
-from proton import Message, Url, Condition
+from proton import Condition, Message, Url
 from proton.handlers import MessagingHandler
 from proton.reactor import Container
 
@@ -36,7 +36,7 @@ class Server(MessagingHandler):
     def on_start(self, event):
         print("Listening on", self.url)
         self.container = event.container
-        self.conn = event.container.connect(self.url, desired_capabilities=["ANONYMOUS-RELAY"])
+        self.conn = event.container.connect(self.url, desired_capabilities="ANONYMOUS-RELAY")
 
     def on_connection_opened(self, event):
         if event.connection.remote_offered_capabilities and 'ANONYMOUS-RELAY' in event.connection.remote_offered_capabilities:
diff --git a/python/proton/_data.py b/python/proton/_data.py
index 8e8355f7e..b6af0b3af 100644
--- a/python/proton/_data.py
+++ b/python/proton/_data.py
@@ -510,7 +510,9 @@ class SymbolList(list):
     ) -> None:
         super(SymbolList, self).__init__()
         self.raise_on_error = raise_on_error
-        if t:
+        if isinstance(t, (str, symbol)):
+            self.append(t)
+        else:
             self.extend(t)
 
     def _check_list(self, t: Iterable[Any]) -> List[Any]:
@@ -521,6 +523,9 @@ class SymbolList(list):
                 l.append(_check_is_symbol(v, self.raise_on_error))
         return l
 
+    def to_array(self):
+        return Array(UNDESCRIBED, PN_SYMBOL, *self)
+
     def append(self, v: str) -> None:
         """ Add a single value v to the end of the list """
         return super(SymbolList, self).append(_check_is_symbol(v, self.raise_on_error))
@@ -541,6 +546,10 @@ class SymbolList(list):
         """ Handles list1 += list2 """
         return super(SymbolList, self).__iadd__(self._check_list(t))
 
+    def __eq__(self, other):
+        """ Handles list1 == list2 """
+        return super().__eq__(SymbolList(other, raise_on_error=False))
+
     def __setitem__(self, i: int, t: Any) -> None:
         """ Handles list[i] = v """
         return super(SymbolList, self).__setitem__(i, _check_is_symbol(t, self.raise_on_error))
@@ -1646,6 +1655,10 @@ def dat2obj(dimpl):
 
 
 def obj2dat(obj, dimpl):
+    if isinstance(obj, SymbolList):
+        if len(obj) == 0:
+            return
+        obj = obj.to_array()
     if obj is not None:
         d = Data(dimpl)
         d.put_object(obj)
diff --git a/python/proton/_endpoints.py b/python/proton/_endpoints.py
index 4f6ac20ca..ee4defe42 100644
--- a/python/proton/_endpoints.py
+++ b/python/proton/_endpoints.py
@@ -174,8 +174,8 @@ class Connection(Wrapper, Endpoint):
 
     def _init(self) -> None:
         Endpoint._init(self)
-        self.offered_capabilities = None
-        self.desired_capabilities = None
+        self.offered_capabilities_list = None
+        self.desired_capabilities_list = None
         self.properties = None
         self.url = None
         self._acceptor = None
@@ -333,7 +333,8 @@ class Connection(Wrapper, Endpoint):
 
         :type: :class:`Data`
         """
-        return dat2obj(pn_connection_remote_offered_capabilities(self._impl))
+        c = dat2obj(pn_connection_remote_offered_capabilities(self._impl))
+        return c and SymbolList(c)
 
     @property
     def remote_desired_capabilities(self):
@@ -347,7 +348,8 @@ class Connection(Wrapper, Endpoint):
 
         :type: :class:`Data`
         """
-        return dat2obj(pn_connection_remote_desired_capabilities(self._impl))
+        c = dat2obj(pn_connection_remote_desired_capabilities(self._impl))
+        return c and SymbolList(c)
 
     @property
     def remote_properties(self):
@@ -508,10 +510,7 @@ class Connection(Wrapper, Endpoint):
             self,
             offered_capability_list: Optional[Union['Array', List['symbol'], SymbolList, List[str]]]
     ) -> None:
-        if isinstance(offered_capability_list, list):
-            self.offered_capabilities_list = SymbolList(offered_capability_list, raise_on_error=False)
-        else:
-            self.offered_capabilities_list = offered_capability_list
+        self.offered_capabilities_list = SymbolList(offered_capability_list)
 
     @property
     def desired_capabilities(self) -> Optional[Union['Array', SymbolList]]:
@@ -528,10 +527,7 @@ class Connection(Wrapper, Endpoint):
             self,
             desired_capability_list: Optional[Union['Array', List['symbol'], SymbolList, List[str]]]
     ) -> None:
-        if isinstance(desired_capability_list, list):
-            self.desired_capabilities_list = SymbolList(desired_capability_list, raise_on_error=False)
-        else:
-            self.desired_capabilities_list = desired_capability_list
+        self.desired_capabilities_list = SymbolList(desired_capability_list)
 
     @property
     def properties(self) -> Optional[PropertyDict]:


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


[qpid-proton] 01/02: PROTON-2095: Add debug API to print proton object

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit b8b6e05678d8280a4d09b786b6e99196ddb148af
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Tue Mar 7 18:07:45 2023 +0000

    PROTON-2095: Add debug API to print proton object
---
 python/cproton.h  | 3 +++
 python/cproton.py | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/python/cproton.h b/python/cproton.h
index 3f6b7ad39..29dc30ba4 100644
--- a/python/cproton.h
+++ b/python/cproton.h
@@ -372,6 +372,7 @@ pn_type_t pn_data_type(pn_data_t *data);
 void pn_data_widen(pn_data_t *data);
 
 int pn_decref(void *object);
+char *pn_tostring(void *object);
 
 pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag);
 void pn_delivery_abort(pn_delivery_t *delivery);
@@ -680,3 +681,5 @@ void pn_record_def_py(pn_record_t *record);
 void *pn_record_get_py(pn_record_t *record);
 void pn_record_set_py(pn_record_t *record, void *value);
 int pn_ssl_get_peer_hostname_py(pn_ssl_t *ssl, char *hostname, size_t size);
+
+void free(void*);
diff --git a/python/cproton.py b/python/cproton.py
index 4d5e1558a..5d5a0b54e 100644
--- a/python/cproton.py
+++ b/python/cproton.py
@@ -318,6 +318,13 @@ def pn_pyref_decref(obj):
     retained_objects.discard(obj)
 
 
+def pn_tostring(obj):
+    cs = lib.pn_tostring(obj)
+    s = ffi.string(cs).decode('utf8')
+    lib.free(cs)
+    return s
+
+
 def pn_collector_put_pyref(collector, obj, etype):
     d = ffi.new_handle(obj)
     retained_objects.add(d)


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