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

Source Code for Package wtf.ext.db

  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  # pylint: disable = W0611 
 28  from wtf.ext.db import _config 
 29  from wtf.ext.db import _connection 
 30  from wtf.ext.db import _tagged as tagged 
 31  from wtf.ext.db._decorators import connection, transaction 
 32  from wtf.ext.db._exceptions import __all__ 
 33  from wtf.ext.db._exceptions import * # pylint: disable = W0401, W0614 
 34  from wtf.ext.db._service import DBService 
 35  __all__ = __all__ + [ 
 36      'driver', 'connect', 'configure', 'connection', 'transaction', 'tagged', 
 37      'DBService', 
 38  ] 
 39   
 40   
41 -def driver(dbname):
42 """ 43 Determine driver module 44 45 :Parameters: 46 `dbname` : ``str`` 47 DB name (section token in db.conf) 48 49 :Return: Driver module 50 :Rtype: ``module`` 51 52 :Exceptions: 53 - `DBConfigurationError` : DB not configured 54 - `KeyError` : DB name not found 55 - `ImportError` : Driver not found 56 """ 57 return _connection.driver(dbname)
58 59
60 -def connect(dbname, **kwargs):
61 """ 62 Connect to database 63 64 :Parameters: 65 `dbname` : ``str`` 66 DB name (section token in db.conf) 67 68 `kwargs` : ``dict`` 69 Additional parameters for adapter connect() call 70 71 :Return: new connection 72 :Rtype: connection object (DBAPI 2) 73 74 :Exceptions: 75 - `DBConfigurationError` : DB not configured 76 - `KeyError` : DB name not found 77 - `ImportError` : Driver not found 78 """ 79 return _connection.connect(dbname, **kwargs)
80 81
82 -def configure(dbconf=None, unpack_password=None):
83 """ 84 Configure the databases 85 86 :Parameters: 87 `dbconf` : ``str`` 88 Config file name. If omitted or ``None``, the environment variable 89 ``WTF_EXT_DB_CONF`` is queried. If that's unset, too, it defaults to 90 ``%r``. 91 92 `unpack_password` : callable 93 Password unpacker. If omitted or ``None``, no password unpacker is 94 applied. 95 96 :Exceptions: 97 - `DBConfigurationError` : Configuration failed (file missing or 98 something) 99 """ 100 _connection.configure(dbconf, unpack_password)
101 if configure.__doc__: 102 # pylint: disable = W0622 103 configure.__doc__ = configure.__doc__ % (_config.DEFAULT_CONF,) 104 105 106 try: 107 configure() 108 except DBConfigurationError: 109 pass # ignore for autoconfiguration 110