From 4bf412905aac6cd102194f6c7625721a95353b02 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 9 Jun 2022 18:29:29 -0300 Subject: [PATCH 1/2] Rename is_reply -> is_request The property is retrieving whether a reply is expected, not whether the message itself is a reply. --- src/oxenmq.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/oxenmq.cpp b/src/oxenmq.cpp index 5022515..aa413d2 100644 --- a/src/oxenmq.cpp +++ b/src/oxenmq.cpp @@ -151,7 +151,7 @@ This typically protects administrative commands like shutting down or access to py::class_ msg(mod, "Message", "Temporary object containing details of a just-received message"); msg - .def_property_readonly("is_reply", [](const Message& m) { return !m.reply_tag.empty(); }, + .def_property_readonly("is_request", [](const Message& m) { return !m.reply_tag.empty(); }, "True if this message is expecting a reply (i.e. it was received on a request_command endpoint)") .def_readonly("remote", &Message::remote, py::return_value_policy::copy, R"(Some sort of remote address from which the request came. @@ -187,7 +187,7 @@ or .to_bytes() on each one)" R"(Sends a reply back to this caller. `args` must be bytes, str, or iterables thereof (and will be flatted). Should only be used from a -request_command endpoint (i.e. when .is_reply is true)") +request_command endpoint (i.e. when .is_request is true)") .def("back", [](Message& m, std::string command, py::args args) { m.send_back(command, send_option::data_parts(extract_data_parts(args))); }, @@ -223,7 +223,7 @@ instance is still alive).)") ; py::class_(msg, "DeferredSend") - .def_property_readonly("is_reply", [](const Message::DeferredSend& m) { return !m.reply_tag.empty(); }, + .def_property_readonly("is_request", [](const Message::DeferredSend& m) { return !m.reply_tag.empty(); }, "True if this message is expecting a reply (i.e. it was received on a request_command endpoint)") .def("reply", [](Message::DeferredSend& d, py::args args) { d.reply(send_option::data_parts(extract_data_parts(args))); From f62fa4916f4a013308796a13112b2089bad266f3 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 4 Aug 2022 10:35:27 -0300 Subject: [PATCH 2/2] Remove base32z encoding We have pyoxenc for that instead. --- setup.py | 4 ++-- src/bencode.cpp | 15 --------------- src/common.hpp | 13 ------------- src/module.cpp | 6 ------ src/oxenmq.cpp | 6 +++--- 5 files changed, 5 insertions(+), 39 deletions(-) delete mode 100644 src/bencode.cpp delete mode 100644 src/common.hpp delete mode 100644 src/module.cpp diff --git a/setup.py b/setup.py index dea0e87..bd43c01 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup # Available at setup time due to pyproject.toml from pybind11.setup_helpers import Pybind11Extension, build_ext -__version__ = "1.0.2" +__version__ = "1.0.3" # Note: # Sort input source files if you glob sources to ensure bit-for-bit @@ -11,7 +11,7 @@ __version__ = "1.0.2" ext_modules = [Pybind11Extension( "oxenmq", - ["src/bencode.cpp", "src/module.cpp", "src/oxenmq.cpp"], + ["src/oxenmq.cpp"], cxx_std=17, libraries=["oxenmq"], ), diff --git a/src/bencode.cpp b/src/bencode.cpp deleted file mode 100644 index 82419f3..0000000 --- a/src/bencode.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "common.hpp" -#include "oxenmq/base32z.h" - -namespace oxenmq { - -void BEncode_Init(py::module& mod) { - mod.def("base32z_encode", [](py::bytes data) { - char* ptr = nullptr; - py::ssize_t sz = 0; - PyBytes_AsStringAndSize(data.ptr(), &ptr, &sz); - return oxenmq::to_base32z(ptr, ptr+sz); - }); -} - -} diff --git a/src/common.hpp b/src/common.hpp deleted file mode 100644 index 4bb8dce..0000000 --- a/src/common.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include -#include -#include - -namespace py = pybind11; - -namespace oxenmq { - -void OxenMQ_Init(py::module &mod); -void BEncode_Init(py::module & mod); - -} diff --git a/src/module.cpp b/src/module.cpp deleted file mode 100644 index a9da6ba..0000000 --- a/src/module.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "common.hpp" - -PYBIND11_MODULE(oxenmq, m) { - oxenmq::OxenMQ_Init(m); - oxenmq::BEncode_Init(m); -} diff --git a/src/oxenmq.cpp b/src/oxenmq.cpp index aa413d2..81cdb83 100644 --- a/src/oxenmq.cpp +++ b/src/oxenmq.cpp @@ -1,4 +1,3 @@ -#include "common.hpp" #include #include #include @@ -14,6 +13,8 @@ #include #include +namespace py = pybind11; + namespace oxenmq { // Convert a py::object containing a str, bytes, or iterable over str/bytes to a vector of message @@ -51,8 +52,7 @@ struct stderr_logger { } }; -void -OxenMQ_Init(py::module& mod) +PYBIND11_MODULE(oxenmq, mod) { using namespace pybind11::literals; constexpr py::kw_only kwonly{};