summaryrefslogtreecommitdiff
path: root/qpid/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp')
-rw-r--r--qpid/cpp/bindings/qpid/python/python.i48
-rw-r--r--qpid/cpp/include/qpid/messaging/Message.h1
-rw-r--r--qpid/cpp/include/qpid/swig_python_typemaps.i10
-rw-r--r--qpid/cpp/src/qpid/messaging/Message.cpp1
4 files changed, 47 insertions, 13 deletions
diff --git a/qpid/cpp/bindings/qpid/python/python.i b/qpid/cpp/bindings/qpid/python/python.i
index 9158836a2b..2a3153d2c4 100644
--- a/qpid/cpp/bindings/qpid/python/python.i
+++ b/qpid/cpp/bindings/qpid/python/python.i
@@ -164,10 +164,6 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
%extend qpid::messaging::Connection {
%pythoncode %{
- # Handle the different options by converting underscores to hyphens.
- # Also, the sasl_mechanisms option in Python has no direct
- # equivalent in C++, so we will translate them to sasl_mechanism
- # when possible.
def __init__(self, url=None, **options):
if url:
args = [str(url)]
@@ -312,6 +308,31 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
%extend qpid::messaging::Message {
%pythoncode %{
+ class MessageProperties:
+ def __init__(self, msg):
+ self.msg = msg
+ self.properties = self.msg.getProperties()
+
+ def __len__(self):
+ return self.properties.__len__()
+
+ def __getitem__(self, key):
+ return self.properties[key];
+
+ def __setitem__(self, key, value):
+ self.properties[key] = value
+ self.msg.setProperty(key, value)
+
+ def __delitem__(self, key):
+ del self.properties[key]
+ self.msg.setProperties(self.properties)
+
+ def __iter__(self):
+ return self.properties.iteritems()
+
+ def __repr__(self):
+ return str(self.properties)
+
# UNSPECIFIED was module level before, but I do not
# know how to insert python code at the top of the module.
# (A bare "%pythoncode" inserts at the end.
@@ -344,11 +365,14 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
if ttl is not None :
self.ttl = ttl
if properties is not None :
- # Can't set properties via (inst).getProperties, because
- # the typemaps make a copy of the underlying properties.
- # Instead, set via setProperty for the time-being
- for k, v in properties.iteritems() :
- self.setProperty(k, v)
+ self.setProperties(properties)
+
+ def _get_msg_props(self):
+ try:
+ return self._msg_props
+ except AttributeError:
+ self._msg_props = Message.MessageProperties(self)
+ return self._msg_props
def _get_content(self) :
obj = self.getContentObject()
@@ -418,8 +442,8 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
__swig_setmethods__["durable"] = setDurable
if _newclass: durable = property(getDurable, setDurable)
- __swig_getmethods__["properties"] = getProperties
- if _newclass: properties = property(getProperties)
+ __swig_getmethods__["properties"] = _get_msg_props
+ if _newclass: properties = property(_get_msg_props)
def getReplyTo(self) :
return self._getReplyTo().str()
@@ -428,7 +452,7 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
__swig_getmethods__["reply_to"] = getReplyTo
__swig_setmethods__["reply_to"] = setReplyTo
if _newclass: reply_to = property(getReplyTo, setReplyTo)
-
+
def __repr__(self):
args = []
for name in ["id", "subject", "user_id", "reply_to",
diff --git a/qpid/cpp/include/qpid/messaging/Message.h b/qpid/cpp/include/qpid/messaging/Message.h
index 10569eb006..6315d3e86f 100644
--- a/qpid/cpp/include/qpid/messaging/Message.h
+++ b/qpid/cpp/include/qpid/messaging/Message.h
@@ -149,6 +149,7 @@ class QPID_MESSAGING_CLASS_EXTERN Message
*/
QPID_MESSAGING_EXTERN const qpid::types::Variant::Map& getProperties() const;
QPID_MESSAGING_EXTERN qpid::types::Variant::Map& getProperties();
+ QPID_MESSAGING_EXTERN void setProperties(const qpid::types::Variant::Map&);
/**
* Set the content to the data held in the string parameter. Note:
diff --git a/qpid/cpp/include/qpid/swig_python_typemaps.i b/qpid/cpp/include/qpid/swig_python_typemaps.i
index 25a4e46b18..ef32012693 100644
--- a/qpid/cpp/include/qpid/swig_python_typemaps.i
+++ b/qpid/cpp/include/qpid/swig_python_typemaps.i
@@ -61,6 +61,11 @@ typedef int Py_ssize_t;
if (PyInt_Check(value)) return qpid::types::Variant(int64_t(PyInt_AS_LONG(value)));
if (PyLong_Check(value)) return qpid::types::Variant(int64_t(PyLong_AsLongLong(value)));
if (PyString_Check(value)) return qpid::types::Variant(std::string(PyString_AS_STRING(value)));
+ if (PyUnicode_Check(value)) {
+ qpid::types::Variant v(std::string(PyUnicode_AS_DATA(value)));
+ v.setEncoding("utf8");
+ return v;
+ }
if (PyDict_Check(value)) {
qpid::types::Variant::Map map;
PyToMap(value, &map);
@@ -116,7 +121,10 @@ typedef int Py_ssize_t;
}
case qpid::types::VAR_STRING : {
const std::string val(v->asString());
- result = PyString_FromStringAndSize(val.c_str(), val.size());
+ if (v->getEncoding() == "utf8")
+ result = PyUnicode_FromStringAndSize(val.c_str(), val.size());
+ else
+ result = PyString_FromStringAndSize(val.c_str(), val.size());
break;
}
case qpid::types::VAR_MAP : {
diff --git a/qpid/cpp/src/qpid/messaging/Message.cpp b/qpid/cpp/src/qpid/messaging/Message.cpp
index b40ae06cbc..62ee93b6c2 100644
--- a/qpid/cpp/src/qpid/messaging/Message.cpp
+++ b/qpid/cpp/src/qpid/messaging/Message.cpp
@@ -73,6 +73,7 @@ void Message::setRedelivered(bool redelivered) { impl->setRedelivered(redelivere
const Variant::Map& Message::getProperties() const { return impl->getHeaders(); }
Variant::Map& Message::getProperties() { return impl->getHeaders(); }
+void Message::setProperties(const Variant::Map& p) { getProperties() = p; }
void Message::setProperty(const std::string& k, const qpid::types::Variant& v) { impl->setHeader(k,v); }
void Message::setContent(const std::string& c) { impl->setBytes(c); }