Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PostgreSQLConnection(psycopg2.extensions.connection):
- """
- A custom `connection_factory` for :func:`psycopg2.connect`.
- This
- * puts the connection into unicode mode (for text)
- * modifies the :meth:`cursor` method of a :class:`psycopg2.connection`,
- facilitating easy acquiring of cursors made from
- :cls:`psycopg2.extras.RealDictCursor`.
- """
- # this may be omitted in py3k
- def __init__(self, *args, **kwargs):
- super(PostgreSQLConnection, self).__init__(*args, **kwargs)
- for type in (psycopg2.extensions.UNICODE,
- psycopg2.extensions.UNICODEARRAY):
- psycopg2.extensions.register_type(type, self)
- def cursor(self, real_dict_cursor=False):
- """
- Get a new cursor.
- If real_dict_cursor is set, a RealDictCursor is returned
- """
- kwargs = {}
- if real_dict_cursor:
- kwargs["cursor_factory"] = psycopg2.extras.RealDictCursor
- return super(PostgreSQLConnection, self).cursor(**kwargs)
Add Comment
Please, Sign In to add comment