'Returns a database connection'

def getDbConnection(self, hostKey):

    hostDef = None
    self.serverHostDefsLock.acquire()
    try:
        if (hostKey in self.serverHostDefs):
            hostDef = self.serverHostDefs[hostKey]
    finally:
        self.serverHostDefsLock.release()
    if (not hostDef):
        return None
    if (not self.settings.useSslForAllConnections):
        useSsl = False
        if ('ssl' in hostDef):
            useSsl = hostDef['ssl']
        if useSsl:
            return pymongo.Connection(hostDef['mongoUri'], slave_okay=True, ssl=True, document_class=bson.son.SON)
        else:
            return pymongo.Connection(hostDef['mongoUri'], slave_okay=True, document_class=bson.son.SON)
    else:
        return pymongo.Connection(hostDef['mongoUri'], slave_okay=True, ssl=True, document_class=bson.son.SON)
