Getting adaped output from unicode text, without a connection - Mailing list psycopg

From Hefferon, James S.
Subject Getting adaped output from unicode text, without a connection
Date
Msg-id 8E15C2BC0B63AD4AA20BF9F1C3947FC157492F75@SMCEXMBX02.mikenet.smcvt.edu
Whole thread Raw
Responses Re: Getting adaped output from unicode text, without a connection  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Re: Getting adaped output from unicode text, without a connection  (Adrian Klaver <adrian.klaver@gmail.com>)
List psycopg
Hello,

I need to write some static .sql files (just as an explanation, it is startup code for Django).  Some of the strings
arenon-ascii.  I'm stumped about how to get utf-8 instead of latin-1 in the file. 

I'm generating the .sql as strings, without a connection.  I found a prior message on this list that suggested what to
do(1) and came up with this routine. 

def todb(s):
    psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
    psycopg2.extensions.register_type(psycopg2.extensions.DECIMAL)
    psycopg2.extensions.register_type(psycopg2.extensions.FLOAT)
    adapted = psycopg2.extensions.adapt(s)
    return adapted.getquoted()

But it encodes in latin-1.  I understand from the docs that I need to get a connection and set the .encoding attribute,
butI can't see how to get a connection instance without a db handy.  For instance,  

>>> conn = psycopg2.connect(database = None)

fails.

I expect that I am asking a dopey question (I'm not very sure what I am doing) but I'd appreciate a pointer even if it
makesme feel dumb. 

Thanks,
Jim

(1) http://www.postgresql.org/message-id/AANLkTik+tq8hbnCj3ROmOLNV1DSw48o4sDoSvnxTN3R8@mail.gmail.com

psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: Connection failures when using green
Next
From: Daniele Varrazzo
Date:
Subject: Re: Getting adaped output from unicode text, without a connection