diff options
author | Ask Solem <ask@celeryproject.org> | 2013-10-07 14:56:58 +0100 |
---|---|---|
committer | Ask Solem <ask@celeryproject.org> | 2013-10-07 14:56:58 +0100 |
commit | 3a3cabb9a567540a8f90faf96493286133888763 (patch) | |
tree | 5f7e20589a0de6bd15585fe2dd86724494f14c11 /kombu | |
parent | 221ae11044dc6d66e53801938a20cdb8b52548a5 (diff) | |
download | kombu-3a3cabb9a567540a8f90faf96493286133888763.tar.gz |
Fixes MongoDB host parsing
Diffstat (limited to 'kombu')
-rw-r--r-- | kombu/transport/mongodb.py | 21 |
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'] |