From b3f005e3e2b3c52fce46dddbef29cfe049dfddc6 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 12 Jan 2011 12:01:02 +0100 Subject: [PATCH] Adds BrokerConnection.as_uri(). Moved from Celery to Kombu --- kombu/connection.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kombu/connection.py b/kombu/connection.py index 0241b408..69ffaefc 100644 --- a/kombu/connection.py +++ b/kombu/connection.py @@ -22,6 +22,12 @@ from kombu.utils.compat import OrderedDict from kombu.utils.functional import wraps +#: Connection info -> URI +URI_FORMAT = """\ +%(transport)s://%(userid)s@%(hostname)s%(port)s%(virtual_host)s\ +""" + + class BrokerConnection(object): """A connection to the broker. @@ -60,6 +66,8 @@ class BrokerConnection(object): >>> conn.release() """ + URI_FORMAT = URI_FORMAT + port = None virtual_host = "/" connect_timeout = 5 @@ -237,6 +245,16 @@ class BrokerConnection(object): ("transport", transport_cls), ("connect_timeout", self.connect_timeout))) + def as_uri(self): + fields = self.info() + port = fields["port"] + if port: + fields["port"] = ":%s" % (port, ) + vhost = fields["virtual_host"] + if not vhost.startswith('/'): + fields["virtual_host"] = '/' + vhost + return self.URI_FORMAT % fields + def Pool(self, limit=None, preload=None): """Pool of connections.