Commit 7775a1f3 authored by Georg Brandl's avatar Georg Brandl

Create the dbm package from PEP 3108. #2881.

parent 6487a3aa
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
class Dbm: class Dbm:
def __init__(self, filename, mode, perm): def __init__(self, filename, mode, perm):
import dbm import dbm.ndbm
self.db = dbm.open(filename, mode, perm) self.db = dbm.ndbm.open(filename, mode, perm)
def __repr__(self): def __repr__(self):
s = '' s = ''
......
...@@ -316,7 +316,7 @@ For example, if you need to link against libraries known to be in the standard ...@@ -316,7 +316,7 @@ For example, if you need to link against libraries known to be in the standard
library search path on target systems :: library search path on target systems ::
Extension(..., Extension(...,
libraries=['gdbm', 'readline']) libraries=['_gdbm', 'readline'])
If you need to link with libraries in a non-standard location, you'll have to If you need to link with libraries in a non-standard location, you'll have to
include the location in ``library_dirs``:: include the location in ``library_dirs``::
......
:mod:`anydbm` --- Generic access to DBM-style databases
=======================================================
.. module:: anydbm
:synopsis: Generic interface to DBM-style database modules.
.. index::
module: dbhash
module: bsddb
module: gdbm
module: dbm
module: dumbdbm
:mod:`anydbm` is a generic interface to variants of the DBM database ---
:mod:`dbhash` (requires :mod:`bsddb`), :mod:`gdbm`, or :mod:`dbm`. If none of
these modules is installed, the slow-but-simple implementation in module
:mod:`dumbdbm` will be used.
.. function:: open(filename[, flag[, mode]])
Open the database file *filename* and return a corresponding object.
If the database file already exists, the :mod:`whichdb` module is used to
determine its type and the appropriate module is used; if it does not exist, the
first module listed above that can be imported is used.
The optional *flag* argument can be ``'r'`` to open an existing database for
reading only, ``'w'`` to open an existing database for reading and writing,
``'c'`` to create the database if it doesn't exist, or ``'n'``, which will
always create a new empty database. If not specified, the default value is
``'r'``.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0666`` (and will be modified
by the prevailing umask).
.. exception:: error
A tuple containing the exceptions that can be raised by each of the supported
modules, with a unique exception also named :exc:`anydbm.error` as the first
item --- the latter is used when :exc:`anydbm.error` is raised.
The object returned by :func:`open` supports most of the same functionality as
dictionaries; keys and their corresponding values can be stored, retrieved, and
deleted, and the :meth:`has_key` and :meth:`keys` methods are available. Keys
and values must always be strings.
The following example records some hostnames and a corresponding title, and
then prints out the contents of the database::
import anydbm
# Open database, creating it if necessary.
db = anydbm.open('cache', 'c')
# Record some values
db['www.python.org'] = 'Python Website'
db['www.cnn.com'] = 'Cable News Network'
# Loop through contents. Other dictionary methods
# such as .keys(), .values() also work.
for k, v in db.iteritems():
print(k, '\t', v)
# Storing a non-string key or value will raise an exception (most
# likely a TypeError).
db['www.yahoo.com'] = 4
# Close when done.
db.close()
.. seealso::
Module :mod:`dbhash`
BSD ``db`` database interface.
Module :mod:`dbm`
Standard Unix database interface.
Module :mod:`dumbdbm`
Portable implementation of the ``dbm`` interface.
Module :mod:`gdbm`
GNU database interface, based on the ``dbm`` interface.
Module :mod:`shelve`
General object persistence built on top of the Python ``dbm`` interface.
Module :mod:`whichdb`
Utility module used to determine the type of an existing database.
...@@ -92,7 +92,7 @@ arguments should be used in most instances. ...@@ -92,7 +92,7 @@ arguments should be used in most instances.
.. seealso:: .. seealso::
Module :mod:`dbhash` Module :mod:`dbm.bsd`
DBM-style interface to the :mod:`bsddb` DBM-style interface to the :mod:`bsddb`
......
:mod:`dbhash` --- DBM-style interface to the BSD database library
=================================================================
.. module:: dbhash
:synopsis: DBM-style interface to the BSD database library.
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
.. index:: module: bsddb
The :mod:`dbhash` module provides a function to open databases using the BSD
``db`` library. This module mirrors the interface of the other Python database
modules that provide access to DBM-style databases. The :mod:`bsddb` module is
required to use :mod:`dbhash`.
This module provides an exception and a function:
.. exception:: error
Exception raised on database errors other than :exc:`KeyError`. It is a synonym
for :exc:`bsddb.error`.
.. function:: open(path[, flag[, mode]])
Open a ``db`` database and return the database object. The *path* argument is
the name of the database file.
The *flag* argument can be:
+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
For platforms on which the BSD ``db`` library supports locking, an ``'l'``
can be appended to indicate that locking should be used.
The optional *mode* parameter is used to indicate the Unix permission bits that
should be set if a new database must be created; this will be masked by the
current umask value for the process.
.. seealso::
Module :mod:`anydbm`
Generic interface to ``dbm``\ -style databases.
Module :mod:`bsddb`
Lower-level interface to the BSD ``db`` library.
Module :mod:`whichdb`
Utility module used to determine the type of an existing database.
.. _dbhash-objects:
Database Objects
----------------
The database objects returned by :func:`open` provide the methods common to all
the DBM-style databases and mapping objects. The following methods are
available in addition to the standard methods.
.. method:: dbhash.first()
It's possible to loop over every key/value pair in the database using this
method and the :meth:`next` method. The traversal is ordered by the databases
internal hash values, and won't be sorted by the key values. This method
returns the starting key.
.. method:: dbhash.last()
Return the last key/value pair in a database traversal. This may be used to
begin a reverse-order traversal; see :meth:`previous`.
.. method:: dbhash.next()
Returns the key next key/value pair in a database traversal. The following code
prints every key in the database ``db``, without having to create a list in
memory that contains them all::
print(db.first())
for i in range(1, len(db)):
print(db.next())
.. method:: dbhash.previous()
Returns the previous key/value pair in a forward-traversal of the database. In
conjunction with :meth:`last`, this may be used to implement a reverse-order
traversal.
.. method:: dbhash.sync()
This method forces any unwritten data to be written to the disk.
:mod:`dbm` --- Interfaces to Unix "databases"
:mod:`dbm` --- Simple "database" interface =============================================
==========================================
.. module:: dbm .. module:: dbm
:synopsis: Interfaces to various Unix "database" formats.
:mod:`dbm` is a generic interface to variants of the DBM database ---
:mod:`dbm.bsd` (requires :mod:`bsddb`), :mod:`dbm.gnu`, or :mod:`dbm.ndbm`. If
none of these modules is installed, the slow-but-simple implementation in module
:mod:`dbm.dumb` will be used.
.. exception:: error
A tuple containing the exceptions that can be raised by each of the supported
modules, with a unique exception also named :exc:`dbm.error` as the first
item --- the latter is used when :exc:`dbm.error` is raised.
.. function:: whichdb(filename)
This functionattempts to guess which of the several simple database modules
available --- :mod:`dbm.bsd`, :mod:`dbm.gnu`, :mod:`dbm.ndbm` or
:mod:`dbm.dumb` --- should be used to open a given file.
Returns one of the following values: ``None`` if the file can't be opened
because it's unreadable or doesn't exist; the empty string (``''``) if the
file's format can't be guessed; or a string containing the required module
name, such as ``'dbm.ndbm'`` or ``'dbm.gnu'``.
.. function:: open(filename[, flag[, mode]])
Open the database file *filename* and return a corresponding object.
If the database file already exists, the :func:`whichdb` function is used to
determine its type and the appropriate module is used; if it does not exist,
the first module listed above that can be imported is used.
The optional *flag* argument can be ``'r'`` to open an existing database for
reading only, ``'w'`` to open an existing database for reading and writing,
``'c'`` to create the database if it doesn't exist, or ``'n'``, which will
always create a new empty database. If not specified, the default value is
``'r'``.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0o666`` (and will be
modified by the prevailing umask).
The object returned by :func:`open` supports most of the same functionality as
dictionaries; keys and their corresponding values can be stored, retrieved, and
deleted, and the :keyword:`in` operator and the :meth:`keys` method are
available. Keys and values must always be strings.
The following example records some hostnames and a corresponding title, and
then prints out the contents of the database::
import dbm
# Open database, creating it if necessary.
db = dbm.open('cache', 'c')
# Record some values
db['www.python.org'] = 'Python Website'
db['www.cnn.com'] = 'Cable News Network'
# Loop through contents. Other dictionary methods
# such as .keys(), .values() also work.
for k, v in db.iteritems():
print(k, '\t', v)
# Storing a non-string key or value will raise an exception (most
# likely a TypeError).
db['www.yahoo.com'] = 4
# Close when done.
db.close()
.. seealso::
Module :mod:`shelve`
Persistence module which stores non-string data.
The individual submodules are described in the following sections.
:mod:`dbm.bsd` --- DBM-style interface to the BSD database library
------------------------------------------------------------------
.. module:: dbm.bsd
:synopsis: DBM-style interface to the BSD database library.
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
.. index:: module: bsddb
The :mod:`dbm.bsd` module provides a function to open databases using the BSD
``db`` library. This module mirrors the interface of the other Python database
modules that provide access to DBM-style databases. The :mod:`bsddb` module is
required to use :mod:`dbm.bsd`.
.. exception:: error
Exception raised on database errors other than :exc:`KeyError`. It is a synonym
for :exc:`bsddb.error`.
.. function:: open(path[, flag[, mode]])
Open a ``db`` database and return the database object. The *path* argument is
the name of the database file.
The *flag* argument can be:
+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
For platforms on which the BSD ``db`` library supports locking, an ``'l'``
can be appended to indicate that locking should be used.
The optional *mode* parameter is used to indicate the Unix permission bits that
should be set if a new database must be created; this will be masked by the
current umask value for the process.
The database objects returned by :func:`open` provide the methods common to all
the DBM-style databases and mapping objects. The following methods are
available in addition to the standard methods:
.. method:: dbhash.first()
It's possible to loop over every key/value pair in the database using this
method and the :meth:`next` method. The traversal is ordered by the databases
internal hash values, and won't be sorted by the key values. This method
returns the starting key.
.. method:: dbhash.last()
Return the last key/value pair in a database traversal. This may be used to
begin a reverse-order traversal; see :meth:`previous`.
.. method:: dbhash.next()
Returns the key next key/value pair in a database traversal. The following code
prints every key in the database ``db``, without having to create a list in
memory that contains them all::
print(db.first())
for i in range(1, len(db)):
print(db.next())
.. method:: dbhash.previous()
Returns the previous key/value pair in a forward-traversal of the database. In
conjunction with :meth:`last`, this may be used to implement a reverse-order
traversal.
.. method:: dbhash.sync()
This method forces any unwritten data to be written to the disk.
:mod:`dbm.gnu` --- GNU's reinterpretation of dbm
------------------------------------------------
.. module:: dbm.gnu
:platform: Unix
:synopsis: GNU's reinterpretation of dbm.
This module is quite similar to the :mod:`dbm` module, but uses the GNU library
``gdbm`` instead to provide some additional functionality. Please note that the
file formats created by ``gdbm`` and ``dbm`` are incompatible.
The :mod:`dbm.gnu` module provides an interface to the GNU DBM library.
``gdbm`` objects behave like mappings (dictionaries), except that keys and
values are always strings. Printing a :mod:`dbm.gnu` object doesn't print the
keys and values, and the :meth:`items` and :meth:`values` methods are not
supported.
.. exception:: error
Raised on ``gdbm``\ -specific errors, such as I/O errors. :exc:`KeyError` is
raised for general mapping errors like specifying an incorrect key.
.. function:: open(filename, [flag, [mode]])
Open a ``gdbm`` database and return a :class:`gdbm` object. The *filename*
argument is the name of the database file.
The optional *flag* argument can be:
+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
The following additional characters may be appended to the flag to control
how the database is opened:
+---------+--------------------------------------------+
| Value | Meaning |
+=========+============================================+
| ``'f'`` | Open the database in fast mode. Writes |
| | to the database will not be synchronized. |
+---------+--------------------------------------------+
| ``'s'`` | Synchronized mode. This will cause changes |
| | to the database to be immediately written |
| | to the file. |
+---------+--------------------------------------------+
| ``'u'`` | Do not lock database. |
+---------+--------------------------------------------+
Not all flags are valid for all versions of ``gdbm``. The module constant
:const:`open_flags` is a string of supported flag characters. The exception
:exc:`error` is raised if an invalid flag is specified.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0666``.
In addition to the dictionary-like methods, ``gdbm`` objects have the
following methods:
.. method:: gdbm.firstkey()
It's possible to loop over every key in the database using this method and the
:meth:`nextkey` method. The traversal is ordered by ``gdbm``'s internal
hash values, and won't be sorted by the key values. This method returns
the starting key.
.. method:: gdbm.nextkey(key)
Returns the key that follows *key* in the traversal. The following code prints
every key in the database ``db``, without having to create a list in memory that
contains them all::
k = db.firstkey()
while k != None:
print(k)
k = db.nextkey(k)
.. method:: gdbm.reorganize()
If you have carried out a lot of deletions and would like to shrink the space
used by the ``gdbm`` file, this routine will reorganize the database. ``gdbm``
will not shorten the length of a database file except by using this
reorganization; otherwise, deleted file space will be kept and reused as new
(key, value) pairs are added.
.. method:: gdbm.sync()
When the database has been opened in fast mode, this method forces any
unwritten data to be written to the disk.
:mod:`dbm.ndbm` --- Interface based on ndbm
-------------------------------------------
.. module:: dbm.ndbm
:platform: Unix :platform: Unix
:synopsis: The standard "database" interface, based on ndbm. :synopsis: The standard "database" interface, based on ndbm.
The :mod:`dbm` module provides an interface to the Unix "(n)dbm" library. Dbm The :mod:`dbm.ndbm` module provides an interface to the Unix "(n)dbm" library.
objects behave like mappings (dictionaries), except that keys and values are Dbm objects behave like mappings (dictionaries), except that keys and values are
always strings. Printing a dbm object doesn't print the keys and values, and the always strings. Printing a dbm object doesn't print the keys and values, and the
:meth:`items` and :meth:`values` methods are not supported. :meth:`items` and :meth:`values` methods are not supported.
...@@ -17,13 +297,10 @@ compatibility interface, or the GNU GDBM compatibility interface. On Unix, the ...@@ -17,13 +297,10 @@ compatibility interface, or the GNU GDBM compatibility interface. On Unix, the
:program:`configure` script will attempt to locate the appropriate header file :program:`configure` script will attempt to locate the appropriate header file
to simplify building this module. to simplify building this module.
The module defines the following:
.. exception:: error .. exception:: error
Raised on dbm-specific errors, such as I/O errors. :exc:`KeyError` is raised for Raised on dbm-specific errors, such as I/O errors. :exc:`KeyError` is raised
general mapping errors like specifying an incorrect key. for general mapping errors like specifying an incorrect key.
.. data:: library .. data:: library
...@@ -61,14 +338,54 @@ The module defines the following: ...@@ -61,14 +338,54 @@ The module defines the following:
modified by the prevailing umask). modified by the prevailing umask).
.. seealso::
Module :mod:`anydbm` :mod:`dbm.dumb` --- Portable DBM implementation
Generic interface to ``dbm``\ -style databases. -----------------------------------------------
.. module:: dbm.dumb
:synopsis: Portable implementation of the simple DBM interface.
.. index:: single: databases
.. note::
The :mod:`dbm.dumb` module is intended as a last resort fallback for the
:mod:`dbm` module when no more robust module is available. The :mod:`dbm.dumb`
module is not written for speed and is not nearly as heavily used as the other
database modules.
The :mod:`dbm.dumb` module provides a persistent dictionary-like interface which
is written entirely in Python. Unlike other modules such as :mod:`gdbm` and
:mod:`bsddb`, no external library is required. As with other persistent
mappings, the keys and values must always be strings.
The module defines the following:
.. exception:: error
Raised on dbm.dumb-specific errors, such as I/O errors. :exc:`KeyError` is
raised for general mapping errors like specifying an incorrect key.
.. function:: open(filename[, flag[, mode]])
Open a dumbdbm database and return a dumbdbm object. The *filename* argument is
the basename of the database file (without any specific extensions). When a
dumbdbm database is created, files with :file:`.dat` and :file:`.dir` extensions
are created.
The optional *flag* argument is currently ignored; the database is always opened
for update, and will be created if it does not exist.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0o666`` (and will be modified
by the prevailing umask).
Module :mod:`gdbm` In addition to the methods provided by the :class:`collections.MutableMapping` class,
Similar interface to the GNU GDBM library. :class:`dumbdbm` objects provide the following method:
Module :mod:`whichdb` .. method:: dumbdbm.sync()
Utility module used to determine the type of an existing database.
Synchronize the on-disk directory and data files. This method is called
by the :meth:`Shelve.sync` method.
:mod:`dumbdbm` --- Portable DBM implementation
==============================================
.. module:: dumbdbm
:synopsis: Portable implementation of the simple DBM interface.
.. index:: single: databases
.. note::
The :mod:`dumbdbm` module is intended as a last resort fallback for the
:mod:`anydbm` module when no more robust module is available. The :mod:`dumbdbm`
module is not written for speed and is not nearly as heavily used as the other
database modules.
The :mod:`dumbdbm` module provides a persistent dictionary-like interface which
is written entirely in Python. Unlike other modules such as :mod:`gdbm` and
:mod:`bsddb`, no external library is required. As with other persistent
mappings, the keys and values must always be strings.
The module defines the following:
.. exception:: error
Raised on dumbdbm-specific errors, such as I/O errors. :exc:`KeyError` is
raised for general mapping errors like specifying an incorrect key.
.. function:: open(filename[, flag[, mode]])
Open a dumbdbm database and return a dumbdbm object. The *filename* argument is
the basename of the database file (without any specific extensions). When a
dumbdbm database is created, files with :file:`.dat` and :file:`.dir` extensions
are created.
The optional *flag* argument is currently ignored; the database is always opened
for update, and will be created if it does not exist.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0666`` (and will be modified
by the prevailing umask).
.. seealso::
Module :mod:`anydbm`
Generic interface to ``dbm``\ -style databases.
Module :mod:`dbm`
Similar interface to the DBM/NDBM library.
Module :mod:`gdbm`
Similar interface to the GNU GDBM library.
Module :mod:`shelve`
Persistence module which stores non-string data.
Module :mod:`whichdb`
Utility module used to determine the type of an existing database.
.. _dumbdbm-objects:
Dumbdbm Objects
---------------
In addition to the methods provided by the :class:`UserDict.DictMixin` class,
:class:`dumbdbm` objects provide the following methods.
.. method:: dumbdbm.sync()
Synchronize the on-disk directory and data files. This method is called by the
:meth:`sync` method of :class:`Shelve` objects.
:mod:`gdbm` --- GNU's reinterpretation of dbm
=============================================
.. module:: gdbm
:platform: Unix
:synopsis: GNU's reinterpretation of dbm.
.. index:: module: dbm
This module is quite similar to the :mod:`dbm` module, but uses ``gdbm`` instead
to provide some additional functionality. Please note that the file formats
created by ``gdbm`` and ``dbm`` are incompatible.
The :mod:`gdbm` module provides an interface to the GNU DBM library. ``gdbm``
objects behave like mappings (dictionaries), except that keys and values are
always strings. Printing a ``gdbm`` object doesn't print the keys and values,
and the :meth:`items` and :meth:`values` methods are not supported.
The module defines the following constant and functions:
.. exception:: error
Raised on ``gdbm``\ -specific errors, such as I/O errors. :exc:`KeyError` is
raised for general mapping errors like specifying an incorrect key.
.. function:: open(filename, [flag, [mode]])
Open a ``gdbm`` database and return a ``gdbm`` object. The *filename* argument
is the name of the database file.
The optional *flag* argument can be:
+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
The following additional characters may be appended to the flag to control
how the database is opened:
+---------+--------------------------------------------+
| Value | Meaning |
+=========+============================================+
| ``'f'`` | Open the database in fast mode. Writes |
| | to the database will not be synchronized. |
+---------+--------------------------------------------+
| ``'s'`` | Synchronized mode. This will cause changes |
| | to the database to be immediately written |
| | to the file. |
+---------+--------------------------------------------+
| ``'u'`` | Do not lock database. |
+---------+--------------------------------------------+
Not all flags are valid for all versions of ``gdbm``. The module constant
:const:`open_flags` is a string of supported flag characters. The exception
:exc:`error` is raised if an invalid flag is specified.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0666``.
In addition to the dictionary-like methods, ``gdbm`` objects have the following
methods:
.. function:: firstkey()
It's possible to loop over every key in the database using this method and the
:meth:`nextkey` method. The traversal is ordered by ``gdbm``'s internal hash
values, and won't be sorted by the key values. This method returns the starting
key.
.. function:: nextkey(key)
Returns the key that follows *key* in the traversal. The following code prints
every key in the database ``db``, without having to create a list in memory that
contains them all::
k = db.firstkey()
while k != None:
print(k)
k = db.nextkey(k)
.. function:: reorganize()
If you have carried out a lot of deletions and would like to shrink the space
used by the ``gdbm`` file, this routine will reorganize the database. ``gdbm``
will not shorten the length of a database file except by using this
reorganization; otherwise, deleted file space will be kept and reused as new
(key, value) pairs are added.
.. function:: sync()
When the database has been opened in fast mode, this method forces any
unwritten data to be written to the disk.
.. seealso::
Module :mod:`anydbm`
Generic interface to ``dbm``\ -style databases.
Module :mod:`whichdb`
Utility module used to determine the type of an existing database.
...@@ -22,11 +22,5 @@ The list of modules described in this chapter is: ...@@ -22,11 +22,5 @@ The list of modules described in this chapter is:
copyreg.rst copyreg.rst
shelve.rst shelve.rst
marshal.rst marshal.rst
anydbm.rst
whichdb.rst
dbm.rst dbm.rst
gdbm.rst
dbhash.rst
bsddb.rst
dumbdbm.rst
sqlite3.rst sqlite3.rst
...@@ -21,7 +21,7 @@ lots of shared sub-objects. The keys are ordinary strings. ...@@ -21,7 +21,7 @@ lots of shared sub-objects. The keys are ordinary strings.
the underlying database. As a side-effect, an extension may be added to the the underlying database. As a side-effect, an extension may be added to the
filename and more than one file may be created. By default, the underlying filename and more than one file may be created. By default, the underlying
database file is opened for reading and writing. The optional *flag* parameter database file is opened for reading and writing. The optional *flag* parameter
has the same interpretation as the *flag* parameter of :func:`anydbm.open`. has the same interpretation as the *flag* parameter of :func:`dbm.open`.
By default, version 0 pickles are used to serialize values. The version of the By default, version 0 pickles are used to serialize values. The version of the
pickle protocol can be specified with the *protocol* parameter. pickle protocol can be specified with the *protocol* parameter.
...@@ -53,12 +53,12 @@ Restrictions ...@@ -53,12 +53,12 @@ Restrictions
------------ ------------
.. index:: .. index::
module: dbm module: dbm.ndbm
module: gdbm module: dbm.gnu
module: bsddb module: bsddb
* The choice of which database package will be used (such as :mod:`dbm`, * The choice of which database package will be used (such as :mod:`dbm.ndbm`,
:mod:`gdbm` or :mod:`bsddb`) depends on which interface is available. Therefore :mod:`dbm.gnu` or :mod:`bsddb`) depends on which interface is available. Therefore
it is not safe to open the database directly using :mod:`dbm`. The database is it is not safe to open the database directly using :mod:`dbm`. The database is
also (unfortunately) subject to the limitations of :mod:`dbm`, if it is used --- also (unfortunately) subject to the limitations of :mod:`dbm`, if it is used ---
this means that (the pickled representation of) the objects stored in the this means that (the pickled representation of) the objects stored in the
...@@ -107,7 +107,7 @@ Restrictions ...@@ -107,7 +107,7 @@ Restrictions
.. class:: DbfilenameShelf(filename[, flag='c'[, protocol=None[, writeback=False]]]) .. class:: DbfilenameShelf(filename[, flag='c'[, protocol=None[, writeback=False]]])
A subclass of :class:`Shelf` which accepts a *filename* instead of a dict-like A subclass of :class:`Shelf` which accepts a *filename* instead of a dict-like
object. The underlying file will be opened using :func:`anydbm.open`. By object. The underlying file will be opened using :func:`dbm.open`. By
default, the file will be created and opened for both read and write. The default, the file will be created and opened for both read and write. The
optional *flag* parameter has the same interpretation as for the :func:`open` optional *flag* parameter has the same interpretation as for the :func:`open`
function. The optional *protocol* and *writeback* parameters have the same function. The optional *protocol* and *writeback* parameters have the same
...@@ -152,25 +152,12 @@ object):: ...@@ -152,25 +152,12 @@ object)::
.. seealso:: .. seealso::
Module :mod:`anydbm` Module :mod:`dbm`
Generic interface to ``dbm``\ -style databases. Generic interface to ``dbm``-style databases.
Module :mod:`bsddb` Module :mod:`bsddb`
BSD ``db`` database interface. BSD ``db`` database interface.
Module :mod:`dbhash`
Thin layer around the :mod:`bsddb` which provides an :func:`open` function like
the other database modules.
Module :mod:`dbm`
Standard Unix database interface.
Module :mod:`dumbdbm`
Portable implementation of the ``dbm`` interface.
Module :mod:`gdbm`
GNU database interface, based on the ``dbm`` interface.
Module :mod:`pickle` Module :mod:`pickle`
Object serialization used by :mod:`shelve`. Object serialization used by :mod:`shelve`.
......
:mod:`whichdb` --- Guess which DBM module created a database
============================================================
.. module:: whichdb
:synopsis: Guess which DBM-style module created a given database.
The single function in this module attempts to guess which of the several simple
database modules available--\ :mod:`dbm`, :mod:`gdbm`, or :mod:`dbhash`\
--should be used to open a given file.
.. function:: whichdb(filename)
Returns one of the following values: ``None`` if the file can't be opened
because it's unreadable or doesn't exist; the empty string (``''``) if the
file's format can't be guessed; or a string containing the required module name,
such as ``'dbm'`` or ``'gdbm'``.
...@@ -394,12 +394,12 @@ Mappings ...@@ -394,12 +394,12 @@ Mappings
section :ref:`dict`). section :ref:`dict`).
.. index:: .. index::
module: dbm module: dbm.ndbm
module: gdbm module: dbm.gnu
module: bsddb module: bsddb
The extension modules :mod:`dbm`, :mod:`gdbm`, and :mod:`bsddb` provide The extension modules :mod:`dbm.ndbm`, :mod:`dbm.gnu`, and :mod:`bsddb`
additional examples of mapping types. provide additional examples of mapping types.
Callable types Callable types
.. index:: .. index::
......
"""Generic interface to all dbm clones.
Instead of
import dbm
d = dbm.open(file, 'w', 0o666)
use
import anydbm
d = anydbm.open(file, 'w')
The returned object is a dbhash, gdbm, dbm or dumbdbm object,
dependent on the type of database being opened (determined by whichdb
module) in the case of an existing dbm. If the dbm does not exist and
the create or new flag ('c' or 'n') was specified, the dbm type will
be determined by the availability of the modules (tested in the above
order).
It has the following interface (key and data are strings):
d[key] = data # store data at key (may override data at
# existing key)
data = d[key] # retrieve data at key (raise KeyError if no
# such key)
del d[key] # delete data stored at key (raises KeyError
# if no such key)
flag = key in d # true if the key exists
list = d.keys() # return a list of all existing keys (slow!)
Future versions may change the order in which implementations are
tested for existence, add interfaces to other dbm-like
implementations.
The open function has an optional second argument. This can be 'r',
for read-only access, 'w', for read-write access of an existing
database, 'c' for read-write access to a new or existing database, and
'n' for read-write access to a new database. The default is 'r'.
Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
only if it doesn't exist; and 'n' always creates a new database.
"""
class error(Exception):
pass
_names = ['dbhash', 'gdbm', 'dbm', 'dumbdbm']
_errors = [error]
_defaultmod = None
for _name in _names:
try:
_mod = __import__(_name)
except ImportError:
continue
if not _defaultmod:
_defaultmod = _mod
_errors.append(_mod.error)
if not _defaultmod:
raise ImportError("no dbm clone found; tried %s" % _names)
error = tuple(_errors)
def open(file, flag = 'r', mode = 0o666):
# guess the type of an existing database
from whichdb import whichdb
result=whichdb(file)
if result is None:
# db doesn't exist
if 'c' in flag or 'n' in flag:
# file doesn't exist and the new
# flag was used so use default type
mod = _defaultmod
else:
raise error("need 'c' or 'n' flag to open new db")
elif result == "":
# db type cannot be determined
raise error("db type could not be determined")
else:
mod = __import__(result)
return mod.open(file, flag, mode)
# !/usr/bin/env python """Generic interface to all dbm clones.
"""Guess which db package to use to open a db file."""
Use
import dbm
d = dbm.open(file, 'w', 0o666)
The returned object is a dbm.bsd, dbm.gnu, dbm.ndbm or dbm.dumb
object, dependent on the type of database being opened (determined by
the whichdb function) in the case of an existing dbm. If the dbm does
not exist and the create or new flag ('c' or 'n') was specified, the
dbm type will be determined by the availability of the modules (tested
in the above order).
It has the following interface (key and data are strings):
d[key] = data # store data at key (may override data at
# existing key)
data = d[key] # retrieve data at key (raise KeyError if no
# such key)
del d[key] # delete data stored at key (raises KeyError
# if no such key)
flag = key in d # true if the key exists
list = d.keys() # return a list of all existing keys (slow!)
Future versions may change the order in which implementations are
tested for existence, add interfaces to other dbm-like
implementations.
The open function has an optional second argument. This can be 'r',
for read-only access, 'w', for read-write access of an existing
database, 'c' for read-write access to a new or existing database, and
'n' for read-write access to a new database. The default is 'r'.
Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
only if it doesn't exist; and 'n' always creates a new database.
"""
__all__ = ['open', 'whichdb', 'error', 'errors']
import io import io
import os import os
import struct import struct
import sys import sys
class error(Exception):
pass
_names = ['dbm.bsd', 'dbm.gnu', 'dbm.ndbm', 'dbm.dumb']
_errors = [error]
_defaultmod = None
_modules = {}
for _name in _names:
try:
_mod = __import__(_name, fromlist=['open'])
except ImportError:
continue
if not _defaultmod:
_defaultmod = _mod
_modules[_name] = _mod
_errors.append(_mod.error)
if not _defaultmod:
raise ImportError("no dbm clone found; tried %s" % _names)
error = tuple(_errors)
def open(file, flag = 'r', mode = 0o666):
# guess the type of an existing database
result = whichdb(file)
if result is None:
# db doesn't exist
if 'c' in flag or 'n' in flag:
# file doesn't exist and the new flag was used so use default type
mod = _defaultmod
else:
raise error("need 'c' or 'n' flag to open new db")
elif result == "":
# db type cannot be determined
raise error("db type could not be determined")
else:
mod = _modules[result]
return mod.open(file, flag, mode)
try: try:
import dbm from dbm import ndbm
_dbmerror = dbm.error _dbmerror = ndbm.error
except ImportError: except ImportError:
dbm = None ndbm = None
# just some sort of valid exception which might be raised in the # just some sort of valid exception which might be raised in the ndbm test
# dbm test
_dbmerror = IOError _dbmerror = IOError
def whichdb(filename): def whichdb(filename):
...@@ -22,34 +101,34 @@ def whichdb(filename): ...@@ -22,34 +101,34 @@ def whichdb(filename):
- None if the database file can't be read; - None if the database file can't be read;
- empty string if the file can be read but can't be recognized - empty string if the file can be read but can't be recognized
- the module name (e.g. "dbm" or "gdbm") if recognized. - the name of the dbm submodule (e.g. "ndbm" or "gnu") if recognized.
Importing the given module may still fail, and opening the Importing the given module may still fail, and opening the
database using that module may still fail. database using that module may still fail.
""" """
# Check for dbm first -- this has a .pag and a .dir file # Check for ndbm first -- this has a .pag and a .dir file
try: try:
f = io.open(filename + ".pag", "rb") f = io.open(filename + ".pag", "rb")
f.close() f.close()
# dbm linked with gdbm on OS/2 doesn't have .dir file # dbm linked with gdbm on OS/2 doesn't have .dir file
if not (dbm.library == "GNU gdbm" and sys.platform == "os2emx"): if not (ndbm.library == "GNU gdbm" and sys.platform == "os2emx"):
f = io.open(filename + ".dir", "rb") f = io.open(filename + ".dir", "rb")
f.close() f.close()
return "dbm" return "dbm.ndbm"
except IOError: except IOError:
# some dbm emulations based on Berkeley DB generate a .db file # some dbm emulations based on Berkeley DB generate a .db file
# some do not, but they should be caught by the dbhash checks # some do not, but they should be caught by the bsd checks
try: try:
f = io.open(filename + ".db", "rb") f = io.open(filename + ".db", "rb")
f.close() f.close()
# guarantee we can actually open the file using dbm # guarantee we can actually open the file using dbm
# kind of overkill, but since we are dealing with emulations # kind of overkill, but since we are dealing with emulations
# it seems like a prudent step # it seems like a prudent step
if dbm is not None: if ndbm is not None:
d = dbm.open(filename) d = ndbm.open(filename)
d.close() d.close()
return "dbm" return "dbm.ndbm"
except (IOError, _dbmerror): except (IOError, _dbmerror):
pass pass
...@@ -60,11 +139,11 @@ def whichdb(filename): ...@@ -60,11 +139,11 @@ def whichdb(filename):
size = os.stat(filename + ".dir").st_size size = os.stat(filename + ".dir").st_size
# dumbdbm files with no keys are empty # dumbdbm files with no keys are empty
if size == 0: if size == 0:
return "dumbdbm" return "dbm.dumb"
f = io.open(filename + ".dir", "rb") f = io.open(filename + ".dir", "rb")
try: try:
if f.read(1) in (b"'", b'"'): if f.read(1) in (b"'", b'"'):
return "dumbdbm" return "dbm.dumb"
finally: finally:
f.close() f.close()
except (OSError, IOError): except (OSError, IOError):
...@@ -93,11 +172,11 @@ def whichdb(filename): ...@@ -93,11 +172,11 @@ def whichdb(filename):
# Check for GNU dbm # Check for GNU dbm
if magic == 0x13579ace: if magic == 0x13579ace:
return "gdbm" return "dbm.gnu"
# Check for old Berkeley db hash file format v2 ## Check for old Berkeley db hash file format v2
if magic in (0x00061561, 0x61150600): #if magic in (0x00061561, 0x61150600):
return "bsddb185" # return "bsddb185" # not supported anymore
# Later versions of Berkeley db hash file have a 12-byte pad in # Later versions of Berkeley db hash file have a 12-byte pad in
# front of the file type # front of the file type
...@@ -108,11 +187,12 @@ def whichdb(filename): ...@@ -108,11 +187,12 @@ def whichdb(filename):
# Check for BSD hash # Check for BSD hash
if magic in (0x00061561, 0x61150600): if magic in (0x00061561, 0x61150600):
return "dbhash" return "dbm.bsd"
# Unknown # Unknown
return "" return ""
if __name__ == "__main__": if __name__ == "__main__":
for filename in sys.argv[1:]: for filename in sys.argv[1:]:
print(whichdb(filename) or "UNKNOWN", filename) print(whichdb(filename) or "UNKNOWN", filename)
"""Provide a (g)dbm-compatible interface to bsddb.hashopen.""" """Provide a (g)dbm-compatible interface to bsddb.hashopen."""
import sys import bsddb
try:
import bsddb
except ImportError:
# prevent a second import of this module from spuriously succeeding
del sys.modules[__name__]
raise
__all__ = ["error","open"] __all__ = ["error", "open"]
error = bsddb.error # Exported for anydbm error = bsddb.error
def open(file, flag = 'r', mode=0o666): def open(file, flag = 'r', mode=0o666):
return bsddb.hashopen(file, flag, mode) return bsddb.hashopen(file, flag, mode)
...@@ -25,9 +25,11 @@ import io as _io ...@@ -25,9 +25,11 @@ import io as _io
import os as _os import os as _os
import collections import collections
__all__ = ["error", "open"]
_BLOCKSIZE = 512 _BLOCKSIZE = 512
error = IOError # For anydbm error = IOError
class _Database(collections.MutableMapping): class _Database(collections.MutableMapping):
...@@ -231,7 +233,7 @@ def open(file, flag=None, mode=0o666): ...@@ -231,7 +233,7 @@ def open(file, flag=None, mode=0o666):
"""Open the database file, filename, and return corresponding object. """Open the database file, filename, and return corresponding object.
The flag argument, used to control how the database is opened in the The flag argument, used to control how the database is opened in the
other DBM implementations, is ignored in the dumbdbm module; the other DBM implementations, is ignored in the dbm.dumb module; the
database is always opened for update, and will be created if it does database is always opened for update, and will be created if it does
not exist. not exist.
......
"""Provide the _gdbm module as a dbm submodule."""
from _gdbm import *
"""Provide the _dbm module as a dbm submodule."""
from _dbm import *
...@@ -270,7 +270,7 @@ class OpenWrapper: ...@@ -270,7 +270,7 @@ class OpenWrapper:
"""Wrapper for builtins.open """Wrapper for builtins.open
Trick so that open won't become a bound method when stored Trick so that open won't become a bound method when stored
as a class variable (as dumbdbm does). as a class variable (as dbm.dumb does).
See initstdio() in Python/pythonrun.c. See initstdio() in Python/pythonrun.c.
""" """
......
...@@ -190,15 +190,15 @@ class BsdDbShelf(Shelf): ...@@ -190,15 +190,15 @@ class BsdDbShelf(Shelf):
class DbfilenameShelf(Shelf): class DbfilenameShelf(Shelf):
"""Shelf implementation using the "anydbm" generic dbm interface. """Shelf implementation using the "dbm" generic dbm interface.
This is initialized with the filename for the dbm database. This is initialized with the filename for the dbm database.
See the module's __doc__ string for an overview of the interface. See the module's __doc__ string for an overview of the interface.
""" """
def __init__(self, filename, flag='c', protocol=None, writeback=False): def __init__(self, filename, flag='c', protocol=None, writeback=False):
import anydbm import dbm
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback) Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
def open(filename, flag='c', protocol=None, writeback=False): def open(filename, flag='c', protocol=None, writeback=False):
...@@ -208,7 +208,7 @@ def open(filename, flag='c', protocol=None, writeback=False): ...@@ -208,7 +208,7 @@ def open(filename, flag='c', protocol=None, writeback=False):
database. As a side-effect, an extension may be added to the database. As a side-effect, an extension may be added to the
filename and more than one file may be created. The optional flag filename and more than one file may be created. The optional flag
parameter has the same interpretation as the flag parameter of parameter has the same interpretation as the flag parameter of
anydbm.open(). The optional protocol parameter specifies the dbm.open(). The optional protocol parameter specifies the
version of the pickle protocol (0, 1, or 2). version of the pickle protocol (0, 1, or 2).
See the module's __doc__ string for an overview of the interface. See the module's __doc__ string for an overview of the interface.
......
...@@ -57,7 +57,7 @@ class AllTest(unittest.TestCase): ...@@ -57,7 +57,7 @@ class AllTest(unittest.TestCase):
self.check_all("copy") self.check_all("copy")
self.check_all("copyreg") self.check_all("copyreg")
self.check_all("csv") self.check_all("csv")
self.check_all("dbhash") self.check_all("dbm.bsd")
self.check_all("decimal") self.check_all("decimal")
self.check_all("difflib") self.check_all("difflib")
self.check_all("dircache") self.check_all("dircache")
......
#! /usr/bin/env python #! /usr/bin/env python
"""Test script for the anydbm module """Test script for the dbm.open function based on testdumbdbm.py"""
based on testdumbdbm.py
"""
import os import os
import unittest import unittest
import anydbm import dbm
import glob import glob
from test import support import test.support
_fname = support.TESTFN
_all_modules = []
for _name in anydbm._names:
try:
_module = __import__(_name)
except ImportError:
continue
_all_modules.append(_module)
_fname = test.support.TESTFN
# #
# Iterates over every database module supported by anydbm # Iterates over every database module supported by dbm currently available,
# currently available, setting anydbm to use each in turn, # setting dbm to use each in turn, and yielding that module
# and yielding that module
# #
def dbm_iterator(): def dbm_iterator():
old_default = anydbm._defaultmod old_default = dbm._defaultmod
for module in _all_modules: for module in dbm._modules.values():
anydbm._defaultmod = module dbm._defaultmod = module
yield module yield module
anydbm._defaultmod = old_default dbm._defaultmod = old_default
# #
# Clean up all scratch databases we might have created # Clean up all scratch databases we might have created during testing
# during testing
# #
def delete_files(): def delete_files():
# we don't know the precise name the underlying database uses # we don't know the precise name the underlying database uses
# so we use glob to locate all names # so we use glob to locate all names
for f in glob.glob(_fname + "*"): for f in glob.glob(_fname + "*"):
try: test.support.unlink(f)
os.unlink(f)
except OSError:
pass
class AnyDBMTestCase(unittest.TestCase): class AnyDBMTestCase(unittest.TestCase):
_dict = {'0': b'', _dict = {'0': b'',
...@@ -60,7 +44,7 @@ class AnyDBMTestCase(unittest.TestCase): ...@@ -60,7 +44,7 @@ class AnyDBMTestCase(unittest.TestCase):
unittest.TestCase.__init__(self, *args) unittest.TestCase.__init__(self, *args)
def test_anydbm_creation(self): def test_anydbm_creation(self):
f = anydbm.open(_fname, 'c') f = dbm.open(_fname, 'c')
self.assertEqual(list(f.keys()), []) self.assertEqual(list(f.keys()), [])
for key in self._dict: for key in self._dict:
f[key.encode("ascii")] = self._dict[key] f[key.encode("ascii")] = self._dict[key]
...@@ -69,26 +53,26 @@ class AnyDBMTestCase(unittest.TestCase): ...@@ -69,26 +53,26 @@ class AnyDBMTestCase(unittest.TestCase):
def test_anydbm_modification(self): def test_anydbm_modification(self):
self.init_db() self.init_db()
f = anydbm.open(_fname, 'c') f = dbm.open(_fname, 'c')
self._dict['g'] = f[b'g'] = b"indented" self._dict['g'] = f[b'g'] = b"indented"
self.read_helper(f) self.read_helper(f)
f.close() f.close()
def test_anydbm_read(self): def test_anydbm_read(self):
self.init_db() self.init_db()
f = anydbm.open(_fname, 'r') f = dbm.open(_fname, 'r')
self.read_helper(f) self.read_helper(f)
f.close() f.close()
def test_anydbm_keys(self): def test_anydbm_keys(self):
self.init_db() self.init_db()
f = anydbm.open(_fname, 'r') f = dbm.open(_fname, 'r')
keys = self.keys_helper(f) keys = self.keys_helper(f)
f.close() f.close()
def test_anydbm_access(self): def test_anydbm_access(self):
self.init_db() self.init_db()
f = anydbm.open(_fname, 'r') f = dbm.open(_fname, 'r')
key = "a".encode("ascii") key = "a".encode("ascii")
assert(key in f) assert(key in f)
assert(f[key] == b"Python:") assert(f[key] == b"Python:")
...@@ -100,7 +84,7 @@ class AnyDBMTestCase(unittest.TestCase): ...@@ -100,7 +84,7 @@ class AnyDBMTestCase(unittest.TestCase):
self.assertEqual(self._dict[key], f[key.encode("ascii")]) self.assertEqual(self._dict[key], f[key.encode("ascii")])
def init_db(self): def init_db(self):
f = anydbm.open(_fname, 'n') f = dbm.open(_fname, 'n')
for k in self._dict: for k in self._dict:
f[k.encode("ascii")] = self._dict[k] f[k.encode("ascii")] = self._dict[k]
f.close() f.close()
...@@ -118,10 +102,44 @@ class AnyDBMTestCase(unittest.TestCase): ...@@ -118,10 +102,44 @@ class AnyDBMTestCase(unittest.TestCase):
delete_files() delete_files()
class WhichDBTestCase(unittest.TestCase):
# Actual test methods are added to namespace after class definition.
def __init__(self, *args):
unittest.TestCase.__init__(self, *args)
def test_whichdb(self):
for module in dbm_iterator():
# Check whether whichdb correctly guesses module name
# for databases opened with "module" module.
# Try with empty files first
name = module.__name__
if name == 'dbm.dumb':
continue # whichdb can't support dbm.dumb
test.support.unlink(_fname)
f = module.open(_fname, 'c')
f.close()
self.assertEqual(name, dbm.whichdb(_fname))
# Now add a key
f = module.open(_fname, 'w')
f[b"1"] = b"1"
# and test that we can find it
self.assertTrue(b"1" in f)
# and read it
self.assertTrue(f[b"1"] == b"1")
f.close()
self.assertEqual(name, dbm.whichdb(_fname))
def tearDown(self):
delete_files()
def setUp(self):
delete_files()
def test_main(): def test_main():
try: try:
for module in dbm_iterator(): for module in dbm_iterator():
support.run_unittest(AnyDBMTestCase) test.support.run_unittest(AnyDBMTestCase, WhichDBTestCase)
finally: finally:
delete_files() delete_files()
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import os, sys import os, sys
import copy import copy
import bsddb import bsddb
import dbhash # Just so we know it's imported import dbm.bsd # Just so we know it's imported
import unittest import unittest
from test import support from test import support
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import io import io
import os import os
import unittest import unittest
import dumbdbm import dbm.dumb as dumbdbm
from test import support from test import support
_fname = support.TESTFN _fname = support.TESTFN
......
import gdbm import dbm.gnu as gdbm
import unittest import unittest
import os import os
from test.support import verbose, TESTFN, run_unittest, unlink from test.support import verbose, TESTFN, run_unittest, unlink
......
...@@ -2,14 +2,14 @@ from test import support ...@@ -2,14 +2,14 @@ from test import support
import unittest import unittest
import os import os
import random import random
import dbm import dbm.ndbm
from dbm import error from dbm.ndbm import error
class DbmTestCase(unittest.TestCase): class DbmTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.filename = support.TESTFN self.filename = support.TESTFN
self.d = dbm.open(self.filename, 'c') self.d = dbm.ndbm.open(self.filename, 'c')
self.d.close() self.d.close()
def tearDown(self): def tearDown(self):
...@@ -17,7 +17,7 @@ class DbmTestCase(unittest.TestCase): ...@@ -17,7 +17,7 @@ class DbmTestCase(unittest.TestCase):
support.unlink(self.filename + suffix) support.unlink(self.filename + suffix)
def test_keys(self): def test_keys(self):
self.d = dbm.open(self.filename, 'c') self.d = dbm.ndbm.open(self.filename, 'c')
self.assert_(self.d.keys() == []) self.assert_(self.d.keys() == [])
self.d['a'] = 'b' self.d['a'] = 'b'
self.d['12345678910'] = '019237410982340912840198242' self.d['12345678910'] = '019237410982340912840198242'
...@@ -28,9 +28,9 @@ class DbmTestCase(unittest.TestCase): ...@@ -28,9 +28,9 @@ class DbmTestCase(unittest.TestCase):
def test_modes(self): def test_modes(self):
for mode in ['r', 'rw', 'w', 'n']: for mode in ['r', 'rw', 'w', 'n']:
try: try:
self.d = dbm.open(self.filename, mode) self.d = dbm.ndbm.open(self.filename, mode)
self.d.close() self.d.close()
except dbm.error: except error:
self.fail() self.fail()
def test_main(): def test_main():
......
#! /usr/bin/env python
"""Test script for the whichdb module
based on test_anydbm.py
"""
import os
import test.support
import unittest
import whichdb
import anydbm
import glob
from test.test_anydbm import delete_files, dbm_iterator
_fname = test.support.TESTFN
class WhichDBTestCase(unittest.TestCase):
# Actual test methods are added to namespace
# after class definition.
def __init__(self, *args):
unittest.TestCase.__init__(self, *args)
def test_whichdb(self):
for module in dbm_iterator():
# Check whether whichdb correctly guesses module name
# for databases opened with "module" module.
# Try with empty files first
name = module.__name__
if name == 'dumbdbm':
continue # whichdb can't support dumbdbm
test.support.unlink(_fname)
f = module.open(_fname, 'c')
f.close()
self.assertEqual(name, whichdb.whichdb(_fname))
# Now add a key
f = module.open(_fname, 'w')
f[b"1"] = b"1"
# and test that we can find it
self.assertTrue(b"1" in f)
# and read it
self.assertTrue(f[b"1"] == b"1")
f.close()
self.assertEqual(name, whichdb.whichdb(_fname))
def tearDown(self):
delete_files()
def setUp(self):
delete_files()
def test_main():
try:
test.support.run_unittest(WhichDBTestCase)
finally:
delete_files()
if __name__ == "__main__":
test_main()
...@@ -57,8 +57,8 @@ following in your .purify file: ...@@ -57,8 +57,8 @@ following in your .purify file:
suppress umr ...; "socketmodule.c" suppress umr ...; "socketmodule.c"
suppress umr ...; time_strftime suppress umr ...; time_strftime
suppress umr ...; "dbmmodule.c" suppress umr ...; "_dbmmodule.c"
suppress umr ...; "gdbmmodule.c" suppress umr ...; "_gdbmmodule.c"
suppress umr ...; "grpmodule.c" suppress umr ...; "grpmodule.c"
suppress umr ...; "nismodule.c" suppress umr ...; "nismodule.c"
suppress umr ...; "pwdmodule.c" suppress umr ...; "pwdmodule.c"
......
...@@ -1795,8 +1795,8 @@ List of modules and packages in base distribution ...@@ -1795,8 +1795,8 @@ List of modules and packages in base distribution
Standard library modules Standard library modules
Operation Result Operation Result
aifc Stuff to parse AIFF-C and AIFF files. aifc Stuff to parse AIFF-C and AIFF files.
anydbm Generic interface to all dbm clones. (dbhash, gdbm, dbm Generic interface to all dbm clones. (dbm.bsd, dbm.gnu,
dbm,dumbdbm) dbm.ndbm, dbm.dumb)
asynchat Support for 'chat' style protocols asynchat Support for 'chat' style protocols
asyncore Asynchronous File I/O (in select style) asyncore Asynchronous File I/O (in select style)
atexit Register functions to be called at exit of Python interpreter. atexit Register functions to be called at exit of Python interpreter.
...@@ -1822,21 +1822,16 @@ ConfigParser Configuration file parser (much like windows .ini files) ...@@ -1822,21 +1822,16 @@ ConfigParser Configuration file parser (much like windows .ini files)
copy Generic shallow and deep copying operations. copy Generic shallow and deep copying operations.
copy_reg Helper to provide extensibility for pickle/cPickle. copy_reg Helper to provide extensibility for pickle/cPickle.
csv Read and write files with comma separated values. csv Read and write files with comma separated values.
dbhash (g)dbm-compatible interface to bsdhash.hashopen.
dircache Sorted list of files in a dir, using a cache. dircache Sorted list of files in a dir, using a cache.
[DEL:dircmp:DEL] [DEL:Defines a class to build directory diff tools on.:DEL]
difflib Tool for creating delta between sequences. difflib Tool for creating delta between sequences.
dis Bytecode disassembler. dis Bytecode disassembler.
distutils Package installation system. distutils Package installation system.
doctest Tool for running and verifying tests inside doc strings. doctest Tool for running and verifying tests inside doc strings.
dospath Common operations on DOS pathnames. dospath Common operations on DOS pathnames.
dumbdbm A dumb and slow but simple dbm clone.
[DEL:dump:DEL] [DEL:Print python code that reconstructs a variable.:DEL]
email Comprehensive support for internet email. email Comprehensive support for internet email.
filecmp File comparison. filecmp File comparison.
fileinput Helper class to quickly write a loop over all standard input fileinput Helper class to quickly write a loop over all standard input
files. files.
[DEL:find:DEL] [DEL:Find files directory hierarchy matching a pattern.:DEL]
fnmatch Filename matching with shell patterns. fnmatch Filename matching with shell patterns.
formatter A test formatter. formatter A test formatter.
fpformat General floating point formatting functions. fpformat General floating point formatting functions.
...@@ -1847,7 +1842,6 @@ getopt Standard command line processing. See also ftp:// ...@@ -1847,7 +1842,6 @@ getopt Standard command line processing. See also ftp://
www.pauahtun.org/pub/getargspy.zip www.pauahtun.org/pub/getargspy.zip
getpass Utilities to get a password and/or the current user name. getpass Utilities to get a password and/or the current user name.
glob filename globbing. glob filename globbing.
[DEL:grep:DEL] [DEL:'grep' utilities.:DEL]
gzip Read & write gzipped files. gzip Read & write gzipped files.
heapq Priority queue implemented using lists organized as heaps. heapq Priority queue implemented using lists organized as heaps.
HMAC Keyed-Hashing for Message Authentication -- RFC 2104. HMAC Keyed-Hashing for Message Authentication -- RFC 2104.
...@@ -1882,8 +1876,6 @@ ntpath Common operations on DOS pathnames. ...@@ -1882,8 +1876,6 @@ ntpath Common operations on DOS pathnames.
nturl2path Mac specific module for conversion between pathnames and URLs. nturl2path Mac specific module for conversion between pathnames and URLs.
optparse A comprehensive tool for processing command line options. optparse A comprehensive tool for processing command line options.
os Either mac, dos or posix depending system. os Either mac, dos or posix depending system.
[DEL:packmail: [DEL:Create a self-unpacking shell archive.:DEL]
DEL]
pdb A Python debugger. pdb A Python debugger.
pickle Pickling (save and restore) of Python objects (a faster pickle Pickling (save and restore) of Python objects (a faster
Cimplementation exists in built-in module: cPickle). Cimplementation exists in built-in module: cPickle).
...@@ -1929,7 +1921,7 @@ StringIO File-like objects that read/write a string buffer (a fasterC ...@@ -1929,7 +1921,7 @@ StringIO File-like objects that read/write a string buffer (a fasterC
sunau Stuff to parse Sun and NeXT audio files. sunau Stuff to parse Sun and NeXT audio files.
sunaudio Interpret sun audio headers. sunaudio Interpret sun audio headers.
symbol Non-terminal symbols of Python grammar (from "graminit.h"). symbol Non-terminal symbols of Python grammar (from "graminit.h").
tabnanny,/font> Check Python source for ambiguous indentation. tabnanny Check Python source for ambiguous indentation.
tarfile Facility for reading and writing to the *nix tarfile format. tarfile Facility for reading and writing to the *nix tarfile format.
telnetlib TELNET client class. Based on RFC 854. telnetlib TELNET client class. Based on RFC 854.
tempfile Temporary file name allocation. tempfile Temporary file name allocation.
...@@ -1950,15 +1942,11 @@ user Hook to allow user-specified customization code to run. ...@@ -1950,15 +1942,11 @@ user Hook to allow user-specified customization code to run.
UserDict A wrapper to allow subclassing of built-in dict class. UserDict A wrapper to allow subclassing of built-in dict class.
UserList A wrapper to allow subclassing of built-in list class. UserList A wrapper to allow subclassing of built-in list class.
UserString A wrapper to allow subclassing of built-in string class. UserString A wrapper to allow subclassing of built-in string class.
[DEL:util:DEL] [DEL:some useful functions that don't fit elsewhere !!:DEL]
uu UUencode/UUdecode. uu UUencode/UUdecode.
unittest Utilities for implementing unit testing. unittest Utilities for implementing unit testing.
wave Stuff to parse WAVE files. wave Stuff to parse WAVE files.
weakref Tools for creating and managing weakly referenced objects. weakref Tools for creating and managing weakly referenced objects.
webbrowser Platform independent URL launcher. webbrowser Platform independent URL launcher.
[DEL:whatsound: [DEL:Several routines that help recognizing sound files.:DEL]
DEL]
whichdb Guess which db package to use to open a db file.
xdrlib Implements (a subset of) Sun XDR (eXternal Data xdrlib Implements (a subset of) Sun XDR (eXternal Data
Representation) Representation)
xmllib A parser for XML, using the derived class as static DTD. xmllib A parser for XML, using the derived class as static DTD.
...@@ -1966,7 +1954,6 @@ xml.dom Classes for processing XML using the Document Object Model. ...@@ -1966,7 +1954,6 @@ xml.dom Classes for processing XML using the Document Object Model.
xml.sax Classes for processing XML using the SAX API. xml.sax Classes for processing XML using the SAX API.
xmlrpclib Support for remote procedure calls using XML. xmlrpclib Support for remote procedure calls using XML.
zipfile Read & write PK zipped files. zipfile Read & write PK zipped files.
[DEL:zmod:DEL] [DEL:Demonstration of abstruse mathematical concepts.:DEL]
...@@ -1993,7 +1980,7 @@ zipfile Read & write PK zipped files. ...@@ -1993,7 +1980,7 @@ zipfile Read & write PK zipped files.
* Unix/Posix * * Unix/Posix *
dbm Interface to Unix ndbm database library dbm Interface to Unix dbm databases
grp Interface to Unix group database grp Interface to Unix group database
posix OS functionality standardized by C and POSIX standards posix OS functionality standardized by C and POSIX standards
posixpath POSIX pathname functions posixpath POSIX pathname functions
......
...@@ -294,8 +294,8 @@ _symtable symtablemodule.c ...@@ -294,8 +294,8 @@ _symtable symtablemodule.c
# Modules that provide persistent dictionary-like semantics. You will # Modules that provide persistent dictionary-like semantics. You will
# probably want to arrange for at least one of them to be available on # probably want to arrange for at least one of them to be available on
# your machine, though none are defined by default because of library # your machine, though none are defined by default because of library
# dependencies. The Python module anydbm.py provides an # dependencies. The Python module dbm/__init__.py provides an
# implementation independent wrapper for these; dumbdbm.py provides # implementation independent wrapper for these; dbm/dumb.py provides
# similar functionality (but slower of course) implemented in Python. # similar functionality (but slower of course) implemented in Python.
# The standard Unix dbm module has been moved to Setup.config so that # The standard Unix dbm module has been moved to Setup.config so that
...@@ -305,13 +305,13 @@ _symtable symtablemodule.c ...@@ -305,13 +305,13 @@ _symtable symtablemodule.c
# #
# First, look at Setup.config; configure may have set this for you. # First, look at Setup.config; configure may have set this for you.
#dbm dbmmodule.c # dbm(3) may require -lndbm or similar #_dbm _dbmmodule.c # dbm(3) may require -lndbm or similar
# Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
# #
# First, look at Setup.config; configure may have set this for you. # First, look at Setup.config; configure may have set this for you.
#gdbm gdbmmodule.c -I/usr/local/include -L/usr/local/lib -lgdbm #_gdbm _gdbmmodule.c -I/usr/local/include -L/usr/local/lib -lgdbm
# Sleepycat Berkeley DB interface. # Sleepycat Berkeley DB interface.
......
...@@ -332,7 +332,7 @@ dbm_getattr(dbmobject *dp, char *name) ...@@ -332,7 +332,7 @@ dbm_getattr(dbmobject *dp, char *name)
static PyTypeObject Dbmtype = { static PyTypeObject Dbmtype = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"dbm.dbm", "_dbm.dbm",
sizeof(dbmobject), sizeof(dbmobject),
0, 0,
(destructor)dbm_dealloc, /*tp_dealloc*/ (destructor)dbm_dealloc, /*tp_dealloc*/
...@@ -391,17 +391,17 @@ static PyMethodDef dbmmodule_methods[] = { ...@@ -391,17 +391,17 @@ static PyMethodDef dbmmodule_methods[] = {
}; };
PyMODINIT_FUNC PyMODINIT_FUNC
initdbm(void) { init_dbm(void) {
PyObject *m, *d, *s; PyObject *m, *d, *s;
if (PyType_Ready(&Dbmtype) < 0) if (PyType_Ready(&Dbmtype) < 0)
return; return;
m = Py_InitModule("dbm", dbmmodule_methods); m = Py_InitModule("_dbm", dbmmodule_methods);
if (m == NULL) if (m == NULL)
return; return;
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
if (DbmError == NULL) if (DbmError == NULL)
DbmError = PyErr_NewException("dbm.error", NULL, NULL); DbmError = PyErr_NewException("_dbm.error", NULL, NULL);
s = PyUnicode_FromString(which_dbm); s = PyUnicode_FromString(which_dbm);
if (s != NULL) { if (s != NULL) {
PyDict_SetItemString(d, "library", s); PyDict_SetItemString(d, "library", s);
......
...@@ -389,7 +389,7 @@ dbm_getattr(dbmobject *dp, char *name) ...@@ -389,7 +389,7 @@ dbm_getattr(dbmobject *dp, char *name)
static PyTypeObject Dbmtype = { static PyTypeObject Dbmtype = {
PyVarObject_HEAD_INIT(0, 0) PyVarObject_HEAD_INIT(0, 0)
"gdbm.gdbm", "_gdbm.gdbm",
sizeof(dbmobject), sizeof(dbmobject),
0, 0,
(destructor)dbm_dealloc, /*tp_dealloc*/ (destructor)dbm_dealloc, /*tp_dealloc*/
...@@ -512,18 +512,18 @@ static PyMethodDef dbmmodule_methods[] = { ...@@ -512,18 +512,18 @@ static PyMethodDef dbmmodule_methods[] = {
}; };
PyMODINIT_FUNC PyMODINIT_FUNC
initgdbm(void) { init_gdbm(void) {
PyObject *m, *d, *s; PyObject *m, *d, *s;
if (PyType_Ready(&Dbmtype) < 0) if (PyType_Ready(&Dbmtype) < 0)
return; return;
m = Py_InitModule4("gdbm", dbmmodule_methods, m = Py_InitModule4("_gdbm", dbmmodule_methods,
gdbmmodule__doc__, (PyObject *)NULL, gdbmmodule__doc__, (PyObject *)NULL,
PYTHON_API_VERSION); PYTHON_API_VERSION);
if (m == NULL) if (m == NULL)
return; return;
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
DbmError = PyErr_NewException("gdbm.error", NULL, NULL); DbmError = PyErr_NewException("_gdbm.error", NULL, NULL);
if (DbmError != NULL) { if (DbmError != NULL) {
PyDict_SetItemString(d, "error", DbmError); PyDict_SetItemString(d, "error", DbmError);
s = PyUnicode_FromString(dbmmodule_open_flags); s = PyUnicode_FromString(dbmmodule_open_flags);
......
...@@ -127,7 +127,7 @@ lock_getattr(lockobject *self, char *name) ...@@ -127,7 +127,7 @@ lock_getattr(lockobject *self, char *name)
static PyTypeObject Locktype = { static PyTypeObject Locktype = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) PyVarObject_HEAD_INIT(&PyType_Type, 0)
"thread.lock", /*tp_name*/ "_thread.lock", /*tp_name*/
sizeof(lockobject), /*tp_size*/ sizeof(lockobject), /*tp_size*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
/* methods */ /* methods */
...@@ -336,7 +336,7 @@ static PyObject *local_getattro(localobject *, PyObject *); ...@@ -336,7 +336,7 @@ static PyObject *local_getattro(localobject *, PyObject *);
static PyTypeObject localtype = { static PyTypeObject localtype = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
/* tp_name */ "thread._local", /* tp_name */ "_thread._local",
/* tp_basicsize */ sizeof(localobject), /* tp_basicsize */ sizeof(localobject),
/* tp_itemsize */ 0, /* tp_itemsize */ 0,
/* tp_dealloc */ (destructor)local_dealloc, /* tp_dealloc */ (destructor)local_dealloc,
......
...@@ -464,7 +464,7 @@ ifeq ($(HAVE_NCURSES),yes) ...@@ -464,7 +464,7 @@ ifeq ($(HAVE_NCURSES),yes)
HARDEXTMODULES+= _curses_ HARDEXTMODULES+= _curses_
endif endif
ifeq ($(HAVE_GDBM),yes) ifeq ($(HAVE_GDBM),yes)
HARDEXTMODULES+= gdbm dbm HARDEXTMODULES+= _gdbm _dbm
endif endif
ifeq ($(HAVE_BZ2),yes) ifeq ($(HAVE_BZ2),yes)
HARDEXTMODULES+= bz2 HARDEXTMODULES+= bz2
...@@ -626,10 +626,10 @@ _curses_panel$(MODULE.EXT): $(OUT)_curses_panel$O $(OUT)_curses_panel_m.def $(PY ...@@ -626,10 +626,10 @@ _curses_panel$(MODULE.EXT): $(OUT)_curses_panel$O $(OUT)_curses_panel_m.def $(PY
_curses_$(MODULE.EXT): _curses_panel$(MODULE.EXT) _curses_$(MODULE.EXT): _curses_panel$(MODULE.EXT)
cp $^ $@ cp $^ $@
dbm$(MODULE.EXT): $(OUT)dbmmodule$O $(OUT)dbm_m.def $(PYTHON.IMPLIB) _dbm$(MODULE.EXT): $(OUT)_dbmmodule$O $(OUT)dbm_m.def $(PYTHON.IMPLIB)
$(LD) $(LDFLAGS.DLL) -o $@ $(^^) $(L^) $(LIBS) -lgdbm $(LD) $(LDFLAGS.DLL) -o $@ $(^^) $(L^) $(LIBS) -lgdbm
gdbm$(MODULE.EXT): $(OUT)gdbmmodule$O $(OUT)gdbm_m.def $(PYTHON.IMPLIB) _gdbm$(MODULE.EXT): $(OUT)_gdbmmodule$O $(OUT)gdbm_m.def $(PYTHON.IMPLIB)
$(LD) $(LDFLAGS.DLL) -o $@ $(^^) $(L^) $(LIBS) -lgdbm $(LD) $(LDFLAGS.DLL) -o $@ $(^^) $(L^) $(LIBS) -lgdbm
......
...@@ -494,7 +494,7 @@ cursesmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ ...@@ -494,7 +494,7 @@ cursesmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \
$(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \ $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \
$(PY_INCLUDE)\tupleobject.h $(PY_INCLUDE)\tupleobject.h
dbmmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \ _dbmmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \
$(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h pyconfig.h \ $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h pyconfig.h \
$(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h $(PY_INCLUDE)\floatobject.h \ $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h $(PY_INCLUDE)\floatobject.h \
$(PY_INCLUDE)\funcobject.h $(PY_INCLUDE)\import.h $(PY_INCLUDE)\intobject.h \ $(PY_INCLUDE)\funcobject.h $(PY_INCLUDE)\import.h $(PY_INCLUDE)\intobject.h \
...@@ -576,7 +576,7 @@ fpetestmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ ...@@ -576,7 +576,7 @@ fpetestmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \
$(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \ $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \
$(PY_INCLUDE)\tupleobject.h $(PY_INCLUDE)\tupleobject.h
gdbmmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \ _gdbmmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \
$(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h pyconfig.h \ $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h pyconfig.h \
$(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h $(PY_INCLUDE)\floatobject.h \ $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h $(PY_INCLUDE)\floatobject.h \
$(PY_INCLUDE)\funcobject.h $(PY_INCLUDE)\import.h $(PY_INCLUDE)\intobject.h \ $(PY_INCLUDE)\funcobject.h $(PY_INCLUDE)\import.h $(PY_INCLUDE)\intobject.h \
......
...@@ -171,8 +171,8 @@ MODULES = \ ...@@ -171,8 +171,8 @@ MODULES = \
# audioop.c -- Various Compute Operations on Audio Samples # audioop.c -- Various Compute Operations on Audio Samples
# Database: # Database:
# dbmmodule.c -- Wrapper of DBM Database API (Generic Flavor) # _dbmmodule.c -- Wrapper of DBM Database API (Generic Flavor)
# gdbmmodule.c -- Wrapper of DBM Database API (GNU Flavor) # _gdbmmodule.c -- Wrapper of DBM Database API (GNU Flavor)
# Cryptography: # Cryptography:
# cryptmodule.c -- Simple Wrapper for crypt() Function # cryptmodule.c -- Simple Wrapper for crypt() Function
...@@ -410,7 +410,7 @@ cursesmodule.obj: abstract.h ceval.h classobject.h cobject.h \ ...@@ -410,7 +410,7 @@ cursesmodule.obj: abstract.h ceval.h classobject.h cobject.h \
pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \ pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \
stringobject.h sysmodule.h traceback.h tupleobject.h stringobject.h sysmodule.h traceback.h tupleobject.h
dbmmodule.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \ _dbmmodule.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \
pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \ pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \
import.h intobject.h intrcheck.h listobject.h longobject.h \ import.h intobject.h intrcheck.h listobject.h longobject.h \
methodobject.h modsupport.h moduleobject.h mymalloc.h myproto.h \ methodobject.h modsupport.h moduleobject.h mymalloc.h myproto.h \
...@@ -458,7 +458,7 @@ fpetestmodule.obj: abstract.h ceval.h classobject.h cobject.h \ ...@@ -458,7 +458,7 @@ fpetestmodule.obj: abstract.h ceval.h classobject.h cobject.h \
pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \ pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \
stringobject.h sysmodule.h traceback.h tupleobject.h stringobject.h sysmodule.h traceback.h tupleobject.h
gdbmmodule.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \ _gdbmmodule.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \
pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \ pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \
import.h intobject.h intrcheck.h listobject.h longobject.h \ import.h intobject.h intrcheck.h listobject.h longobject.h \
methodobject.h modsupport.h moduleobject.h mymalloc.h myproto.h \ methodobject.h modsupport.h moduleobject.h mymalloc.h myproto.h \
......
...@@ -6,7 +6,7 @@ Synopsis: %(prog)s [-h|-g|-b|-r|-a] dbfile [ picklefile ] ...@@ -6,7 +6,7 @@ Synopsis: %(prog)s [-h|-g|-b|-r|-a] dbfile [ picklefile ]
Convert the database file given on the command line to a pickle Convert the database file given on the command line to a pickle
representation. The optional flags indicate the type of the database: representation. The optional flags indicate the type of the database:
-a - open using anydbm -a - open using dbm (any supported format)
-b - open as bsddb btree file -b - open as bsddb btree file
-d - open as dbm file -d - open as dbm file
-g - open as gdbm file -g - open as gdbm file
...@@ -25,15 +25,15 @@ try: ...@@ -25,15 +25,15 @@ try:
except ImportError: except ImportError:
bsddb = None bsddb = None
try: try:
import dbm import dbm.ndbm as dbm
except ImportError: except ImportError:
dbm = None dbm = None
try: try:
import gdbm import dbm.gnu as gdbm
except ImportError: except ImportError:
gdbm = None gdbm = None
try: try:
import anydbm import dbm as anydbm
except ImportError: except ImportError:
anydbm = None anydbm = None
import sys import sys
...@@ -94,19 +94,19 @@ def main(args): ...@@ -94,19 +94,19 @@ def main(args):
try: try:
dbopen = anydbm.open dbopen = anydbm.open
except AttributeError: except AttributeError:
sys.stderr.write("anydbm module unavailable.\n") sys.stderr.write("dbm module unavailable.\n")
return 1 return 1
elif opt in ("-g", "--gdbm"): elif opt in ("-g", "--gdbm"):
try: try:
dbopen = gdbm.open dbopen = gdbm.open
except AttributeError: except AttributeError:
sys.stderr.write("gdbm module unavailable.\n") sys.stderr.write("dbm.gnu module unavailable.\n")
return 1 return 1
elif opt in ("-d", "--dbm"): elif opt in ("-d", "--dbm"):
try: try:
dbopen = dbm.open dbopen = dbm.open
except AttributeError: except AttributeError:
sys.stderr.write("dbm module unavailable.\n") sys.stderr.write("dbm.ndbm module unavailable.\n")
return 1 return 1
if dbopen is None: if dbopen is None:
if bsddb is None: if bsddb is None:
......
...@@ -7,10 +7,10 @@ Read the given picklefile as a series of key/value pairs and write to a new ...@@ -7,10 +7,10 @@ Read the given picklefile as a series of key/value pairs and write to a new
database. If the database already exists, any contents are deleted. The database. If the database already exists, any contents are deleted. The
optional flags indicate the type of the output database: optional flags indicate the type of the output database:
-a - open using anydbm -a - open using dbm (open any supported format)
-b - open as bsddb btree file -b - open as bsddb btree file
-d - open as dbm file -d - open as dbm.ndbm file
-g - open as gdbm file -g - open as dbm.gnu file
-h - open as bsddb hash file -h - open as bsddb hash file
-r - open as bsddb recno file -r - open as bsddb recno file
...@@ -30,15 +30,15 @@ try: ...@@ -30,15 +30,15 @@ try:
except ImportError: except ImportError:
bsddb = None bsddb = None
try: try:
import dbm import dbm.ndbm as dbm
except ImportError: except ImportError:
dbm = None dbm = None
try: try:
import gdbm import dbm.gnu as gdbm
except ImportError: except ImportError:
gdbm = None gdbm = None
try: try:
import anydbm import dbm as anydbm
except ImportError: except ImportError:
anydbm = None anydbm = None
import sys import sys
...@@ -99,19 +99,19 @@ def main(args): ...@@ -99,19 +99,19 @@ def main(args):
try: try:
dbopen = anydbm.open dbopen = anydbm.open
except AttributeError: except AttributeError:
sys.stderr.write("anydbm module unavailable.\n") sys.stderr.write("dbm module unavailable.\n")
return 1 return 1
elif opt in ("-g", "--gdbm"): elif opt in ("-g", "--gdbm"):
try: try:
dbopen = gdbm.open dbopen = gdbm.open
except AttributeError: except AttributeError:
sys.stderr.write("gdbm module unavailable.\n") sys.stderr.write("dbm.gnu module unavailable.\n")
return 1 return 1
elif opt in ("-d", "--dbm"): elif opt in ("-d", "--dbm"):
try: try:
dbopen = dbm.open dbopen = dbm.open
except AttributeError: except AttributeError:
sys.stderr.write("dbm module unavailable.\n") sys.stderr.write("dbm.ndbm module unavailable.\n")
return 1 return 1
if dbopen is None: if dbopen is None:
if bsddb is None: if bsddb is None:
......
...@@ -637,8 +637,8 @@ class PyBuildExt(build_ext): ...@@ -637,8 +637,8 @@ class PyBuildExt(build_ext):
# Modules that provide persistent dictionary-like semantics. You will # Modules that provide persistent dictionary-like semantics. You will
# probably want to arrange for at least one of them to be available on # probably want to arrange for at least one of them to be available on
# your machine, though none are defined by default because of library # your machine, though none are defined by default because of library
# dependencies. The Python module anydbm.py provides an # dependencies. The Python module dbm/__init__.py provides an
# implementation independent wrapper for these; dumbdbm.py provides # implementation independent wrapper for these; dbm/dumb.py provides
# similar functionality (but slower of course) implemented in Python. # similar functionality (but slower of course) implemented in Python.
# Sleepycat^WOracle Berkeley DB interface. # Sleepycat^WOracle Berkeley DB interface.
...@@ -902,16 +902,16 @@ class PyBuildExt(build_ext): ...@@ -902,16 +902,16 @@ class PyBuildExt(build_ext):
ndbm_libs = ['ndbm'] ndbm_libs = ['ndbm']
else: else:
ndbm_libs = [] ndbm_libs = []
exts.append( Extension('dbm', ['dbmmodule.c'], exts.append( Extension('_dbm', ['_dbmmodule.c'],
define_macros=[('HAVE_NDBM_H',None)], define_macros=[('HAVE_NDBM_H',None)],
libraries = ndbm_libs ) ) libraries = ndbm_libs ) )
elif (self.compiler.find_library_file(lib_dirs, 'gdbm') elif (self.compiler.find_library_file(lib_dirs, 'gdbm')
and find_file("gdbm/ndbm.h", inc_dirs, []) is not None): and find_file("gdbm/ndbm.h", inc_dirs, []) is not None):
exts.append( Extension('dbm', ['dbmmodule.c'], exts.append( Extension('_dbm', ['_dbmmodule.c'],
define_macros=[('HAVE_GDBM_NDBM_H',None)], define_macros=[('HAVE_GDBM_NDBM_H',None)],
libraries = ['gdbm'] ) ) libraries = ['gdbm'] ) )
elif db_incs is not None: elif db_incs is not None:
exts.append( Extension('dbm', ['dbmmodule.c'], exts.append( Extension('_dbm', ['_dbmmodule.c'],
library_dirs=dblib_dir, library_dirs=dblib_dir,
runtime_library_dirs=dblib_dir, runtime_library_dirs=dblib_dir,
include_dirs=db_incs, include_dirs=db_incs,
...@@ -919,14 +919,14 @@ class PyBuildExt(build_ext): ...@@ -919,14 +919,14 @@ class PyBuildExt(build_ext):
('DB_DBM_HSEARCH',None)], ('DB_DBM_HSEARCH',None)],
libraries=dblibs)) libraries=dblibs))
else: else:
missing.append('dbm') missing.append('_dbm')
# Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
if (self.compiler.find_library_file(lib_dirs, 'gdbm')): if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
exts.append( Extension('gdbm', ['gdbmmodule.c'], exts.append( Extension('_gdbm', ['_gdbmmodule.c'],
libraries = ['gdbm'] ) ) libraries = ['gdbm'] ) )
else: else:
missing.append('gdbm') missing.append('_gdbm')
# Unix-only modules # Unix-only modules
if platform not in ['mac', 'win32']: if platform not in ['mac', 'win32']:
......
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