Package wtf :: Package ext :: Package db :: Module _connection
[hide private]
[frames] | no frames]

Source Code for Module wtf.ext.db._connection

 1  # -*- coding: ascii -*- 
 2  # 
 3  # Copyright 2010-2012 
 4  # Andr\xe9 Malo or his licensors, as applicable 
 5  # 
 6  # Licensed under the Apache License, Version 2.0 (the "License"); 
 7  # you may not use this file except in compliance with the License. 
 8  # You may obtain a copy of the License at 
 9  # 
10  #     http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  # Unless required by applicable law or agreed to in writing, software 
13  # distributed under the License is distributed on an "AS IS" BASIS, 
14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  # See the License for the specific language governing permissions and 
16  # limitations under the License. 
17  """ 
18  ========== 
19   DB stuff 
20  ========== 
21   
22  DB stuff. 
23  """ 
24  __author__ = u"Andr\xe9 Malo" 
25  __docformat__ = "restructuredtext en" 
26   
27  from wtf.ext.db import _config 
28  from wtf.ext.db._exceptions import DBConfigurationError 
29   
30   
31 -def driver(dbname):
32 """ 33 Determine driver module 34 35 :Parameters: 36 `dbname` : ``str`` 37 DB name (section token in db.conf) 38 39 :Return: Driver module 40 :Rtype: ``module`` 41 42 :Exceptions: 43 - `DBConfigurationError` : DB not configured 44 - `KeyError` : DB name not found 45 - `ImportError` : Driver not found 46 """ 47 # pylint: disable = W0613 48 raise DBConfigurationError("Databases not configured")
49 50
51 -def connect(dbname, **kwargs):
52 """ 53 Connect to database 54 55 :Parameters: 56 `dbname` : ``str`` 57 DB name (section token in db.conf) 58 59 `kwargs` : ``dict`` 60 Additional parameters for adapter connect() call 61 62 :Return: new connection 63 :Rtype: connection object (DBAPI 2) 64 65 :Exceptions: 66 - `DBConfigurationError` : DB not configured 67 - `KeyError` : DB name not found 68 - `ImportError` : Driver not found 69 """ 70 # pylint: disable = W0613 71 raise DBConfigurationError("Databases not configured")
72 73
74 -def configure(dbconf=None, unpack_password=None):
75 """ 76 Configure the databases 77 78 :Parameters: 79 `dbconf` : ``str`` 80 Config file name. If omitted or ``None``, the environment variable 81 ``WTF_EXT_DB_CONF`` is queried. If that's unset, too, it defaults to 82 ``'/etc/wtf/ext/db.conf'``. 83 84 `unpack_password` : callable 85 Password unpacker. If omitted or ``None``, no password unpacker is 86 applied. 87 88 :Exceptions: 89 - `DBConfigurationError` : Configuration failed (file missing or 90 something) 91 """ 92 global driver, connect # pylint: disable = W0601 93 driver, connect = _config.configure(dbconf, unpack_password)
94