summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-09-05 18:33:51 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-09-05 18:33:51 (GMT)
commit32476fc5a8c1e4bdfab04ab09b254a3c833e5785 (patch)
tree1ddd84d1817eec0dad96aae8ba8408db353b131a /Lib
parent6024834ed9887b47cfa798f20e99d5c941b97f24 (diff)
downloadcpython-32476fc5a8c1e4bdfab04ab09b254a3c833e5785.zip
cpython-32476fc5a8c1e4bdfab04ab09b254a3c833e5785.tar.gz
cpython-32476fc5a8c1e4bdfab04ab09b254a3c833e5785.tar.bz2
Deprecate bsddb for removal in Python 3.0.
Closes issue 3776. Review by Nick Coghlan.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/bsddb/__init__.py6
-rw-r--r--Lib/dbhash.py3
-rw-r--r--Lib/test/test_py3kwarn.py2
-rw-r--r--Lib/test/test_warnings.py1
-rw-r--r--Lib/warnings.py9
5 files changed, 19 insertions, 2 deletions
diff --git a/Lib/bsddb/__init__.py b/Lib/bsddb/__init__.py
index 0e5169c..0af679f 100644
--- a/Lib/bsddb/__init__.py
+++ b/Lib/bsddb/__init__.py
@@ -42,6 +42,12 @@ instead. It mirrors the Oracle Berkeley DB C API.
import sys
absolute_import = (sys.version_info[0] >= 3)
+if sys.py3kwarning:
+ import warnings
+ warnings.warnpy3k("in 3.x, bsddb has been removed; "
+ "please use the pybsddb project instead",
+ DeprecationWarning, 2)
+
try:
if __name__ == 'bsddb3':
# import _pybsddb binary as it should be the more recent version from
diff --git a/Lib/dbhash.py b/Lib/dbhash.py
index 9f8a9c3..5ca0bc1 100644
--- a/Lib/dbhash.py
+++ b/Lib/dbhash.py
@@ -1,6 +1,9 @@
"""Provide a (g)dbm-compatible interface to bsddb.hashopen."""
import sys
+if sys.py3kwarning:
+ import warnings
+ warnings.warnpy3k("in 3.x, dbhash has been removed", DeprecationWarning, 2)
try:
import bsddb
except ImportError:
diff --git a/Lib/test/test_py3kwarn.py b/Lib/test/test_py3kwarn.py
index 7bfe1e5..780de74 100644
--- a/Lib/test/test_py3kwarn.py
+++ b/Lib/test/test_py3kwarn.py
@@ -305,7 +305,7 @@ class TestStdlibRemovals(unittest.TestCase):
'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
}
optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
- 'sv', 'cPickle')
+ 'sv', 'cPickle', 'bsddb', 'dbhash')
def check_removal(self, module_name, optional=False):
"""Make sure the specified module, when imported, raises a
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index 1520bf2..9980f24 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -508,6 +508,7 @@ class CatchWarningTests(BaseTest):
wmod = self.module
with wmod.catch_warnings(module=wmod, record=True) as w:
self.assertEqual(w, [])
+ self.assertRaises(AttributeError, getattr, w, 'message')
wmod.simplefilter("always")
wmod.warn("foo")
self.assertEqual(str(w.message), "foo")
diff --git a/Lib/warnings.py b/Lib/warnings.py
index b699c43..9ec04be 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -314,7 +314,14 @@ class WarningsRecorder(list):
self.append(WarningMessage(*args, **kwargs))
def __getattr__(self, attr):
- return getattr(self[-1], attr)
+ """Return attributes from the last caught warning, or raise
+ AttributeError."""
+ try:
+ return getattr(self[-1], attr)
+ except IndexError:
+ raise AttributeError("no recorded warning to read "
+ "{0!r} attribute from".format(attr))
+
def reset(self):
del self[:]