Release 1.0.0: 23/1223/3 python-1.0.0
authorTommy Carpenter <tc677g@att.com>
Thu, 24 Oct 2019 18:14:04 +0000 (14:14 -0400)
committerTommy Carpenter <tc677g@att.com>
Thu, 24 Oct 2019 18:28:41 +0000 (14:28 -0400)
* It's been past due to bump this to 1.0.0 since people depend on it!
* Add the ability to set sbuf attributes in the same call that it is allocated
* (breaking) removes bytes2meid
* (breaking) rmr_set_meid now infers length
* (breaking) rmr_get_meid now returns bytes, to be symmetric with set_meid

Change-Id: I8519293af6dd30be56c0a7956f31da105c78085d
Signed-off-by: Tommy Carpenter <tc677g@att.com>
src/bindings/rmr-python/docs/Changelog.rst
src/bindings/rmr-python/rmr/rmr.py
src/bindings/rmr-python/setup.py
src/bindings/rmr-python/tests/test_rmr.py

index 25595c9..3b29e66 100644 (file)
@@ -7,6 +7,19 @@ The format is based on `Keep a Changelog <http://keepachangelog.com/>`__
 and this project adheres to `Semantic
 Versioning <http://semver.org/>`__.
 
+
+[1.0.0] - 10/24/2019
+--------------------
+
+::
+
+    * It's been past due to bump this to 1.0.0 since people depend on it!
+    * Add the ability to set sbuf attributes in the same call that it is allocated
+    * (breaking) removes bytes2meid
+    * (breaking) rmr_set_meid now infers length
+    * (breaking) rmr_get_meid now returns bytes, to be symmetric with set_meid
+
+
 [0.13.5] - 10/23/2019
 --------------------
 
index 85c9ee8..0265e21 100644 (file)
@@ -215,17 +215,37 @@ _rmr_alloc_msg.argtypes = [c_void_p, c_int]
 _rmr_alloc_msg.restype = POINTER(rmr_mbuf_t)
 
 
-def rmr_alloc_msg(vctx, size):
+def rmr_alloc_msg(vctx, size, payload=None, gen_transaction_id=False, mtype=None, meid=None):
     """
     Refer to the rmr C documentation for rmr_alloc_msg
     extern rmr_mbuf_t* rmr_alloc_msg(void* vctx, int size)
+
+    if payload is not None, attempts to set the payload
+    if gen_transaction_id is True, it generates and sets a transaction id
+    if mtype is not None, sets the sbuf's message type
+    if meid is not None, sets the sbuf's meid
+
     """
     sbuf = _rmr_alloc_msg(vctx, size)
+    # make sure it's good
     try:
         sbuf.contents
+        if payload:
+            set_payload_and_length(payload, sbuf)
+
+        if gen_transaction_id:
+            generate_and_set_transaction_id(sbuf)
+
+        if mtype:
+            sbuf.contents.mtype = mtype
+
+        if meid:
+            rmr_set_meid(sbuf, meid)
+
+        return sbuf
+
     except ValueError:
         raise BadBufferAllocation
-    return sbuf
 
 
 _rmr_free_msg = rmr_c_lib.rmr_free_msg
@@ -330,16 +350,13 @@ _rmr_bytes2meid.argtypes = [POINTER(rmr_mbuf_t), c_char_p, c_int]
 _rmr_bytes2meid.restype = c_int
 
 
-def rmr_bytes2meid(ptr_mbuf, src, length):
+def rmr_set_meid(ptr_mbuf, byte_str):
     """
     Refer to the rmr C documentation for rmr_bytes2meid
     extern int rmr_bytes2meid(rmr_mbuf_t* mbuf, unsigned char const* src, int len);
     """
-    return _rmr_bytes2meid(ptr_mbuf, src, length)
-
+    return _rmr_bytes2meid(ptr_mbuf, byte_str, len(byte_str))
 
-# this is an alias to rmr_bytes2meid using familiar set/get terminoloigy
-rmr_set_meid = rmr_bytes2meid
 
 # CAUTION:  Some of the C functions expect a mutable buffer to copy the bytes into;
 #           if there is a get_* function below, use it to set up and return the
@@ -370,7 +387,7 @@ def rmr_get_meid(ptr_mbuf):
     sz = _get_constants().get("RMR_MAX_MEID", 64)  # size for buffer to fill
     buf = create_string_buffer(sz)
     _rmr_get_meid(ptr_mbuf, buf)
-    return buf.value.decode()  # decode turns into a string
+    return buf.value
 
 
 _rmr_get_src = rmr_c_lib.rmr_get_src
index 845ded1..5651e6b 100644 (file)
@@ -32,7 +32,7 @@ def _long_descr():
 
 setup(
     name="rmr",
-    version="0.13.5",
+    version="1.0.0",
     packages=find_packages(),
     author="Tommy Carpenter, E. Scott Daniels",
     description="Python wrapper for RIC RMR",
index d5023b3..e43b170 100644 (file)
@@ -63,7 +63,7 @@ def _assert_new_sbuf(sbuf):
     assert summary["transaction id"] == b""
     assert summary["message state"] == 0
     assert summary["message status"] == "RMR_OK"
-    assert summary["meid"] == ""
+    assert summary["meid"] == b""
     assert summary["errno"] == 0
 
 
@@ -105,19 +105,19 @@ def test_meid():
     """
     sbuf = rmr.rmr_alloc_msg(MRC_SEND, SIZE)
 
-    rmr.rmr_set_meid(sbuf, b"\x01\x02", 2)
-    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == "\x01\x02"
+    rmr.rmr_set_meid(sbuf, b"\x01\x02")
+    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"\x01\x02"
     assert len(rmr.rmr_get_meid(sbuf)) == 2
 
-    rmr.rmr_set_meid(sbuf, b"\x00" * 32, 32)
-    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == ""  # NULL bytes get truncated
+    rmr.rmr_set_meid(sbuf, b"\x00" * 32)
+    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b""  # NULL bytes get truncated
 
-    rmr.rmr_set_meid(sbuf, b"6" * 32, 32)
-    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == "6" * 32  # string in string out
+    rmr.rmr_set_meid(sbuf, b"6" * 32)
+    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"6" * 32  # string in string out
 
-    rmr.rmr_set_meid(sbuf, b"\x01\x02", 2)
+    rmr.rmr_set_meid(sbuf, b"\x01\x02")
     assert (
-        rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == "\x01\x02" + "6" * 30
+        rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"\x01\x02" + b"6" * 30
     )  # bytes in string out, 6s left over
     assert len(rmr.rmr_get_meid(sbuf)) == 32
 
@@ -145,10 +145,10 @@ def test_rmr_set_get():
     assert len(summary["transaction id"]) == 32
 
     # test meid
-    assert rmr.rmr_get_meid(sbuf) == summary["meid"] == ""
-    rmr.rmr_set_meid(sbuf, b"666\x01\x00\x01", 6)
+    assert rmr.rmr_get_meid(sbuf) == summary["meid"] == b""
+    rmr.rmr_set_meid(sbuf, b"666\x01\x00\x01")
     summary = rmr.message_summary(sbuf)
-    assert rmr.rmr_get_meid(sbuf) == summary["meid"] == "666\x01"
+    assert rmr.rmr_get_meid(sbuf) == summary["meid"] == b"666\x01"
     assert (len(summary["meid"])) == 4
 
 
@@ -274,3 +274,16 @@ def test_bad_buffer():
     """test that we get a proper exception when the buffer has a null pointer"""
     with pytest.raises(exceptions.BadBufferAllocation):
         rmr.rmr_alloc_msg(None, 4096)
+
+
+def test_alloc_fancy():
+    """test allocation with setting payload, trans, mtype"""
+    pay = b"yoo\x01\x00\x80"
+    sbuf = rmr.rmr_alloc_msg(MRC_SEND, SIZE, payload=pay, gen_transaction_id=True, mtype=14, meid=b"asdf")
+    summary = rmr.message_summary(sbuf)
+    assert summary["payload"] == pay
+    assert summary["payload length"] == 6
+    assert summary["transaction id"] != b""  # hard to test what it will be, but make sure not empty
+    assert summary["message state"] == 0
+    assert summary["message type"] == 14
+    assert summary["meid"] == b"asdf"