Take last host if multiple defined

This commit is contained in:
Don Brown
2014-04-01 12:06:11 -06:00
parent 9f5bdb3926
commit 924825d6b4
2 changed files with 8 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ class Pool:
except (AttributeError, ValueError): except (AttributeError, ValueError):
raise Exception("Missing database name in URI") raise Exception("Missing database name in URI")
self._host = url.hostname host = url.hostname
try: try:
port = url.port port = url.port
@@ -63,10 +63,15 @@ class Pool:
# strip any additional hosts in the connection string for now # strip any additional hosts in the connection string for now
try: try:
if "," in port: if "," in port:
port = port[:port.find(',')] hosts = port.split(",")
netloc = hosts[len(hosts)-1]
netloc = netloc.split(':')
host = netloc[0]
port = netloc[1]
except TypeError: except TypeError:
pass pass
self._host = host
self._port = port or 27017 self._port = port or 27017
username = url.username username = url.username
password = url.password password = url.password

View File

@@ -45,7 +45,7 @@ class TestMongoConnectionMethods(MongoTest):
@async @async
def test_pool_multiple_hosts(self): def test_pool_multiple_hosts(self):
# MongoConnectionPool returns deferred, which gets MongoAPI # MongoConnectionPool returns deferred, which gets MongoAPI
pool = asyncio_mongo.Pool.create(url="mongodb://{host}:{port},otherhost:333".format( pool = asyncio_mongo.Pool.create(url="mongodb://blahhost:333,{host}:{port}".format(
host=mongo_host, port=mongo_port), poolsize=2) host=mongo_host, port=mongo_port), poolsize=2)
self.assertTrue(inspect.isgenerator(pool)) self.assertTrue(inspect.isgenerator(pool))
rapi = yield from pool rapi = yield from pool