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:24 UTC
[qpid-proton] 02/02: PROTON-2690: Make offered & desired capabilities arrays on the wire
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