summaryrefslogtreecommitdiff
path: root/kombu/transport/mongodb.py
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2013-10-07 14:56:58 +0100
committerAsk Solem <ask@celeryproject.org>2013-10-07 14:56:58 +0100
commit3a3cabb9a567540a8f90faf96493286133888763 (patch)
tree5f7e20589a0de6bd15585fe2dd86724494f14c11 /kombu/transport/mongodb.py
parent221ae11044dc6d66e53801938a20cdb8b52548a5 (diff)
downloadkombu-3a3cabb9a567540a8f90faf96493286133888763.tar.gz
Fixes MongoDB host parsing
Diffstat (limited to 'kombu/transport/mongodb.py')
-rw-r--r--kombu/transport/mongodb.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/kombu/transport/mongodb.py b/kombu/transport/mongodb.py
index b46c87dd..e4c4f501 100644
--- a/kombu/transport/mongodb.py
+++ b/kombu/transport/mongodb.py
@@ -98,23 +98,28 @@ class Channel(virtual.Channel):
hostname = client.hostname or DEFAULT_HOST
authdb = dbname = client.virtual_host
- if dbname in ["/", None]:
+ if dbname in ['/', None]:
dbname = "kombu_default"
authdb = "admin"
+ if not hostname.startswith('mongodb://'):
+ hostname = 'mongodb://' + hostname
- if not client.userid:
- hostname = hostname.replace('/' + client.virtual_host, '/')
- else:
- hostname = hostname.replace('/' + client.virtual_host,
- '/' + authdb)
+ if not hostname[10:]:
+ hostname = hostname + 'localhost'
+
+ if '/' in hostname[10:]:
+ if not client.userid:
+ hostname = hostname.replace('/' + client.virtual_host, '/')
+ else:
+ hostname = hostname.replace('/' + client.virtual_host,
+ '/' + authdb)
- mongo_uri = 'mongodb://' + hostname
# At this point we expect the hostname to be something like
# (considering replica set form too):
#
# mongodb://[username:password@]host1[:port1][,host2[:port2],
# ...[,hostN[:portN]]][/[?options]]
- mongoconn = MongoClient(host=mongo_uri, ssl=client.ssl)
+ mongoconn = MongoClient(host=hostname, ssl=client.ssl)
database = getattr(mongoconn, dbname)
version = mongoconn.server_info()['version']