<s> _cvsid = '<STR_LIT>' <EOL> import re <EOL> import sys <EOL> import copy <EOL> import random <EOL> import struct <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> import pickle <EOL> else : <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> import cPickle as pickle <EOL> else : <EOL> import warnings <EOL> w = warnings . catch_warnings ( ) <EOL> w . __enter__ ( ) <EOL> try : <EOL> warnings . filterwarnings ( '<STR_LIT:ignore>' , <EOL> message = '<STR_LIT>' , <EOL> category = DeprecationWarning ) <EOL> import cPickle as pickle <EOL> finally : <EOL> w . __exit__ ( ) <EOL> del w <EOL> try : <EOL> from bsddb3 import db <EOL> except ImportError : <EOL> from bsddb import db <EOL> class TableDBError ( StandardError ) : <EOL> pass <EOL> class TableAlreadyExists ( TableDBError ) : <EOL> pass <EOL> class Cond : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , s ) : <EOL> return <NUM_LIT:1> <EOL> class ExactCond ( Cond ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , strtomatch ) : <EOL> self . strtomatch = strtomatch <EOL> def __call__ ( self , s ) : <EOL> return s == self . strtomatch <EOL> class PrefixCond ( Cond ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , prefix ) : <EOL> self . prefix = prefix <EOL> def __call__ ( self , s ) : <EOL> return s [ : len ( self . prefix ) ] == self . prefix <EOL> class PostfixCond ( Cond ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , postfix ) : <EOL> self . postfix = postfix <EOL> def __call__ ( self , s ) : <EOL> return s [ - len ( self . postfix ) : ] == self . postfix <EOL> class LikeCond ( Cond ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , likestr , re_flags = re . IGNORECASE ) : <EOL> chars_to_escape = '<STR_LIT>' <EOL> for char in chars_to_escape : <EOL> likestr = likestr . replace ( char , '<STR_LIT:\\>' + char ) <EOL> self . likestr = likestr . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) <EOL> self . re = re . compile ( '<STR_LIT>' + self . likestr + '<STR_LIT:$>' , re_flags ) <EOL> def __call__ ( self , s ) : <EOL> return self . re . match ( s ) <EOL> _table_names_key = '<STR_LIT>' <EOL> _columns = '<STR_LIT>' <EOL> def _columns_key ( table ) : <EOL> return table + _columns <EOL> _data = '<STR_LIT>' <EOL> _rowid = '<STR_LIT>' <EOL> _rowid_str_len = <NUM_LIT:8> <EOL> def _data_key ( table , col , rowid ) : <EOL> return table + _data + col + _data + rowid <EOL> def _search_col_data_key ( table , col ) : <EOL> return table + _data + col + _data <EOL> def _search_all_data_key ( table ) : <EOL> return table + _data <EOL> def _rowid_key ( table , rowid ) : <EOL> return table + _rowid + rowid + _rowid <EOL> def _search_rowid_key ( table ) : <EOL> return table + _rowid <EOL> def contains_metastrings ( s ) : <EOL> """<STR_LIT>""" <EOL> if ( s . find ( _table_names_key ) >= <NUM_LIT:0> or <EOL> s . find ( _columns ) >= <NUM_LIT:0> or <EOL> s . find ( _data ) >= <NUM_LIT:0> or <EOL> s . find ( _rowid ) >= <NUM_LIT:0> ) : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> class bsdTableDB : <EOL> def __init__ ( self , filename , dbhome , create = <NUM_LIT:0> , truncate = <NUM_LIT:0> , mode = <NUM_LIT:0> <NUM_LIT> , <EOL> recover = <NUM_LIT:0> , dbflags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . db = None <EOL> myflags = db . DB_THREAD <EOL> if create : <EOL> myflags |= db . DB_CREATE <EOL> flagsforenv = ( db . DB_INIT_MPOOL | db . DB_INIT_LOCK | db . DB_INIT_LOG | <EOL> db . DB_INIT_TXN | dbflags ) <EOL> try : <EOL> dbflags |= db . DB_AUTO_COMMIT <EOL> except AttributeError : <EOL> pass <EOL> if recover : <EOL> flagsforenv = flagsforenv | db . DB_RECOVER <EOL> self . env = db . DBEnv ( ) <EOL> self . env . set_lk_detect ( db . DB_LOCK_DEFAULT ) <EOL> self . env . open ( dbhome , myflags | flagsforenv ) <EOL> if truncate : <EOL> myflags |= db . DB_TRUNCATE <EOL> self . db = db . DB ( self . env ) <EOL> self . db . set_get_returns_none ( <NUM_LIT:1> ) <EOL> self . db . set_flags ( db . DB_DUP ) <EOL> self . db . open ( filename , db . DB_BTREE , dbflags | myflags , mode ) <EOL> self . dbfilename = filename <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> class cursor_py3k ( object ) : <EOL> def __init__ ( self , dbcursor ) : <EOL> self . _dbcursor = dbcursor <EOL> def close ( self ) : <EOL> return self . _dbcursor . close ( ) <EOL> def set_range ( self , search ) : <EOL> v = self . _dbcursor . set_range ( bytes ( search , "<STR_LIT>" ) ) <EOL> if v is not None : <EOL> v = ( v [ <NUM_LIT:0> ] . decode ( "<STR_LIT>" ) , <EOL> v [ <NUM_LIT:1> ] . decode ( "<STR_LIT>" ) ) <EOL> return v <EOL> def __next__ ( self ) : <EOL> v = getattr ( self . _dbcursor , "<STR_LIT>" ) ( ) <EOL> if v is not None : <EOL> v = ( v [ <NUM_LIT:0> ] . decode ( "<STR_LIT>" ) , <EOL> v [ <NUM_LIT:1> ] . decode ( "<STR_LIT>" ) ) <EOL> return v <EOL> class db_py3k ( object ) : <EOL> def __init__ ( self , db ) : <EOL> self . _db = db <EOL> def cursor ( self , txn = None ) : <EOL> return cursor_py3k ( self . _db . cursor ( txn = txn ) ) <EOL> def has_key ( self , key , txn = None ) : <EOL> return getattr ( self . _db , "<STR_LIT>" ) ( bytes ( key , "<STR_LIT>" ) , <EOL> txn = txn ) <EOL> def put ( self , key , value , flags = <NUM_LIT:0> , txn = None ) : <EOL> key = bytes ( key , "<STR_LIT>" ) <EOL> if value is not None : <EOL> value = bytes ( value , "<STR_LIT>" ) <EOL> return self . _db . put ( key , value , flags = flags , txn = txn ) <EOL> def put_bytes ( self , key , value , txn = None ) : <EOL> key = bytes ( key , "<STR_LIT>" ) <EOL> return self . _db . put ( key , value , txn = txn ) <EOL> def get ( self , key , txn = None , flags = <NUM_LIT:0> ) : <EOL> key = bytes ( key , "<STR_LIT>" ) <EOL> v = self . _db . get ( key , txn = txn , flags = flags ) <EOL> if v is not None : <EOL> v = v . decode ( "<STR_LIT>" ) <EOL> return v <EOL> def get_bytes ( self , key , txn = None , flags = <NUM_LIT:0> ) : <EOL> key = bytes ( key , "<STR_LIT>" ) <EOL> return self . _db . get ( key , txn = txn , flags = flags ) <EOL> def delete ( self , key , txn = None ) : <EOL> key = bytes ( key , "<STR_LIT>" ) <EOL> return self . _db . delete ( key , txn = txn ) <EOL> def close ( self ) : <EOL> return self . _db . close ( ) <EOL> self . db = db_py3k ( self . db ) <EOL> else : <EOL> pass <EOL> txn = self . env . txn_begin ( ) <EOL> try : <EOL> if not getattr ( self . db , "<STR_LIT>" ) ( _table_names_key , txn ) : <EOL> getattr ( self . db , "<STR_LIT>" , self . db . put ) ( _table_names_key , pickle . dumps ( [ ] , <NUM_LIT:1> ) , txn = txn ) <EOL> except : <EOL> txn . abort ( ) <EOL> raise <EOL> else : <EOL> txn . commit ( ) <EOL> self . __tablecolumns = { } <EOL> def __del__ ( self ) : <EOL> self . close ( ) <EOL> def close ( self ) : <EOL> if self . db is not None : <EOL> self . db . close ( ) <EOL> self . db = None <EOL> if self . env is not None : <EOL> self . env . close ( ) <EOL> self . env = None <EOL> def checkpoint ( self , mins = <NUM_LIT:0> ) : <EOL> self . env . txn_checkpoint ( mins ) <EOL> def sync ( self ) : <EOL> self . db . sync ( ) <EOL> def _db_print ( self ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> cur = self . db . cursor ( ) <EOL> try : <EOL> key , data = cur . first ( ) <EOL> while <NUM_LIT:1> : <EOL> print repr ( { key : data } ) <EOL> next = cur . next ( ) <EOL> if next : <EOL> key , data = next <EOL> else : <EOL> cur . close ( ) <EOL> return <EOL> except db . DBNotFoundError : <EOL> cur . close ( ) <EOL> def CreateTable ( self , table , columns ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( columns , list ) <EOL> txn = None <EOL> try : <EOL> if contains_metastrings ( table ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" ) <EOL> for column in columns : <EOL> if contains_metastrings ( column ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" ) <EOL> columnlist_key = _columns_key ( table ) <EOL> if getattr ( self . db , "<STR_LIT>" ) ( columnlist_key ) : <EOL> raise TableAlreadyExists , "<STR_LIT>" <EOL> txn = self . env . txn_begin ( ) <EOL> getattr ( self . db , "<STR_LIT>" , self . db . put ) ( columnlist_key , <EOL> pickle . dumps ( columns , <NUM_LIT:1> ) , txn = txn ) <EOL> tablelist = pickle . loads ( getattr ( self . db , "<STR_LIT>" , <EOL> self . db . get ) ( _table_names_key , txn = txn , flags = db . DB_RMW ) ) <EOL> tablelist . append ( table ) <EOL> self . db . delete ( _table_names_key , txn = txn ) <EOL> getattr ( self . db , "<STR_LIT>" , self . db . put ) ( _table_names_key , <EOL> pickle . dumps ( tablelist , <NUM_LIT:1> ) , txn = txn ) <EOL> txn . commit ( ) <EOL> txn = None <EOL> except db . DBError , dberror : <EOL> if txn : <EOL> txn . abort ( ) <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> raise TableDBError , dberror [ <NUM_LIT:1> ] <EOL> else : <EOL> raise TableDBError , dberror . args [ <NUM_LIT:1> ] <EOL> def ListTableColumns ( self , table ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( table , str ) <EOL> if contains_metastrings ( table ) : <EOL> raise ValueError , "<STR_LIT>" <EOL> columnlist_key = _columns_key ( table ) <EOL> if not getattr ( self . db , "<STR_LIT>" ) ( columnlist_key ) : <EOL> return [ ] <EOL> pickledcolumnlist = getattr ( self . db , "<STR_LIT>" , <EOL> self . db . get ) ( columnlist_key ) <EOL> if pickledcolumnlist : <EOL> return pickle . loads ( pickledcolumnlist ) <EOL> else : <EOL> return [ ] <EOL> def ListTables ( self ) : <EOL> """<STR_LIT>""" <EOL> pickledtablelist = self . db . get_get ( _table_names_key ) <EOL> if pickledtablelist : <EOL> return pickle . loads ( pickledtablelist ) <EOL> else : <EOL> return [ ] <EOL> def CreateOrExtendTable ( self , table , columns ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( columns , list ) <EOL> try : <EOL> self . CreateTable ( table , columns ) <EOL> except TableAlreadyExists : <EOL> txn = None <EOL> try : <EOL> columnlist_key = _columns_key ( table ) <EOL> txn = self . env . txn_begin ( ) <EOL> oldcolumnlist = pickle . loads ( <EOL> getattr ( self . db , "<STR_LIT>" , <EOL> self . db . get ) ( columnlist_key , txn = txn , flags = db . DB_RMW ) ) <EOL> oldcolumnhash = { } <EOL> for c in oldcolumnlist : <EOL> oldcolumnhash [ c ] = c <EOL> newcolumnlist = copy . copy ( oldcolumnlist ) <EOL> for c in columns : <EOL> if not c in oldcolumnhash : <EOL> newcolumnlist . append ( c ) <EOL> if newcolumnlist != oldcolumnlist : <EOL> self . db . delete ( columnlist_key , txn = txn ) <EOL> getattr ( self . db , "<STR_LIT>" , self . db . put ) ( columnlist_key , <EOL> pickle . dumps ( newcolumnlist , <NUM_LIT:1> ) , <EOL> txn = txn ) <EOL> txn . commit ( ) <EOL> txn = None <EOL> self . __load_column_info ( table ) <EOL> except db . DBError , dberror : <EOL> if txn : <EOL> txn . abort ( ) <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> raise TableDBError , dberror [ <NUM_LIT:1> ] <EOL> else : <EOL> raise TableDBError , dberror . args [ <NUM_LIT:1> ] <EOL> def __load_column_info ( self , table ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> tcolpickles = getattr ( self . db , "<STR_LIT>" , <EOL> self . db . get ) ( _columns_key ( table ) ) <EOL> except db . DBNotFoundError : <EOL> raise TableDBError , "<STR_LIT>" % ( table , ) <EOL> if not tcolpickles : <EOL> raise TableDBError , "<STR_LIT>" % ( table , ) <EOL> self . __tablecolumns [ table ] = pickle . loads ( tcolpickles ) <EOL> def __new_rowid ( self , table , txn ) : <EOL> """<STR_LIT>""" <EOL> unique = <NUM_LIT:0> <EOL> while not unique : <EOL> blist = [ ] <EOL> for x in xrange ( _rowid_str_len ) : <EOL> blist . append ( random . randint ( <NUM_LIT:0> , <NUM_LIT:255> ) ) <EOL> newid = struct . pack ( '<STR_LIT:B>' * _rowid_str_len , * blist ) <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> newid = newid . decode ( "<STR_LIT>" ) <EOL> try : <EOL> self . db . put ( _rowid_key ( table , newid ) , None , txn = txn , <EOL> flags = db . DB_NOOVERWRITE ) <EOL> except db . DBKeyExistError : <EOL> pass <EOL> else : <EOL> unique = <NUM_LIT:1> <EOL> return newid <EOL> def Insert ( self , table , rowdict ) : <EOL> """<STR_LIT>""" <EOL> txn = None <EOL> try : <EOL> if not getattr ( self . db , "<STR_LIT>" ) ( _columns_key ( table ) ) : <EOL> raise TableDBError , "<STR_LIT>" <EOL> if not table in self . __tablecolumns : <EOL> self . __load_column_info ( table ) <EOL> for column in rowdict . keys ( ) : <EOL> if not self . __tablecolumns [ table ] . count ( column ) : <EOL> raise TableDBError , "<STR_LIT>" % ( column , ) <EOL> txn = self . env . txn_begin ( ) <EOL> rowid = self . __new_rowid ( table , txn = txn ) <EOL> for column , dataitem in rowdict . items ( ) : <EOL> self . db . put ( _data_key ( table , column , rowid ) , dataitem , txn = txn ) <EOL> txn . commit ( ) <EOL> txn = None <EOL> except db . DBError , dberror : <EOL> info = sys . exc_info ( ) <EOL> if txn : <EOL> txn . abort ( ) <EOL> self . db . delete ( _rowid_key ( table , rowid ) ) <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> raise TableDBError , dberror [ <NUM_LIT:1> ] , info [ <NUM_LIT:2> ] <EOL> else : <EOL> raise TableDBError , dberror . args [ <NUM_LIT:1> ] , info [ <NUM_LIT:2> ] <EOL> def Modify ( self , table , conditions = { } , mappings = { } ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> matching_rowids = self . __Select ( table , [ ] , conditions ) <EOL> columns = mappings . keys ( ) <EOL> for rowid in matching_rowids . keys ( ) : <EOL> txn = None <EOL> try : <EOL> for column in columns : <EOL> txn = self . env . txn_begin ( ) <EOL> try : <EOL> dataitem = self . db . get ( <EOL> _data_key ( table , column , rowid ) , <EOL> txn = txn ) <EOL> self . db . delete ( <EOL> _data_key ( table , column , rowid ) , <EOL> txn = txn ) <EOL> except db . DBNotFoundError : <EOL> dataitem = None <EOL> dataitem = mappings [ column ] ( dataitem ) <EOL> if dataitem is not None : <EOL> self . db . put ( <EOL> _data_key ( table , column , rowid ) , <EOL> dataitem , txn = txn ) <EOL> txn . commit ( ) <EOL> txn = None <EOL> except : <EOL> if txn : <EOL> txn . abort ( ) <EOL> raise <EOL> except db . DBError , dberror : <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> raise TableDBError , dberror [ <NUM_LIT:1> ] <EOL> else : <EOL> raise TableDBError , dberror . args [ <NUM_LIT:1> ] <EOL> def Delete ( self , table , conditions = { } ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> matching_rowids = self . __Select ( table , [ ] , conditions ) <EOL> columns = self . __tablecolumns [ table ] <EOL> for rowid in matching_rowids . keys ( ) : <EOL> txn = None <EOL> try : <EOL> txn = self . env . txn_begin ( ) <EOL> for column in columns : <EOL> try : <EOL> self . db . delete ( _data_key ( table , column , rowid ) , <EOL> txn = txn ) <EOL> except db . DBNotFoundError : <EOL> pass <EOL> try : <EOL> self . db . delete ( _rowid_key ( table , rowid ) , txn = txn ) <EOL> except db . DBNotFoundError : <EOL> pass <EOL> txn . commit ( ) <EOL> txn = None <EOL> except db . DBError , dberror : <EOL> if txn : <EOL> txn . abort ( ) <EOL> raise <EOL> except db . DBError , dberror : <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> raise TableDBError , dberror [ <NUM_LIT:1> ] <EOL> else : <EOL> raise TableDBError , dberror . args [ <NUM_LIT:1> ] <EOL> def Select ( self , table , columns , conditions = { } ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if not table in self . __tablecolumns : <EOL> self . __load_column_info ( table ) <EOL> if columns is None : <EOL> columns = self . __tablecolumns [ table ] <EOL> matching_rowids = self . __Select ( table , columns , conditions ) <EOL> except db . DBError , dberror : <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> raise TableDBError , dberror [ <NUM_LIT:1> ] <EOL> else : <EOL> raise TableDBError , dberror . args [ <NUM_LIT:1> ] <EOL> return matching_rowids . values ( ) <EOL> def __Select ( self , table , columns , conditions ) : <EOL> """<STR_LIT>""" <EOL> if not table in self . __tablecolumns : <EOL> self . __load_column_info ( table ) <EOL> if columns is None : <EOL> columns = self . tablecolumns [ table ] <EOL> for column in ( columns + conditions . keys ( ) ) : <EOL> if not self . __tablecolumns [ table ] . count ( column ) : <EOL> raise TableDBError , "<STR_LIT>" % ( column , ) <EOL> matching_rowids = { } <EOL> rejected_rowids = { } <EOL> def cmp_conditions ( atuple , btuple ) : <EOL> a = atuple [ <NUM_LIT:1> ] <EOL> b = btuple [ <NUM_LIT:1> ] <EOL> if type ( a ) is type ( b ) : <EOL> def cmp ( a , b ) : <EOL> if a == b : return <NUM_LIT:0> <EOL> if a < b : return - <NUM_LIT:1> <EOL> return <NUM_LIT:1> <EOL> if isinstance ( a , PrefixCond ) and isinstance ( b , PrefixCond ) : <EOL> return cmp ( len ( b . prefix ) , len ( a . prefix ) ) <EOL> if isinstance ( a , LikeCond ) and isinstance ( b , LikeCond ) : <EOL> return cmp ( len ( b . likestr ) , len ( a . likestr ) ) <EOL> return <NUM_LIT:0> <EOL> if isinstance ( a , ExactCond ) : <EOL> return - <NUM_LIT:1> <EOL> if isinstance ( b , ExactCond ) : <EOL> return <NUM_LIT:1> <EOL> if isinstance ( a , PrefixCond ) : <EOL> return - <NUM_LIT:1> <EOL> if isinstance ( b , PrefixCond ) : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> conditionlist = conditions . items ( ) <EOL> conditionlist . sort ( cmp_conditions ) <EOL> else : <EOL> conditionlist = [ ] <EOL> for i in conditions . items ( ) : <EOL> for j , k in enumerate ( conditionlist ) : <EOL> r = cmp_conditions ( k , i ) <EOL> if r == <NUM_LIT:1> : <EOL> conditionlist . insert ( j , i ) <EOL> break <EOL> else : <EOL> conditionlist . append ( i ) <EOL> cur = self . db . cursor ( ) <EOL> column_num = - <NUM_LIT:1> <EOL> for column , condition in conditionlist : <EOL> column_num = column_num + <NUM_LIT:1> <EOL> searchkey = _search_col_data_key ( table , column ) <EOL> if column in columns : <EOL> savethiscolumndata = <NUM_LIT:1> <EOL> else : <EOL> savethiscolumndata = <NUM_LIT:0> <EOL> try : <EOL> key , data = cur . set_range ( searchkey ) <EOL> while key [ : len ( searchkey ) ] == searchkey : <EOL> rowid = key [ - _rowid_str_len : ] <EOL> if not rowid in rejected_rowids : <EOL> if not condition or condition ( data ) : <EOL> if not rowid in matching_rowids : <EOL> matching_rowids [ rowid ] = { } <EOL> if savethiscolumndata : <EOL> matching_rowids [ rowid ] [ column ] = data <EOL> else : <EOL> if rowid in matching_rowids : <EOL> del matching_rowids [ rowid ] <EOL> rejected_rowids [ rowid ] = rowid <EOL> key , data = cur . next ( ) <EOL> except db . DBError , dberror : <EOL> if dberror . args [ <NUM_LIT:0> ] != db . DB_NOTFOUND : <EOL> raise <EOL> continue <EOL> cur . close ( ) <EOL> del rejected_rowids <EOL> if len ( columns ) > <NUM_LIT:0> : <EOL> for rowid , rowdata in matching_rowids . items ( ) : <EOL> for column in columns : <EOL> if column in rowdata : <EOL> continue <EOL> try : <EOL> rowdata [ column ] = self . db . get ( <EOL> _data_key ( table , column , rowid ) ) <EOL> except db . DBError , dberror : <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) : <EOL> if dberror [ <NUM_LIT:0> ] != db . DB_NOTFOUND : <EOL> raise <EOL> else : <EOL> if dberror . args [ <NUM_LIT:0> ] != db . DB_NOTFOUND : <EOL> raise <EOL> rowdata [ column ] = None <EOL> return matching_rowids <EOL> def Drop ( self , table ) : <EOL> """<STR_LIT>""" <EOL> txn = None <EOL> try : <EOL> txn = self . env . txn_begin ( ) <EOL> self . db . delete ( _columns_key ( table ) , txn = txn ) <EOL> cur = self . db . cursor ( txn ) <EOL> table_key = _search_all_data_key ( table ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> key , data = cur . set_range ( table_key ) <EOL> except db . DBNotFoundError : <EOL> break <EOL> if key [ : len ( table_key ) ] != table_key : <EOL> break <EOL> cur . delete ( ) <EOL> table_key = _search_rowid_key ( table ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> key , data = cur . set_range ( table_key ) <EOL> except db . DBNotFoundError : <EOL> break <EOL> if key [ : len ( table_key ) ] != table_key : <EOL> break <EOL> cur . delete ( ) <EOL> cur . close ( ) <EOL> tablelist = pickle . loads ( <EOL> getattr ( self . db , "<STR_LIT>" , self . db . get ) ( _table_names_key , <EOL> txn = txn , flags = db . DB_RMW ) ) <EOL> try : <EOL> tablelist . remove ( table ) <EOL> except ValueError : <EOL> pass <EOL> self . db . delete ( _table_names_key , txn = txn ) <EOL> getattr ( self . db , "<STR_LIT>" , self . db . put ) ( _table_names_key , <EOL> pickle . dumps ( tablelist , <NUM_LIT:1> ) , txn = txn ) <EOL> txn . commit ( ) <EOL> txn = None <EOL> if table in self . __tablecolumns : <EOL> del self . __tablecolumns [ table ] <EOL> except db . DBError , dberror : <EOL> if txn : <EOL> txn . abort ( ) <EOL> raise TableDBError ( dberror . args [ <NUM_LIT:1> ] ) </s>
