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/04/17 17:39:54 UTC
[qpid-proton] branch main updated: PROTON-2712: Fix some issues in the python binding type mapping
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
The following commit(s) were added to refs/heads/main by this push:
new 23c45e12f PROTON-2712: Fix some issues in the python binding type mapping
23c45e12f is described below
commit 23c45e12f5547297a6391c8a82318f50c50beb0c
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Fri Apr 14 18:29:07 2023 -0400
PROTON-2712: Fix some issues in the python binding type mapping
---
python/cproton.py | 18 ++++++++++--------
python/proton/_data.py | 14 +++-----------
2 files changed, 13 insertions(+), 19 deletions(-)
diff --git a/python/cproton.py b/python/cproton.py
index 5d5a0b54e..24281699d 100644
--- a/python/cproton.py
+++ b/python/cproton.py
@@ -193,19 +193,21 @@ def bytes2py(b):
return memoryview(ffi.buffer(b.start, b.size))
+def bytes2pybytes(b):
+ return bytes(ffi.buffer(b.start, b.size))
+
+
def bytes2string(b, encoding='utf8'):
return ffi.unpack(b.start, b.size).decode(encoding)
def py2bytes(py):
- if isinstance(py, memoryview):
- return len(py), py
+ if isinstance(py, (bytes, bytearray,memoryview)):
+ s = ffi.from_buffer(py)
+ return len(s), s
elif isinstance(py, str):
s = ffi.from_buffer(py.encode('utf8'))
return len(s), s
- elif isinstance(py, bytes):
- s = ffi.from_buffer(py)
- return len(s), s
def string2bytes(py, encoding='utf8'):
@@ -240,7 +242,7 @@ def msgid2py(msgid):
elif t == PN_ULONG:
return msgid.u.as_ulong
elif t == PN_BINARY:
- return ffi.buffer(msgid.u.as_bytes.start, msgid.u.as_bytes.size)
+ return bytes2py(msgid.u.as_bytes)
elif t == PN_STRING:
return bytes2string(msgid.u.as_bytes)
elif t == PN_UUID:
@@ -265,7 +267,7 @@ def py2msgid(py):
elif isinstance(py, int):
return {'type': PN_ULONG, 'u': {'as_ulong': py}}
elif isinstance(py, str):
- return {'type': PN_STRING, 'u': {'as_bytes': py2bytes(py)}}
+ return {'type': PN_STRING, 'u': {'as_bytes': string2bytes(py)}}
elif isinstance(py, bytes):
return {'type': PN_BINARY, 'u': {'as_bytes': py2bytes(py)}}
elif isinstance(py, UUID):
@@ -568,7 +570,7 @@ def pn_message_set_id(message, value):
def pn_message_get_user_id(message):
- return bytes2py(lib.pn_message_get_user_id(message))
+ return bytes2pybytes(lib.pn_message_get_user_id(message))
def pn_message_set_user_id(message, value):
diff --git a/python/proton/_data.py b/python/proton/_data.py
index b6af0b3af..bf627b6d9 100644
--- a/python/proton/_data.py
+++ b/python/proton/_data.py
@@ -1094,16 +1094,7 @@ class Data:
:param mv: A Python memoryview object
:raise: :exc:`DataException` if there is a Proton error.
"""
- self.put_binary(mv.tobytes())
-
- def put_buffer(self, buff: Iterable[int]) -> None:
- """
- Put a Python buffer object as an AMQP binary value.
-
- :param buff: A Python buffer object (**CHECK THIS**)
- :raise: :exc:`DataException` if there is a Proton error.
- """
- self.put_binary(bytes(buff))
+ self.put_binary(mv)
def put_string(self, s: str) -> None:
"""
@@ -1589,6 +1580,7 @@ class Data:
timestamp: put_timestamp,
uuid.UUID: put_uuid,
bytes: put_binary,
+ bytearray: put_binary,
unicode: put_string,
symbol: put_symbol,
list: put_sequence,
@@ -1599,7 +1591,7 @@ class Data:
AnnotationDict: put_dict,
PropertyDict: put_dict,
SymbolList: put_sequence,
- memoryview: put_memoryview
+ memoryview: put_binary
}
get_mappings = {
NULL: lambda s: None,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org