Re: Feature branches merged to master for 2.8 release - Mailing list psycopg

From Daniele Varrazzo
Subject Re: Feature branches merged to master for 2.8 release
Date
Msg-id CA+mi_8bE7Z5BZ3O6Q1QxbCFtfBTthcNAaVa65GQs+sUTZbroTg@mail.gmail.com
Whole thread Raw
In response to Re: Feature branches merged to master for 2.8 release  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List psycopg
On Mon, Oct 29, 2018 at 10:54 AM Karsten Hilbert
<Karsten.Hilbert@gmx.net> wrote:

> Apart from a wrapper class one can always monkey-patch
>
>         my_dbapi_instance._get_native_connection = my_dbapi_instance.get_native_connection
>
> at runtime.

True for a Python object, but not for a C extension object. But
subclassing is supported, so one would be able to do:

    >>> class MyConnection(psycopg2.extensions.connection):
    ...     _get_native_connection =
psycopg2.extensions.connection.get_native_connection
    ...
    >>> cnn = psycopg2.connect('', connection_factory=MyConnection)
    >>> ptr = cnn._get_native_connection()

-- Daniele


psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: Feature branches merged to master for 2.8 release
Next
From: Akshay Joshi
Date:
Subject: Re: psycopg2 conn.poll() hangs when used with sshtunnel