[pypy-svn] r66661 - in pypy/branch/pyjitpl5/pypy/lib: . app_test
arigo at codespeak.net
arigo at codespeak.net
Wed Jul 29 14:09:17 CEST 2009
Author: arigo
Date: Wed Jul 29 14:09:15 2009
New Revision: 66661
Added:
pypy/branch/pyjitpl5/pypy/lib/app_test/test_dbm_extra.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5/pypy/lib/dbm.py
Log:
Fix: d.get(key) without a default should be equivalent to
d.get(key, None). It should not raise KeyError.
Added: pypy/branch/pyjitpl5/pypy/lib/app_test/test_dbm_extra.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/lib/app_test/test_dbm_extra.py Wed Jul 29 14:09:15 2009
@@ -0,0 +1,9 @@
+from pypy.lib import dbm
+from pypy.tool.udir import udir
+
+def test_get():
+ path = str(udir.join('test_dbm_extra.test_get'))
+ d = dbm.open(path, 'c')
+ x = d.get("42")
+ assert x is None
+ d.close()
Modified: pypy/branch/pyjitpl5/pypy/lib/dbm.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/lib/dbm.py (original)
+++ pypy/branch/pyjitpl5/pypy/lib/dbm.py Wed Jul 29 14:09:15 2009
@@ -2,9 +2,6 @@
import ctypes.util
import os, sys
-class _singleton(object):
- pass
-
class error(Exception):
def __init__(self, msg):
self.msg = msg
@@ -36,7 +33,7 @@
k = getattr(lib, funcs['nextkey'])(self._aobj)
return allkeys
- def get(self, key, default=_singleton):
+ def get(self, key, default=None):
if not self._aobj:
raise error('DBM object has already been closed')
dat = datum()
@@ -45,8 +42,6 @@
k = getattr(lib, funcs['fetch'])(self._aobj, dat)
if k.dptr:
return k.dptr[:k.dsize]
- if default is _singleton:
- raise KeyError
if getattr(lib, funcs['error'])(self._aobj):
getattr(lib, funcs['clearerr'])(self._aobj)
raise error("")
More information about the Pypy-commit
mailing list