summaryrefslogtreecommitdiff
path: root/qpid/python
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/python')
-rw-r--r--qpid/python/qpid/client.py2
-rw-r--r--qpid/python/qpid/tests/util.py22
-rw-r--r--qpid/python/qpid/util.py13
3 files changed, 25 insertions, 12 deletions
diff --git a/qpid/python/qpid/client.py b/qpid/python/qpid/client.py
index b0ce5d9009..fbec7ccc7d 100644
--- a/qpid/python/qpid/client.py
+++ b/qpid/python/qpid/client.py
@@ -89,7 +89,7 @@ class Client:
self.password = password
self.locale = locale
self.tune_params = tune_params
- self.client_properties=get_client_properties_with_defaults(provided_client_properties=client_properties)
+ self.client_properties=get_client_properties_with_defaults(provided_client_properties=client_properties, version_property_key="version")
self.sasl_options = sasl_options
self.socket = connect(self.host, self.port, connection_options)
self.conn = Connection(self.socket, self.spec)
diff --git a/qpid/python/qpid/tests/util.py b/qpid/python/qpid/tests/util.py
index 9777443720..4e901218c2 100644
--- a/qpid/python/qpid/tests/util.py
+++ b/qpid/python/qpid/tests/util.py
@@ -21,26 +21,32 @@ from qpid.util import get_client_properties_with_defaults
class UtilTest (TestCase):
- def test_get_spec_recommended_client_properties(self):
- client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"})
+ def test_default_client_properties_08091(self):
+ client_properties = get_client_properties_with_defaults(version_property_key="version")
self.assertTrue("product" in client_properties)
self.assertTrue("version" in client_properties)
self.assertTrue("platform" in client_properties)
- def test_get_client_properties_with_provided_value(self):
+ def test_default_client_properties_010(self):
+ client_properties = get_client_properties_with_defaults(version_property_key="qpid.client_version")
+ self.assertTrue("product" in client_properties)
+ self.assertTrue("qpid.client_version" in client_properties)
+ self.assertTrue("platform" in client_properties)
+
+ def test_client_properties_with_provided_value(self):
client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"})
self.assertTrue("product" in client_properties)
self.assertTrue("mykey" in client_properties)
self.assertEqual("myvalue", client_properties["mykey"])
- def test_get_client_properties_with_no_provided_values(self):
+ def test_client_properties_with_provided_value_that_overrides_default(self):
+ client_properties = get_client_properties_with_defaults(provided_client_properties={"product":"myproduct"})
+ self.assertEqual("myproduct", client_properties["product"])
+
+ def test_client_properties_with_no_provided_values(self):
client_properties = get_client_properties_with_defaults(provided_client_properties=None)
self.assertTrue("product" in client_properties)
client_properties = get_client_properties_with_defaults()
self.assertTrue("product" in client_properties)
- def test_get_client_properties_with_provided_value_that_overrides_default(self):
- client_properties = get_client_properties_with_defaults(provided_client_properties={"version":"myversion"})
- self.assertEqual("myversion", client_properties["version"])
-
diff --git a/qpid/python/qpid/util.py b/qpid/python/qpid/util.py
index 37d999b771..fb343b536a 100644
--- a/qpid/python/qpid/util.py
+++ b/qpid/python/qpid/util.py
@@ -17,7 +17,7 @@
# under the License.
#
-import os, socket, time, textwrap, re, sys
+import os, socket, time, textwrap, re, sys, pkg_resources
try:
from ssl import wrap_socket as ssl
@@ -42,15 +42,22 @@ except ImportError:
def close(self):
self.sock.close()
-def get_client_properties_with_defaults(provided_client_properties={}):
+def get_client_properties_with_defaults(provided_client_properties={}, version_property_key="qpid.client_version"):
ppid = 0
+ version = "unidentified"
try:
ppid = os.getppid()
except:
pass
+ try:
+ pkg = pkg_resources.require("qpid-python")
+ version = pkg[0].version if pkg and pkg[0] and pkg[0].version else version
+ except:
+ pass
+
client_properties = {"product": "qpid python client",
- "version": "development",
+ version_property_key : version,
"platform": os.name,
"qpid.client_process": os.path.basename(sys.argv and sys.argv[0] or ''),
"qpid.client_pid": os.getpid(),