def _connection(username=None, password=None, host=None, port=None, db=None):
    "returns a connected cursor to the database-server."

    c_opts = {}

    if username: c_opts['user'] = username
    if password: c_opts['password'] = password
    if host: c_opts['host'] = host
    if port: c_opts['port'] = port
    if db: c_opts['database'] = db

    dbc = psycopg2.connect(**c_opts)
    dbc.autocommit = True
    return dbc
returns a connected cursor to the database-server.