ofc@s!dZddlZddlZddlZddlZddlZejddkrdddlZnzejd(krddlZn\ddl Z e j Z e j z)e j ddd d eddlZWde jX[ ydd lmZWn!ek rdd lmZnXd efd YZdefdYZdd)dYZdefdYZdefdYZdefdYZdefdYZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&d*d'YZ(dS(+s$Id$iNiiiitignoretmessages1the cPickle module has been removed in Python 3.0tcategory(tdbt TableDBErrorcBseZRS((t__name__t __module__(((s&/usr/lib64/python2.7/bsddb/dbtables.pyR>stTableAlreadyExistscBseZRS((RR(((s&/usr/lib64/python2.7/bsddb/dbtables.pyR@stCondcBseZdZdZRS(s!This condition matches everythingcCsdS(Ni((tselfts((s&/usr/lib64/python2.7/bsddb/dbtables.pyt__call__Fs(RRt__doc__R (((s&/usr/lib64/python2.7/bsddb/dbtables.pyRDst ExactCondcBs eZdZdZdZRS(s)Acts as an exact match condition functioncCs ||_dS(N(t strtomatch(R R((s&/usr/lib64/python2.7/bsddb/dbtables.pyt__init__KscCs ||jkS(N(R(R R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyR Ms(RRR RR (((s&/usr/lib64/python2.7/bsddb/dbtables.pyR Is t PrefixCondcBs eZdZdZdZRS(s9Acts as a condition function for matching a string prefixcCs ||_dS(N(tprefix(R R((s&/usr/lib64/python2.7/bsddb/dbtables.pyRRscCs|t|j |jkS(N(tlenR(R R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyR Ts(RRR RR (((s&/usr/lib64/python2.7/bsddb/dbtables.pyRPs t PostfixCondcBs eZdZdZdZRS(s:Acts as a condition function for matching a string postfixcCs ||_dS(N(tpostfix(R R((s&/usr/lib64/python2.7/bsddb/dbtables.pyRYscCs|t|j |jkS(N(RR(R R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyR [s(RRR RR (((s&/usr/lib64/python2.7/bsddb/dbtables.pyRWs tLikeCondcBs&eZdZejdZdZRS(s Acts as a function that will match using an SQL 'LIKE' style string. Case insensitive and % signs are wild cards. This isn't perfect but it should work for the simple common cases. cCsfd}x$|D]}|j|d|}q W|jdd|_tjd|jd||_dS(Ns.*+()[]?s\t%s.*t^t$(treplacetlikestrtretcompile(R Rtre_flagstchars_to_escapetchar((s&/usr/lib64/python2.7/bsddb/dbtables.pyRds  cCs|jj|S(N(Rtmatch(R R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyR ls(RRR Rt IGNORECASERR (((s&/usr/lib64/python2.7/bsddb/dbtables.pyR^st__TABLE_NAMES__s ._COLUMNS__cCs|tS(N(t_columns(ttable((s&/usr/lib64/python2.7/bsddb/dbtables.pyt _columns_keyuss._DATA_.s ._ROWID_.icCs|t|t|S(N(t_data(R$tcoltrowid((s&/usr/lib64/python2.7/bsddb/dbtables.pyt _data_keyscCs|t|tS(N(R&(R$R'((s&/usr/lib64/python2.7/bsddb/dbtables.pyt_search_col_data_keyscCs|tS(N(R&(R$((s&/usr/lib64/python2.7/bsddb/dbtables.pyt_search_all_data_keyscCs|t|tS(N(t_rowid(R$R(((s&/usr/lib64/python2.7/bsddb/dbtables.pyt _rowid_keyscCs|tS(N(R,(R$((s&/usr/lib64/python2.7/bsddb/dbtables.pyt_search_rowid_keyscCs`|jtdksT|jtdksT|jtdksT|jtdkrXdSdSdS(sVerify that the given string does not contain any metadata strings that might interfere with dbtables database operation. iiN(tfindt_table_names_keyR#R&R,(R ((s&/usr/lib64/python2.7/bsddb/dbtables.pytcontains_metastringss t bsdTableDBcBseZddddddZdZdZddZdZdZdZd Z d Z d Z d Z d Z dZiidZidZidZdZdZRS(iic s"d |_tj}|r(|tjO}ntjtjBtjBtjB|B} y|tjO}Wnt k rnnX|r| tj B} ntj |_ |j j tj|j j||| B|r|tjO}ntj|j |_|jjd|jjtj|jj|tj||B|||_tjddkrdtfdYdtffdY} | |j|_n|j j} yVt|jdt| st|jd |jjttjgdd | nWn| j n X| j!i|_"d S( sbsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600) Open database name in the dbhome Berkeley DB directory. Use keyword arguments when calling this constructor. iiit cursor_py3kcBs,eZdZdZdZdZRS(cSs ||_dS(N(t _dbcursor(R tdbcursor((s&/usr/lib64/python2.7/bsddb/dbtables.pyRscSs |jjS(N(R4tclose(R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyR6scSsT|jjt|d}|dk rP|djd|djdf}n|S(Ns iso8859-1ii(R4t set_rangetbytestNonetdecode(R tsearchtv((s&/usr/lib64/python2.7/bsddb/dbtables.pyR7s  cSsNt|jd}|dk rJ|djd|djdf}n|S(Ntnextis iso8859-1i(tgetattrR4R9R:(R R<((s&/usr/lib64/python2.7/bsddb/dbtables.pyt__next__s  (RRRR6R7R?(((s&/usr/lib64/python2.7/bsddb/dbtables.pyR3s   tdb_py3kcs}eZdZd fdZd dZdd dZd dZd ddZd ddZ d dZ d Z RS( cSs ||_dS(N(t_db(R R((s&/usr/lib64/python2.7/bsddb/dbtables.pyRscs|jjd|S(Nttxn(RAtcursor(R RB(R3(s&/usr/lib64/python2.7/bsddb/dbtables.pyRCscSs%t|jdt|dd|S(Nthas_keys iso8859-1RB(R>RAR8(R tkeyRB((s&/usr/lib64/python2.7/bsddb/dbtables.pyRDsicSsLt|d}|dk r-t|d}n|jj||d|d|S(Ns iso8859-1tflagsRB(R8R9RAtput(R REtvalueRFRB((s&/usr/lib64/python2.7/bsddb/dbtables.pyRGs cSs(t|d}|jj||d|S(Ns iso8859-1RB(R8RARG(R RERHRB((s&/usr/lib64/python2.7/bsddb/dbtables.pyt put_bytesscSsOt|d}|jj|d|d|}|dk rK|jd}n|S(Ns iso8859-1RBRF(R8RAtgetR9R:(R RERBRFR<((s&/usr/lib64/python2.7/bsddb/dbtables.pyRJs  cSs+t|d}|jj|d|d|S(Ns iso8859-1RBRF(R8RARJ(R RERBRF((s&/usr/lib64/python2.7/bsddb/dbtables.pyt get_bytesscSs%t|d}|jj|d|S(Ns iso8859-1RB(R8RAtdelete(R RERB((s&/usr/lib64/python2.7/bsddb/dbtables.pyRLscSs |jjS(N(RAR6(R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyR6sN( RRRR9RCRDRGRIRJRKRLR6((R3(s&/usr/lib64/python2.7/bsddb/dbtables.pyR@s    RDRIRBN(#R9Rt DB_THREADt DB_CREATEt DB_INIT_MPOOLt DB_INIT_LOCKt DB_INIT_LOGt DB_INIT_TXNtDB_AUTO_COMMITtAttributeErrort DB_RECOVERtDBEnvtenvt set_lk_detecttDB_LOCK_DEFAULTtopent DB_TRUNCATEtDBtset_get_returns_nonet set_flagstDB_DUPtDB_BTREEt dbfilenametsyst version_infotobjectt txn_beginR>R0RGtpickletdumpstaborttcommitt_bsdTableDB__tablecolumns( R tfilenametdbhometcreatettruncatetmodetrecovertdbflagstmyflagst flagsforenvR@RB((R3s&/usr/lib64/python2.7/bsddb/dbtables.pyRsF  "   '#  cCs|jdS(N(R6(R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyt__del__scCsT|jdk r(|jjd|_n|jdk rP|jjd|_ndS(N(RR9R6RW(R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyR6s    cCs|jj|dS(N(RWttxn_checkpoint(R tmins((s&/usr/lib64/python2.7/bsddb/dbtables.pyt checkpointscCs|jjdS(N(Rtsync(R ((s&/usr/lib64/python2.7/bsddb/dbtables.pyRx scCsdGH|jj}y]|j\}}xDti||6GH|j}|r_|\}}q,|jdSq,Wntjk r|jnXdS(s*Print the database to stdout for debuggings5******** Printing raw database for debugging ********N(RRCtfirsttreprR=R6tDBNotFoundError(R tcurREtdataR=((s&/usr/lib64/python2.7/bsddb/dbtables.pyt _db_print#s   cCst|tstd }y^t|r9tdnx)|D]!}t|r@tdq@q@Wt|}t|jd|rt dn|j j }t|jd|jj |t j|dd|t jt|jd|jjtd|d tj}|j||jjtd|t|jd|jj tt j|dd||jd }WnXtjk r}|r|jntjd krt|dqt|jdnXd S(sCreateTable(table, columns) - Create a new table in the database. raises TableDBError if it already exists or for other DB errors. s-bad table name: contains reserved metastringss.bad column name: contains reserved metastringsRDstable already existsRIiRBRKRFiiN(ii(t isinstancetlisttAssertionErrorR9R1t ValueErrorR%R>RRRWReRGRfRgtloadsRJR0tDB_RMWtappendRLRitDBErrorRhRbRcRtargs(R R$tcolumnsRBtcolumntcolumnlist_keyt tablelisttdberror((s&/usr/lib64/python2.7/bsddb/dbtables.pyt CreateTable5s<      '    cCst|tstt|r-tdnt|}t|jd|sUgSt|jd|jj|}|rt j |SgSdS(s\Return a list of columns in the given table. [] if the table doesn't exist. s-bad table name: contains reserved metastringsRDRKN( RtstrRR1RR%R>RRJRfR(R R$Rtpickledcolumnlist((s&/usr/lib64/python2.7/bsddb/dbtables.pytListTableColumnses     cCs-|jjt}|r%tj|SgSdS(s)Return a list of tables in this database.N(Rtget_getR0RfR(R tpickledtablelist((s&/usr/lib64/python2.7/bsddb/dbtables.pyt ListTablesws c Cst|tsty|j||Wntk rd}y+t|}|jj}t j t |j d|j j |d|dt j}i}x|D]}|||RRJRtcopyRRLRGRgRit_bsdTableDB__load_column_infoRRhRbRcRR( R R$RRBRt oldcolumnlistt oldcolumnhashtct newcolumnlistR((s&/usr/lib64/python2.7/bsddb/dbtables.pytCreateOrExtendTables@    '       cCsy+t|jd|jjt|}Wn$tjk rQtd|fnX|sktd|fntj||j|RRJR%R{RRfRRj(R R$t tcolpickles((s&/usr/lib64/python2.7/bsddb/dbtables.pyt__load_column_infos cCsd}x|sg}x-ttD]}|jtjddq"Wtjdt|}tjddkr|j d}ny/|j j t ||d d|dt jWnt jk rq Xd}q W|S( s"Create a new unique row identifieriitBis iso8859-1RBRFiN(txranget_rowid_str_lenRtrandomtrandinttstructtpackRbRcR:RRGR-R9tDB_NOOVERWRITEtDBKeyExistError(R R$RBtuniquetblisttxtnewid((s&/usr/lib64/python2.7/bsddb/dbtables.pyt __new_rowids ! c Csd}yt|jdt|s3tdn||jkrR|j|nx=|jD]/}|j|j|s_td|fq_q_W|j j }|j |d|}x?|j D]1\}}|jj t||||d|qW|jd}Wntjk r}tj}|rV|j|jjt||ntjd kr|t|d|dqt|jd|dnXdS( sInsert(table, datadict) - Insert a new row into the table using the keys+values from rowdict as the column values. RDs unknown tablesunknown column: %rRBiiiN(ii(R9R>RR%RRjRtkeystcountRWRet_bsdTableDB__new_rowidtitemsRGR)RiRRbtexc_infoRhRLR-RcR( R R$trowdictRBRR(tdataitemRtinfo((s&/usr/lib64/python2.7/bsddb/dbtables.pytInserts. )    c CsyA|j|g|}|j}x|jD] }d}yx|D]}|jj}yJ|jjt|||d|} |jjt|||d|Wntj k rd} nX||| } | dk r|jj t|||| d|n|j d}qGWWq1|r5|j nq1Xq1WWnEtj k r} tjdkrut| dqt| jdnXdS(sModify(table, conditions={}, mappings={}) - Modify items in rows matching 'conditions' using mapping functions in 'mappings' * table - the table name * conditions - a dictionary keyed on column names containing a condition callable expecting the data string as an argument and returning a boolean. * mappings - a dictionary keyed on column names containing a condition callable expecting the data string as an argument and returning the new string for that column. RBiiiN(ii(t_bsdTableDB__SelectRR9RWReRRJR)RLR{RGRiRhRRbRcRR( R R$t conditionstmappingstmatching_rowidsRR(RBRRR((s&/usr/lib64/python2.7/bsddb/dbtables.pytModify s@            c Csiy|j|g|}|j|}x|jD]}d}y|jj}xK|D]C}y&|jjt|||d|WqWtj k rqWXqWWy#|jjt ||d|Wntj k rnX|j d}Wq2tj k r}|r|j nq2Xq2WWnEtj k rd}tjdkrQt|dqet|jdnXdS(sDelete(table, conditions) - Delete items matching the given conditions from the table. * conditions - a dictionary keyed on column names containing condition functions expecting the data string as an argument and returning a boolean. RBiiiN(ii(RRjRR9RWReRRLR)R{R-RiRRhRbRcRR( R R$RRRR(RBRR((s&/usr/lib64/python2.7/bsddb/dbtables.pytDeleteBs6    #   cCsyT||jkr"|j|n|dkr>|j|}n|j|||}WnEtjk r}tjdkrt|dqt|j dnX|j S(sSelect(table, columns, conditions) - retrieve specific row data Returns a list of row column->value mapping dictionaries. * columns - a list of which column data to return. If columns is None, all columns will be returned. * conditions - a dictionary keyed on column names containing callable conditions expecting the data string as an argument and returning a boolean. iiiN(ii( RjRR9RRRRbRcRRtvalues(R R$RRRR((s&/usr/lib64/python2.7/bsddb/dbtables.pytSelectos  cCs||jkr|j|n|dkr;|j|}nxA||jD]/}|j|j|sLtd|fqLqLWi}i}d}tjd kr|j }|j |nvg}xm|j D]_} xVt |D];\} } || | } | dkr|j | | PqqW|j | qW|jj} d}xH|D]@\}}|d}t||}||krd}nd}y| j|\}}x|t| |krW|t }||krB| s||r||kri||RJR0RtremoveRRGRgRiRjRRhRR( R R$RBR|t table_keyRER}RR((s&/usr/lib64/python2.7/bsddb/dbtables.pytDropsT        (RRRRtR6RwRxR~RRRRRRRRRRRR(((s&/usr/lib64/python2.7/bsddb/dbtables.pyR2s& r      0   :  ,6 -  (ii((()t_cvsidRRbRRRRcRftcPickletwarningstcatch_warningstwt __enter__tfilterwarningstDeprecationWarningt__exit__tbsddb3Rt ImportErrortbsddbt StandardErrorRRRR RRRR0R#R%R&R,RR)R*R+R-R.R1R2(((s&/usr/lib64/python2.7/bsddb/dbtables.pytsV