2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18 # $Id: __init__.py,v 1.40 2007-11-07 20:47:12 richard Exp $
20 '''Container for the hyperdb storage backend implementations.
22 __docformat__
= 'restructuredtext'
26 # These names are used to suppress import errors.
27 # If get_backend raises an ImportError with appropriate
28 # module name, have_backend quietly returns False.
29 # Otherwise the error is reraised.
31 'mysql': ('MySQLdb',),
32 'postgresql': ('psycopg',),
33 'tsearch2': ('psycopg',),
34 'sqlite': ('pysqlite', 'pysqlite2', 'sqlite3', '_sqlite3', 'sqlite'),
37 def get_backend(name
):
38 '''Get a specific backend by name.'''
40 # if requested backend has been imported yet, return current instance
43 # import the backend module
44 module_name
= 'back_%s' % name
46 module
= __import__(module_name
, vars)
48 # import failed, but in versions prior to 2.4, a (broken)
49 # module is left in sys.modules and package globals;
50 # subsequent imports would succeed and get the broken module.
51 # This no longer happens in Python 2.4 and later.
52 if sys
.version_info
< (2, 4):
53 del sys
.modules
['.'.join((__name__
, module_name
))]
60 def have_backend(name
):
61 '''Is backend "name" available?'''
62 if name
== 'tsearch2':
63 # currently not working
68 except ImportError, e
:
69 for name
in _modules
.get(name
, (name
,)):
70 if str(e
).startswith('No module named %s'%name
):
76 '''List all available backend names.
78 This function has side-effect of registering backward-compatible
79 globals for all available backends.
83 for name
in 'anydbm', 'mysql', 'sqlite', 'postgresql':
84 if have_backend(name
):
88 # vim: set filetype=python sts=4 sw=4 et si :