Adds BrokerConnection.as_uri(). Moved from Celery to Kombu

This commit is contained in:
Ask Solem 2011-01-12 12:01:02 +01:00
parent 85112484d6
commit b3f005e3e2
1 changed files with 18 additions and 0 deletions

View File

@ -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.