Commit 8388895f authored by Anthony Baxter's avatar Anthony Baxter

SF patch [ 545523 ] patch for 514433 bsddb.dbopen (NULL)

closes SF #514433

can now pass 'None' as the filename for the bsddb.*open functions,
and you'll get an in-memory temporary store.

docs are ripped out of the bsddb dbopen man page. Fred may want to
clean them up.

Considering this for 2.2, but not 2.1.
parent 0494955b
...@@ -37,7 +37,9 @@ instances. ...@@ -37,7 +37,9 @@ instances.
ffactor\optional{, nelem\optional{, ffactor\optional{, nelem\optional{,
cachesize\optional{, hash\optional{, cachesize\optional{, hash\optional{,
lorder}}}}}}}}} lorder}}}}}}}}}
Open the hash format file named \var{filename}. The optional Open the hash format file named \var{filename}. Files never intended
to be preserved on disk may be created by passing \code{None} as the
\var{filename}. The optional
\var{flag} identifies the mode used to open the file. It may be \var{flag} identifies the mode used to open the file. It may be
\character{r} (read only), \character{w} (read-write), \character{r} (read only), \character{w} (read-write),
\character{c} (read-write - create if necessary) or \character{c} (read-write - create if necessary) or
...@@ -51,7 +53,9 @@ for their use and interpretation. ...@@ -51,7 +53,9 @@ for their use and interpretation.
mode\optional{, btflags\optional{, cachesize\optional{, maxkeypage\optional{, mode\optional{, btflags\optional{, cachesize\optional{, maxkeypage\optional{,
minkeypage\optional{, psize\optional{, lorder}}}}}}}}} minkeypage\optional{, psize\optional{, lorder}}}}}}}}}
Open the btree format file named \var{filename}. The optional Open the btree format file named \var{filename}. Files never intended
to be preserved on disk may be created by passing \code{None} as the
\var{filename}. The optional
\var{flag} identifies the mode used to open the file. It may be \var{flag} identifies the mode used to open the file. It may be
\character{r} (read only), \character{w} (read-write), \character{r} (read only), \character{w} (read-write),
\character{c} (read-write - create if necessary) or \character{c} (read-write - create if necessary) or
...@@ -65,7 +69,9 @@ interpretation. ...@@ -65,7 +69,9 @@ interpretation.
rnflags\optional{, cachesize\optional{, psize\optional{, lorder\optional{, rnflags\optional{, cachesize\optional{, psize\optional{, lorder\optional{,
reclen\optional{, bval\optional{, bfname}}}}}}}}}} reclen\optional{, bval\optional{, bfname}}}}}}}}}}
Open a DB record format file named \var{filename}. The optional Open a DB record format file named \var{filename}. Files never intended
to be preserved on disk may be created by passing \code{None} as the
\var{filename}. The optional
\var{flag} identifies the mode used to open the file. It may be \var{flag} identifies the mode used to open the file. It may be
\character{r} (read only), \character{w} (read-write), \character{r} (read only), \character{w} (read-write),
\character{c} (read-write - create if necessary) or \character{c} (read-write - create if necessary) or
......
...@@ -2,19 +2,21 @@ ...@@ -2,19 +2,21 @@
"""Test script for the bsddb C module """Test script for the bsddb C module
Roger E. Masse Roger E. Masse
""" """
import os import os
import bsddb import bsddb
import dbhash # Just so we know it's imported import dbhash # Just so we know it's imported
import tempfile import tempfile
from test_support import verbose, verify from test_support import verbose, verify
def test(openmethod, what): def test(openmethod, what, ondisk=1):
if verbose: if verbose:
print '\nTesting: ', what print '\nTesting: ', what, (ondisk and "on disk" or "in memory")
fname = tempfile.mktemp() if ondisk:
fname = tempfile.mktemp()
else:
fname = None
f = openmethod(fname, 'c') f = openmethod(fname, 'c')
verify(f.keys() == []) verify(f.keys() == [])
if verbose: if verbose:
...@@ -47,30 +49,35 @@ def test(openmethod, what): ...@@ -47,30 +49,35 @@ def test(openmethod, what):
f.sync() f.sync()
f.close() f.close()
if verbose: if ondisk:
print 'modification...' # if we're using an in-memory only db, we can't reopen it
f = openmethod(fname, 'w') # so finish here.
f['d'] = 'discovered' if verbose:
print 'modification...'
f = openmethod(fname, 'w')
f['d'] = 'discovered'
if verbose:
print 'access...'
for key in f.keys():
word = f[key]
if verbose: if verbose:
print word print 'access...'
for key in f.keys():
word = f[key]
if verbose:
print word
f.close() f.close()
try: try:
os.remove(fname) os.remove(fname)
except os.error: except os.error:
pass pass
types = [(bsddb.btopen, 'BTree'), types = [(bsddb.btopen, 'BTree'),
(bsddb.hashopen, 'Hash Table'), (bsddb.hashopen, 'Hash Table'),
(bsddb.btopen, 'BTree', 0),
(bsddb.hashopen, 'Hash Table', 0),
# (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85 # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
# appears broken... at least on # appears broken... at least on
# Solaris Intel - rmasse 1/97 # Solaris Intel - rmasse 1/97
] ]
for type in types: for type in types:
test(type[0], type[1]) test(*type)
...@@ -64,6 +64,10 @@ Core and builtins ...@@ -64,6 +64,10 @@ Core and builtins
Extension modules Extension modules
- The bsddb.*open functions can now take 'None' as a filename.
This will create a temporary in-memory bsddb that won't be
written to disk.
- posix.mknod was added. - posix.mknod was added.
- The locale module now exposes the C library's gettext interface. - The locale module now exposes the C library's gettext interface.
......
...@@ -687,7 +687,7 @@ bsdhashopen(PyObject *self, PyObject *args) ...@@ -687,7 +687,7 @@ bsdhashopen(PyObject *self, PyObject *args)
int hash = 0; /* XXX currently ignored */ int hash = 0; /* XXX currently ignored */
int lorder = 0; int lorder = 0;
if (!PyArg_ParseTuple(args, "s|siiiiiii:hashopen", if (!PyArg_ParseTuple(args, "z|siiiiiii:hashopen",
&file, &flag, &mode, &file, &flag, &mode,
&bsize, &ffactor, &nelem, &cachesize, &bsize, &ffactor, &nelem, &cachesize,
&hash, &lorder)) &hash, &lorder))
...@@ -738,7 +738,7 @@ bsdbtopen(PyObject *self, PyObject *args) ...@@ -738,7 +738,7 @@ bsdbtopen(PyObject *self, PyObject *args)
unsigned int psize = 0; unsigned int psize = 0;
int lorder = 0; int lorder = 0;
if (!PyArg_ParseTuple(args, "s|siiiiiii:btopen", if (!PyArg_ParseTuple(args, "z|siiiiiii:btopen",
&file, &flag, &mode, &file, &flag, &mode,
&btflags, &cachesize, &maxkeypage, &minkeypage, &btflags, &cachesize, &maxkeypage, &minkeypage,
&psize, &lorder)) &psize, &lorder))
...@@ -791,7 +791,7 @@ bsdrnopen(PyObject *self, PyObject *args) ...@@ -791,7 +791,7 @@ bsdrnopen(PyObject *self, PyObject *args)
char *bval = ""; char *bval = "";
char *bfname = NULL; char *bfname = NULL;
if (!PyArg_ParseTuple(args, "s|siiiiiiss:rnopen", if (!PyArg_ParseTuple(args, "z|siiiiiiss:rnopen",
&file, &flag, &mode, &file, &flag, &mode,
&rnflags, &cachesize, &psize, &lorder, &rnflags, &cachesize, &psize, &lorder,
&reclen, &bval, &bfname)) &reclen, &bval, &bfname))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment