summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/python/python.i
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2013-07-16 10:50:43 +0000
committerGordon Sim <gsim@apache.org>2013-07-16 10:50:43 +0000
commitc45a0c6ab32069730752f2f10e30cce7595c74ec (patch)
tree0ad5ae6a41efcf28adc31bef72551d172bcca087 /cpp/bindings/qpid/python/python.i
parentdd3daa5c3b8ce28d383643c94de41ecb9dd9ab7e (diff)
downloadqpid-python-c45a0c6ab32069730752f2f10e30cce7595c74ec.tar.gz
QPID-4988: Add test runs using swigged python client
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1503652 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/bindings/qpid/python/python.i')
-rw-r--r--cpp/bindings/qpid/python/python.i70
1 files changed, 54 insertions, 16 deletions
diff --git a/cpp/bindings/qpid/python/python.i b/cpp/bindings/qpid/python/python.i
index 148cad5e63..c10ea46000 100644
--- a/cpp/bindings/qpid/python/python.i
+++ b/cpp/bindings/qpid/python/python.i
@@ -139,8 +139,9 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
/* This only renames the non-const version (I believe). Then again, I
* don't even know why there is a non-const version of the method. */
%rename(opened) qpid::messaging::Connection::isOpen();
+%rename(_close) qpid::messaging::Connection::close();
%rename(receiver) qpid::messaging::Session::createReceiver;
-%rename(sender) qpid::messaging::Session::createSender;
+%rename(_sender) qpid::messaging::Session::createSender;
%rename(_acknowledge_all) qpid::messaging::Session::acknowledge(bool);
%rename(_acknowledge_msg) qpid::messaging::Session::acknowledge(
Message &, bool);
@@ -169,20 +170,26 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
# when possible.
def __init__(self, url=None, **options):
if url:
- args = [url]
+ args = [str(url)]
else:
args = []
- if options :
- if "sasl_mechanisms" in options :
- if ' ' in options.get("sasl_mechanisms",'') :
- raise Exception(
- "C++ Connection objects are unable to handle "
- "multiple sasl-mechanisms")
- options["sasl_mechanism"] = options.pop("sasl_mechanisms")
- args.append(options)
+ if options:
+ # remove null valued options
+ clean_opts = {}
+ for k, v in options.iteritems():
+ if v:
+ clean_opts[k] = v
+ args.append(clean_opts)
this = _cqpid.new_Connection(*args)
try: self.this.append(this)
except: self.this = this
+
+ def attached(self):
+ return self.opened()
+
+ def close(self, timeout=None):
+ #timeout not supported in c++
+ self._close()
%}
/* Return a pre-existing session with the given name, if one
@@ -236,18 +243,29 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
__swig_getmethods__["connection"] = getConnection
if _newclass: connection = property(getConnection)
+
+ def sender(self, target, **options) :
+ s = self._sender(target)
+ s._setDurable(options.get("durable"))
+ return s
%}
}
%extend qpid::messaging::Receiver {
%pythoncode %{
+ def _get_source(self):
+ return self.getAddress().str()
+
__swig_getmethods__["capacity"] = getCapacity
__swig_setmethods__["capacity"] = setCapacity
if _newclass: capacity = property(getCapacity, setCapacity)
__swig_getmethods__["session"] = getSession
if _newclass: session = property(getSession)
+
+ __swig_getmethods__["source"] = _get_source
+ if _newclass: source = property(_get_source)
%}
%pythoncode %{
@@ -263,19 +281,31 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
%extend qpid::messaging::Sender {
%pythoncode %{
+ def _get_target(self):
+ return self.getAddress().str()
+
+ def _setDurable(self, d):
+ self.durable = d
+
def send(self, object, sync=True) :
if isinstance(object, Message):
message = object
else:
message = Message(object)
+ if self.durable and message.durable is None:
+ message.durable = self.durable
return self._send(message, sync)
-
+
__swig_getmethods__["capacity"] = getCapacity
__swig_setmethods__["capacity"] = setCapacity
if _newclass: capacity = property(getCapacity, setCapacity)
__swig_getmethods__["session"] = getSession
if _newclass: session = property(getSession)
+
+ __swig_getmethods__["target"] = _get_target
+ if _newclass: source = property(_get_target)
+
%}
}
@@ -293,7 +323,7 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
this = _cqpid.new_Message('')
try: self.this.append(this)
except: self.this = this
- if content :
+ if not content is None:
self.content = content
if content_type != UNSPECIFIED :
self.content_type = content_type
@@ -327,21 +357,29 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
return decodeMap(self)
return self.getContent()
def _set_content(self, content) :
- if isinstance(content, basestring) :
+ if isinstance(content, str) :
self.setContent(content)
+ elif isinstance(content, unicode) :
+ if not self.content_type: self.content_type = "text/plain"
+ self.setContent(str(content))
elif isinstance(content, list) or isinstance(content, dict) :
encode(content, self)
else :
# Not a type we can handle. Try setting it anyway,
# although this will probably lead to a swig error
- self.setContent(content)
+ self.setContent(str(content))
__swig_getmethods__["content"] = _get_content
__swig_setmethods__["content"] = _set_content
if _newclass: content = property(_get_content, _set_content)
- __swig_getmethods__["content_type"] = getContentType
+ def _get_content_type(self) :
+ ct = self.getContentType()
+ if ct == "": return None
+ else: return ct
+
+ __swig_getmethods__["content_type"] = _get_content_type
__swig_setmethods__["content_type"] = setContentType
- if _newclass: content_type = property(getContentType, setContentType)
+ if _newclass: content_type = property(_get_content_type, setContentType)
__swig_getmethods__["id"] = getMessageId
__swig_setmethods__["id"] = setMessageId