parameters: (self, filename, dbhome, create=0, truncate=0, mode=0600,
                   recover=0, dbflags=0)
docstring: bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600)
  
          Open database name in the dbhome Berkeley DB directory.
          Use keyword arguments when calling this constructor.
docstring_summary: bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600)
docstring_tokens: bsdTableDB ( filename dbhome create = 0 truncate = 0 mode = 0600 )
function: def __init__(self, filename, dbhome, create=0, truncate=0, mode=0600,
                   recover=0, dbflags=0):
          """bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600)
  
          Open database name in the dbhome Berkeley DB directory.
          Use keyword arguments when calling this constructor.
          """
          self.db = None
          myflags = db.DB_THREAD
          if create:
              myflags |= db.DB_CREATE
          flagsforenv = (db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_LOG |
                         db.DB_INIT_TXN | dbflags)
          # DB_AUTO_COMMIT isn't a valid flag for env.open()
          try:
              dbflags |= db.DB_AUTO_COMMIT
          except AttributeError:
              pass
          if recover:
              flagsforenv = flagsforenv | db.DB_RECOVER
          self.env = db.DBEnv()
          # enable auto deadlock avoidance
          self.env.set_lk_detect(db.DB_LOCK_DEFAULT)
          self.env.open(dbhome, myflags | flagsforenv)
          if truncate:
              myflags |= db.DB_TRUNCATE
          self.db = db.DB(self.env)
          # this code relies on DBCursor.set* methods to raise exceptions
          # rather than returning None
          self.db.set_get_returns_none(1)
          # allow duplicate entries [warning: be careful w/ metadata]
          self.db.set_flags(db.DB_DUP)
          self.db.open(filename, db.DB_BTREE, dbflags | myflags, mode)
          self.dbfilename = filename
  
          if sys.version_info[0] >= 3 :
              class cursor_py3k(object) :
                  def __init__(self, dbcursor) :
                      self._dbcursor = dbcursor
  
                  def close(self) :
                      return self._dbcursor.close()
  
                  def set_range(self, search) :
                      v = self._dbcursor.set_range(bytes(search, "iso8859-1"))
                      if v is not None :
                          v = (v[0].decode("iso8859-1"),
                                  v[1].decode("iso8859-1"))
                      return v
  
                  def __next__(self) :
                      v = getattr(self._dbcursor, "next")()
                      if v is not None :
                          v = (v[0].decode("iso8859-1"),
                                  v[1].decode("iso8859-1"))
                      return v
  
              class db_py3k(object) :
                  def __init__(self, db) :
                      self._db = db
  
                  def cursor(self, txn=None) :
                      return cursor_py3k(self._db.cursor(txn=txn))
  
                  def has_key(self, key, txn=None) :
                      return getattr(self._db,"has_key")(bytes(key, "iso8859-1"),
                              txn=txn)
  
                  def put(self, key, value, flags=0, txn=None) :
                      key = bytes(key, "iso8859-1")
                      if value is not None :
                          value = bytes(value, "iso8859-1")
                      return self._db.put(key, value, flags=flags, txn=txn)
  
                  def put_bytes(self, key, value, txn=None) :
                      key = bytes(key, "iso8859-1")
                      return self._db.put(key, value, txn=txn)
  
                  def get(self, key, txn=None, flags=0) :
                      key = bytes(key, "iso8859-1")
                      v = self._db.get(key, txn=txn, flags=flags)
                      if v is not None :
                          v = v.decode("iso8859-1")
                      return v
  
                  def get_bytes(self, key, txn=None, flags=0) :
                      key = bytes(key, "iso8859-1")
                      return self._db.get(key, txn=txn, flags=flags)
  
                  def delete(self, key, txn=None) :
                      key = bytes(key, "iso8859-1")
                      return self._db.delete(key, txn=txn)
  
                  def close (self) :
                      return self._db.close()
  
              self.db = db_py3k(self.db)
          else :  # Python 2.x
              pass
  
          # Initialize the table names list if this is a new database
          txn = self.env.txn_begin()
          try:
              if not getattr(self.db, "has_key")(_table_names_key, txn):
                  getattr(self.db, "put_bytes", self.db.put) \
                          (_table_names_key, pickle.dumps([], 1), txn=txn)
          # Yes, bare except
          except:
              txn.abort()
              raise
          else:
              txn.commit()
          # TODO verify more of the database's metadata?
          self.__tablecolumns = {}
function_tokens: def __init__ ( self , filename , dbhome , create = 0 , truncate = 0 , mode = 0600 , recover = 0 , dbflags = 0 ) : self . db = None myflags = db . DB_THREAD if create : myflags |= db . DB_CREATE flagsforenv = ( db . DB_INIT_MPOOL | db . DB_INIT_LOCK | db . DB_INIT_LOG | db . DB_INIT_TXN | dbflags ) # DB_AUTO_COMMIT isn't a valid flag for env.open() try : dbflags |= db . DB_AUTO_COMMIT except AttributeError : pass if recover : flagsforenv = flagsforenv | db . DB_RECOVER self . env = db . DBEnv ( ) # enable auto deadlock avoidance self . env . set_lk_detect ( db . DB_LOCK_DEFAULT ) self . env . open ( dbhome , myflags | flagsforenv ) if truncate : myflags |= db . DB_TRUNCATE self . db = db . DB ( self . env ) # this code relies on DBCursor.set* methods to raise exceptions # rather than returning None self . db . set_get_returns_none ( 1 ) # allow duplicate entries [warning: be careful w/ metadata] self . db . set_flags ( db . DB_DUP ) self . db . open ( filename , db . DB_BTREE , dbflags | myflags , mode ) self . dbfilename = filename if sys . version_info [ 0 ] >= 3 : class cursor_py3k ( object ) : def __init__ ( self , dbcursor ) : self . _dbcursor = dbcursor def close ( self ) : return self . _dbcursor . close ( ) def set_range ( self , search ) : v = self . _dbcursor . set_range ( bytes ( search , "iso8859-1" ) ) if v is not None : v = ( v [ 0 ] . decode ( "iso8859-1" ) , v [ 1 ] . decode ( "iso8859-1" ) ) return v def __next__ ( self ) : v = getattr ( self . _dbcursor , "next" ) ( ) if v is not None : v = ( v [ 0 ] . decode ( "iso8859-1" ) , v [ 1 ] . decode ( "iso8859-1" ) ) return v class db_py3k ( object ) : def __init__ ( self , db ) : self . _db = db def cursor ( self , txn = None ) : return cursor_py3k ( self . _db . cursor ( txn = txn ) ) def has_key ( self , key , txn = None ) : return getattr ( self . _db , "has_key" ) ( bytes ( key , "iso8859-1" ) , txn = txn ) def put ( self , key , value , flags = 0 , txn = None ) : key = bytes ( key , "iso8859-1" ) if value is not None : value = bytes ( value , "iso8859-1" ) return self . _db . put ( key , value , flags = flags , txn = txn ) def put_bytes ( self , key , value , txn = None ) : key = bytes ( key , "iso8859-1" ) return self . _db . put ( key , value , txn = txn ) def get ( self , key , txn = None , flags = 0 ) : key = bytes ( key , "iso8859-1" ) v = self . _db . get ( key , txn = txn , flags = flags ) if v is not None : v = v . decode ( "iso8859-1" ) return v def get_bytes ( self , key , txn = None , flags = 0 ) : key = bytes ( key , "iso8859-1" ) return self . _db . get ( key , txn = txn , flags = flags ) def delete ( self , key , txn = None ) : key = bytes ( key , "iso8859-1" ) return self . _db . delete ( key , txn = txn ) def close ( self ) : return self . _db . close ( ) self . db = db_py3k ( self . db ) else : # Python 2.x pass # Initialize the table names list if this is a new database txn = self . env . txn_begin ( ) try : if not getattr ( self . db , "has_key" ) ( _table_names_key , txn ) : getattr ( self . db , "put_bytes" , self . db . put ) ( _table_names_key , pickle . dumps ( [ ] , 1 ) , txn = txn ) # Yes, bare except except : txn . abort ( ) raise else : txn . commit ( ) # TODO verify more of the database's metadata? self . __tablecolumns = { }