Re: RFC: Extend psycopg2.connect to accept all valid parameters?

Поиск
Список
Период
Сортировка
От Fabian Knittel
Тема Re: RFC: Extend psycopg2.connect to accept all valid parameters?
Дата
Msg-id 4EC4118C.2030806@avona.com
обсуждение исходный текст
Ответ на Re: RFC: Extend psycopg2.connect to accept all valid parameters?  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Ответы Re: RFC: Extend psycopg2.connect to accept all valid parameters?  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список psycopg
Hello Daniele,

Am 16.11.2011 19:56, schrieb Daniele Varrazzo:
> On Wed, Nov 16, 2011 at 5:56 PM, Fabian Knittel
> <fabian.knittel@avona.com> wrote:
>> I'm trying to pass the "sslrootcert" connection keyword parameter
>> through sqlalchemy and psycopg2.
[...]
> os.environ['PGSSLROOTCERT'] is (should be) your friend. Also see
> <http://www.postgresql.org/docs/9.1/static/libpq-envars.html>.

True, this is another possible approach.  I personally don't see it as
viable solution, because it's not easy to configure via a configuration
file and you can't really configure multiple connections.  In my
applications you currently select and configure all DB backends by
setting apropriate connection URIs in the configuration file.  Using
environment variables to configure some aspects of a backend would need
explicit code to set and unset the options when using the PostgreSQL
backend (carefully setting it right before a specific connection and
resetting it for the next connection with a different setting).  This is
possible, but IMHO falls into the work-around category.  I'd probably
use the dsn-work-around mentioned in my initial mail before resorting to
environment variables.

>> Properly fixing it in psycopg2 would probably mean accepting all missing
>> keywords [4] in psycopg2.connect.
>
>> 4: Currently missing keywords: hostaddr, connect_timeout,
>> client_encoding, options, application_name, fallback_application_name,
>> keepalives, keepalives_idle, keepalives_interval, keepalives_count,
>> sslcert, sslkey, sslrootcert, sslcrl, requirepeer, krbsrvname, gsslib,
>> service. (I've omitted requiressl and tty, because they are
>> deprecated/ignored.)
>
> As you see they are a lot, and counting. If I'm not mistaken there is
> a fallback env variable for each of them. [...]

(Sorry, I should have sorted my proposed solutions.)

I agree that option a) is probably the least desirable one.  But what do
you think of option b)?  Effectively, it would be something along the
lines of

  dsn = ' '.join(
      ['%s=%s' % (key, str(val)) for key, val in kwargs.iteritems()])

translated to C (with a few additional translations, e.g. database to
dbname).  All keyword arguments would be translated to a connection
string, without explicit checking.  Any unknown keywords would then be
detected by libpq the same way they are detected when the dsn is
explicitly given.

Cheers
Fabian


Вложения

В списке psycopg по дате отправления:

Предыдущее
От: Daniele Varrazzo
Дата:
Сообщение: Re: RFC: Extend psycopg2.connect to accept all valid parameters?
Следующее
От: Daniele Varrazzo
Дата:
Сообщение: Re: RFC: Extend psycopg2.connect to accept all valid parameters?