Merge from trunk
[plcapi.git] / trunk / psycopg2 / lib / extensions.py
1 """psycopg extensions to the DBAPI-2.0
2
3 This module holds all the extensions to the DBAPI-2.0 provided by psycopg.
4
5 - `connection` -- the new-type inheritable connection class
6 - `cursor` -- the new-type inheritable cursor class
7 - `adapt()` -- exposes the PEP-246_ compatible adapting mechanism used
8   by psycopg to adapt Python types to PostgreSQL ones
9   
10 .. _PEP-246: http://www.python.org/peps/pep-0246.html
11 """
12 # psycopg/extensions.py - DBAPI-2.0 extensions specific to psycopg
13 #
14 # Copyright (C) 2003-2004 Federico Di Gregorio  <fog@debian.org>
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by the
18 # Free Software Foundation; either version 2, or (at your option) any later
19 # version.
20 #
21 # This program is distributed in the hope that it will be useful, but
22 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
23 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24 # for more details.
25
26 from _psycopg import UNICODE, INTEGER, LONGINTEGER, BOOLEAN, FLOAT
27 from _psycopg import TIME, DATE, INTERVAL
28
29 from _psycopg import Boolean, QuotedString, AsIs
30 try:
31     from _psycopg import DateFromMx, TimeFromMx, TimestampFromMx
32     from _psycopg import IntervalFromMx
33 except:
34     pass
35 try:
36     from _psycopg import DateFromPy, TimeFromPy, TimestampFromPy
37     from _psycopg import IntervalFromPy
38 except:
39     pass
40
41 from _psycopg import adapt, adapters, encodings, connection, cursor
42 from _psycopg import string_types, binary_types, new_type, register_type
43 from _psycopg import ISQLQuote
44
45 """Isolation level values."""
46 ISOLATION_LEVEL_AUTOCOMMIT     = 0
47 ISOLATION_LEVEL_READ_COMMITTED = 1 
48 ISOLATION_LEVEL_SERIALIZABLE   = 2
49
50 # PostgreSQL maps the the other standard values to already defined levels
51 ISOLATION_LEVEL_REPEATABLE_READ  = ISOLATION_LEVEL_SERIALIZABLE
52 ISOLATION_LEVEL_READ_UNCOMMITTED = ISOLATION_LEVEL_READ_COMMITTED
53
54 """Transaction status values."""
55 STATUS_SETUP = 0
56 STATUS_READY    = 1
57 STATUS_BEGIN    = 2
58 STATUS_SYNC     = 3
59 STATUS_ASYNC    = 4
60
61 # This is a usefull mnemonic to check if the connection is in a transaction
62 STATUS_IN_TRANSACTION = STATUS_BEGIN
63
64
65 def register_adapter(typ, callable):
66     """Register 'callable' as an ISQLQuote adapter for type 'typ'."""
67     adapters[(typ, ISQLQuote)] = callable
68
69 __all__ = [ k for k in locals().keys() if not k.startswith('_') ]