晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /proc/thread-self/root/usr/share/doc/python2-docs/html/_sources/library/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/usr/share/doc/python2-docs/html/_sources/library/bsddb.rst.txt
:mod:`bsddb` --- Interface to Berkeley DB library
=================================================

.. module:: bsddb
   :synopsis: Interface to Berkeley DB database library
.. sectionauthor:: Skip Montanaro <skip@pobox.com>

.. deprecated:: 2.6
    The :mod:`bsddb` module has been removed in Python 3.


The :mod:`bsddb` module provides an interface to the Berkeley DB library.  Users
can create hash, btree or record based library files using the appropriate open
call. Bsddb objects behave generally like dictionaries.  Keys and values must be
strings, however, so to use other objects as keys or to store other kinds of
objects the user must serialize them somehow, typically using
:func:`marshal.dumps` or  :func:`pickle.dumps`.

The :mod:`bsddb` module requires a Berkeley DB library version from 4.0 thru
4.7.


.. seealso::

   http://www.jcea.es/programacion/pybsddb.htm
      The website with documentation for the :mod:`bsddb.db` Python Berkeley DB
      interface that closely mirrors the object oriented interface provided in
      Berkeley DB 4.x itself.

   http://www.oracle.com/database/berkeley-db/
      The Berkeley DB library.

A more modern DB, DBEnv and DBSequence object interface is available in the
:mod:`bsddb.db` module which closely matches the Berkeley DB C API documented at
the above URLs.  Additional features provided by the :mod:`bsddb.db` API include
fine tuning, transactions, logging, and multiprocess concurrent database access.

The following is a description of the legacy :mod:`bsddb` interface compatible
with the old Python bsddb module.  Starting in Python 2.5 this interface should
be safe for multithreaded access.  The :mod:`bsddb.db` API is recommended for
threading users as it provides better control.

The :mod:`bsddb` module defines the following functions that create objects that
access the appropriate type of Berkeley DB file.  The first two arguments of
each function are the same.  For ease of portability, only the first two
arguments should be used in most instances.


.. function:: hashopen(filename[, flag[, mode[, pgsize[, ffactor[, nelem[, cachesize[, lorder[, hflags]]]]]]]])

   Open the hash format file named *filename*.  Files never intended to be
   preserved on disk may be created by passing ``None`` as the  *filename*.  The
   optional *flag* identifies the mode used to open the file.  It may be ``'r'``
   (read only), ``'w'`` (read-write), ``'c'`` (read-write - create if necessary;
   the default) or ``'n'`` (read-write - truncate to zero length).  The other
   arguments are rarely used and are just passed to the low-level :c:func:`dbopen`
   function.  Consult the Berkeley DB documentation for their use and
   interpretation.


.. function:: btopen(filename[, flag[, mode[, btflags[, cachesize[, maxkeypage[, minkeypage[, pgsize[, lorder]]]]]]]])

   Open the btree format file named *filename*.  Files never intended  to be
   preserved on disk may be created by passing ``None`` as the  *filename*.  The
   optional *flag* identifies the mode used to open the file.  It may be ``'r'``
   (read only), ``'w'`` (read-write), ``'c'`` (read-write - create if necessary;
   the default) or ``'n'`` (read-write - truncate to zero length).  The other
   arguments are rarely used and are just passed to the low-level dbopen function.
   Consult the Berkeley DB documentation for their use and interpretation.


.. function:: rnopen(filename[, flag[, mode[, rnflags[, cachesize[, pgsize[, lorder[, rlen[, delim[, source[, pad]]]]]]]]]])

   Open a DB record format file named *filename*.  Files never intended  to be
   preserved on disk may be created by passing ``None`` as the  *filename*.  The
   optional *flag* identifies the mode used to open the file.  It may be ``'r'``
   (read only), ``'w'`` (read-write), ``'c'`` (read-write - create if necessary;
   the default) or ``'n'`` (read-write - truncate to zero length).  The other
   arguments are rarely used and are just passed to the low-level dbopen function.
   Consult the Berkeley DB documentation for their use and interpretation.

.. note::

   Beginning in 2.3 some Unix versions of Python may have a :mod:`bsddb185` module.
   This is present *only* to allow backwards compatibility with systems which ship
   with the old Berkeley DB 1.85 database library.  The :mod:`bsddb185` module
   should never be used directly in new code. The module has been removed in
   Python 3.  If you find you still need it look in PyPI.


.. seealso::

   Module :mod:`dbhash`
      DBM-style interface to the :mod:`bsddb`


.. _bsddb-objects:

Hash, BTree and Record Objects
------------------------------

Once instantiated, hash, btree and record objects support the same methods as
dictionaries.  In addition, they support the methods listed below.

.. versionchanged:: 2.3.1
   Added dictionary methods.


.. method:: bsddbobject.close()

   Close the underlying file.  The object can no longer be accessed.  Since there
   is no open :meth:`open` method for these objects, to open the file again a new
   :mod:`bsddb` module open function must be called.


.. method:: bsddbobject.keys()

   Return the list of keys contained in the DB file.  The order of the list is
   unspecified and should not be relied on.  In particular, the order of the list
   returned is different for different file formats.


.. method:: bsddbobject.has_key(key)

   Return ``1`` if the DB file contains the argument as a key.


.. method:: bsddbobject.set_location(key)

   Set the cursor to the item indicated by *key* and return a tuple containing the
   key and its value.  For binary tree databases (opened using :func:`btopen`), if
   *key* does not actually exist in the database, the cursor will point to the next
   item in sorted order and return that key and value.  For other databases,
   :exc:`KeyError` will be raised if *key* is not found in the database.


.. method:: bsddbobject.first()

   Set the cursor to the first item in the DB file and return it.  The order of
   keys in the file is unspecified, except in the case of B-Tree databases. This
   method raises :exc:`bsddb.error` if the database is empty.


.. method:: bsddbobject.next()

   Set the cursor to the next item in the DB file and return it.  The order of
   keys in the file is unspecified, except in the case of B-Tree databases.


.. method:: bsddbobject.previous()

   Set the cursor to the previous item in the DB file and return it.  The order of
   keys in the file is unspecified, except in the case of B-Tree databases.  This
   is not supported on hashtable databases (those opened with :func:`hashopen`).


.. method:: bsddbobject.last()

   Set the cursor to the last item in the DB file and return it.  The order of keys
   in the file is unspecified.  This is not supported on hashtable databases (those
   opened with :func:`hashopen`). This method raises :exc:`bsddb.error` if the
   database is empty.


.. method:: bsddbobject.sync()

   Synchronize the database on disk.

Example::

   >>> import bsddb
   >>> db = bsddb.btopen('spam.db', 'c')
   >>> for i in range(10): db['%d'%i] = '%d'% (i*i)
   ...
   >>> db['3']
   '9'
   >>> db.keys()
   ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
   >>> db.first()
   ('0', '0')
   >>> db.next()
   ('1', '1')
   >>> db.last()
   ('9', '81')
   >>> db.set_location('2')
   ('2', '4')
   >>> db.previous()
   ('1', '1')
   >>> for k, v in db.iteritems():
   ...     print k, v
   0 0
   1 1
   2 4
   3 9
   4 16
   5 25
   6 36
   7 49
   8 64
   9 81
   >>> '8' in db
   True
   >>> db.sync()
   0


haha - 2025