Skip to content

Commit f1b22e9

Browse files
author
Johannes Gijsbers
committed
Simplify backend importing, by moving the imports into the backend modules.
1 parent 7091e24 commit f1b22e9

File tree

2 files changed

+25
-64
lines changed

2 files changed

+25
-64
lines changed

roundup/backends/__init__.py

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: __init__.py,v 1.23 2003-04-24 06:55:24 richard Exp $
18+
# $Id: __init__.py,v 1.24 2003-09-14 18:55:37 jlgijsbers Exp $
1919

2020
''' Container for the hyperdb storage backend implementations.
2121
@@ -25,66 +25,17 @@
2525

2626
__all__ = []
2727

28-
try:
29-
import sys, anydbm
30-
if not hasattr(sys, 'version_info') or sys.version_info < (2,1,2):
31-
import dumbdbm
32-
# dumbdbm only works in python 2.1.2+
33-
assert anydbm._defaultmod != dumbdbm
34-
del anydbm
35-
del dumbdbm
36-
except AssertionError:
37-
print "WARNING: you should upgrade to python 2.1.3"
38-
except ImportError, message:
39-
if str(message) != 'No module named anydbm': raise
40-
else:
41-
import back_anydbm
42-
anydbm = back_anydbm
43-
__all__.append('anydbm')
44-
45-
try:
46-
import MySQLdb
47-
except ImportError, message:
48-
if str(message) != 'No module named MySQLdb': raise
49-
else:
50-
import back_mysql
51-
mysql = back_mysql
52-
__all__.append('mysql')
53-
54-
try:
55-
import sqlite
56-
except ImportError, message:
57-
if str(message) != 'No module named sqlite': raise
58-
else:
59-
import back_sqlite
60-
sqlite = back_sqlite
61-
__all__.append('sqlite')
62-
63-
try:
64-
import bsddb
65-
except ImportError, message:
66-
if not str(message).startswith('No module named'): raise
67-
else:
68-
import back_bsddb
69-
bsddb = back_bsddb
70-
__all__.append('bsddb')
71-
72-
try:
73-
import bsddb3
74-
except ImportError, message:
75-
if str(message) != 'No module named bsddb3': raise
76-
else:
77-
import back_bsddb3
78-
bsddb3 = back_bsddb3
79-
__all__.append('bsddb3')
80-
81-
try:
82-
import metakit
83-
except ImportError, message:
84-
if str(message) != 'No module named metakit': raise
85-
else:
86-
import back_metakit
87-
metakit = back_metakit
88-
__all__.append('metakit')
28+
for backend in ['anydbm', ('mysql', 'MySQLdb'), 'bsddb', 'bsddb3', 'sqlite',
29+
'metakit']:
30+
if len(backend) == 2:
31+
backend, backend_module = backend
32+
else:
33+
backend_module = backend
34+
try:
35+
globals()[backend] = __import__('back_%s' % backend, globals())
36+
__all__.append(backend)
37+
except ImportError, e:
38+
if not str(e).startswith('No module named %s' % backend_module):
39+
raise
8940

9041
# vim: set filetype=python ts=4 sw=4 et si

roundup/backends/back_anydbm.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.127 2003-09-08 20:39:18 jlgijsbers Exp $
18+
#$Id: back_anydbm.py,v 1.128 2003-09-14 18:55:37 jlgijsbers Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
2222
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
2323
serious bugs, and is not available)
2424
'''
2525

26-
import whichdb, anydbm, os, marshal, re, weakref, string, copy
26+
try:
27+
import anydbm, sys
28+
# dumbdbm only works in python 2.1.2+
29+
if sys.version_info < (2,1,2):
30+
import dumbdbm
31+
assert anydbm._defaultmod != dumbdbm
32+
del dumbdbm
33+
except AssertionError:
34+
print "WARNING: you should upgrade to python 2.1.3"
35+
36+
import whichdb, os, marshal, re, weakref, string, copy
2737
from roundup import hyperdb, date, password, roundupdb, security
2838
from blobfiles import FileStorage
2939
from sessions import Sessions, OneTimeKeys

0 commit comments

Comments
 (0)