'Connect to the CouchDB server.'

def _get_connection(self):

    if (self.username and self.password):
        conn_string = (u'%s://%s:%s@%s:%s' % (self.scheme, self.username, self.password, self.host, str(self.port)))
        server = pycouchdb.Server(conn_string, authmethod=u'basic')
    else:
        conn_string = (u'%s://%s:%s' % (self.scheme, self.host, str(self.port)))
        server = pycouchdb.Server(conn_string)
    try:
        return server.database(self.container)
    except pycouchdb.exceptions.NotFound:
        return server.create(self.container)
