ffactor\optional{, nelem\optional{,
cachesize\optional{, hash\optional{,
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
\character{r} (read only), \character{w} (read-write),
\character{c} (read-write - create if necessary) or
mode\optional{, btflags\optional{, cachesize\optional{, maxkeypage\optional{,
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
\character{r} (read only), \character{w} (read-write),
\character{c} (read-write - create if necessary) or
rnflags\optional{, cachesize\optional{, psize\optional{, lorder\optional{,
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
\character{r} (read only), \character{w} (read-write),
\character{c} (read-write - create if necessary) or
"""Test script for the bsddb C module
Roger E. Masse
"""
-
import os
import bsddb
import dbhash # Just so we know it's imported
import tempfile
from test_support import verbose, verify
-def test(openmethod, what):
+def test(openmethod, what, ondisk=1):
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')
verify(f.keys() == [])
if verbose:
f.sync()
f.close()
- if verbose:
- print 'modification...'
- f = openmethod(fname, 'w')
- f['d'] = 'discovered'
+ if ondisk:
+ # if we're using an in-memory only db, we can't reopen it
+ # so finish here.
+ 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:
- print word
+ print 'access...'
+ for key in f.keys():
+ word = f[key]
+ if verbose:
+ print word
- f.close()
- try:
- os.remove(fname)
- except os.error:
- pass
+ f.close()
+ try:
+ os.remove(fname)
+ except os.error:
+ pass
types = [(bsddb.btopen, 'BTree'),
(bsddb.hashopen, 'Hash Table'),
+ (bsddb.btopen, 'BTree', 0),
+ (bsddb.hashopen, 'Hash Table', 0),
# (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
# appears broken... at least on
# Solaris Intel - rmasse 1/97
]
for type in types:
- test(type[0], type[1])
+ test(*type)
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.
- The locale module now exposes the C library's gettext interface.
int hash = 0; /* XXX currently ignored */
int lorder = 0;
- if (!PyArg_ParseTuple(args, "s|siiiiiii:hashopen",
+ if (!PyArg_ParseTuple(args, "z|siiiiiii:hashopen",
&file, &flag, &mode,
&bsize, &ffactor, &nelem, &cachesize,
&hash, &lorder))
unsigned int psize = 0;
int lorder = 0;
- if (!PyArg_ParseTuple(args, "s|siiiiiii:btopen",
+ if (!PyArg_ParseTuple(args, "z|siiiiiii:btopen",
&file, &flag, &mode,
&btflags, &cachesize, &maxkeypage, &minkeypage,
&psize, &lorder))
char *bval = "";
char *bfname = NULL;
- if (!PyArg_ParseTuple(args, "s|siiiiiiss:rnopen",
+ if (!PyArg_ParseTuple(args, "z|siiiiiiss:rnopen",
&file, &flag, &mode,
&rnflags, &cachesize, &psize, &lorder,
&reclen, &bval, &bfname))