Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/bsddb/
Upload File :
Current File : //usr/lib/python2.7/bsddb/dbtables.pyc


|_c@s!dZddlZddlZddlZddlZddlZejddkrdddlZnzejd(krddlZn\ddl	Z	e	j
Zejz)e	j
ddd	d
eddlZWdejX[yddlmZWn!ek
rddlmZnXd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/lib/python2.7/bsddb/dbtables.pyR>stTableAlreadyExistscBseZRS((RR(((s$/usr/lib/python2.7/bsddb/dbtables.pyR@stCondcBseZdZdZRS(s!This condition matches everythingcCsdS(Ni((tselfts((s$/usr/lib/python2.7/bsddb/dbtables.pyt__call__Fs(RRt__doc__R(((s$/usr/lib/python2.7/bsddb/dbtables.pyRDst	ExactCondcBs eZdZdZdZRS(s)Acts as an exact match condition functioncCs
||_dS(N(t
strtomatch(R	R((s$/usr/lib/python2.7/bsddb/dbtables.pyt__init__KscCs
||jkS(N(R(R	R
((s$/usr/lib/python2.7/bsddb/dbtables.pyRMs(RRRRR(((s$/usr/lib/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/lib/python2.7/bsddb/dbtables.pyRRscCs|t|j |jkS(N(tlenR(R	R
((s$/usr/lib/python2.7/bsddb/dbtables.pyRTs(RRRRR(((s$/usr/lib/python2.7/bsddb/dbtables.pyRPs	tPostfixCondcBs eZdZdZdZRS(s:Acts as a condition function for matching a string postfixcCs
||_dS(N(tpostfix(R	R((s$/usr/lib/python2.7/bsddb/dbtables.pyRYscCs|t|j|jkS(N(RR(R	R
((s$/usr/lib/python2.7/bsddb/dbtables.pyR[s(RRRRR(((s$/usr/lib/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/lib/python2.7/bsddb/dbtables.pyRds

cCs|jj|S(N(Rtmatch(R	R
((s$/usr/lib/python2.7/bsddb/dbtables.pyRls(RRRRt
IGNORECASERR(((s$/usr/lib/python2.7/bsddb/dbtables.pyR^st__TABLE_NAMES__s._COLUMNS__cCs|tS(N(t_columns(ttable((s$/usr/lib/python2.7/bsddb/dbtables.pyt_columns_keyuss._DATA_.s	._ROWID_.icCs|t|t|S(N(t_data(R$tcoltrowid((s$/usr/lib/python2.7/bsddb/dbtables.pyt	_data_keyscCs|t|tS(N(R&(R$R'((s$/usr/lib/python2.7/bsddb/dbtables.pyt_search_col_data_keyscCs|tS(N(R&(R$((s$/usr/lib/python2.7/bsddb/dbtables.pyt_search_all_data_keyscCs|t|tS(N(t_rowid(R$R(((s$/usr/lib/python2.7/bsddb/dbtables.pyt
_rowid_keyscCs|tS(N(R,(R$((s$/usr/lib/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/lib/python2.7/bsddb/dbtables.pytcontains_metastringsst
bsdTableDBcBseZddddddZdZdZddZdZdZdZd	Z	d
Z
dZd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 nX|j!i|_"dS(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.
        iiitcursor_py3kcBs,eZdZdZdZdZRS(cSs
||_dS(N(t	_dbcursor(R	tdbcursor((s$/usr/lib/python2.7/bsddb/dbtables.pyRscSs
|jjS(N(R4tclose(R	((s$/usr/lib/python2.7/bsddb/dbtables.pyR6scSsT|jjt|d}|dk	rP|djd|djdf}n|S(Ns	iso8859-1ii(R4t	set_rangetbytestNonetdecode(R	tsearchtv((s$/usr/lib/python2.7/bsddb/dbtables.pyR7s
cSsNt|jd}|dk	rJ|djd|djdf}n|S(Ntnextis	iso8859-1i(tgetattrR4R9R:(R	R<((s$/usr/lib/python2.7/bsddb/dbtables.pyt__next__s
(RRRR6R7R?(((s$/usr/lib/python2.7/bsddb/dbtables.pyR3s			tdb_py3kcs}eZdZd
fdZd
dZdd
dZd
dZd
ddZd
ddZ	d
dZ
d	ZRS(cSs
||_dS(N(t_db(R	R((s$/usr/lib/python2.7/bsddb/dbtables.pyRscs|jjd|S(Nttxn(RAtcursor(R	RB(R3(s$/usr/lib/python2.7/bsddb/dbtables.pyRCscSs%t|jdt|dd|S(Nthas_keys	iso8859-1RB(R>RAR8(R	tkeyRB((s$/usr/lib/python2.7/bsddb/dbtables.pyRDsicSsLt|d}|dk	r-t|d}n|jj||d|d|S(Ns	iso8859-1tflagsRB(R8R9RAtput(R	REtvalueRFRB((s$/usr/lib/python2.7/bsddb/dbtables.pyRGscSs(t|d}|jj||d|S(Ns	iso8859-1RB(R8RARG(R	RERHRB((s$/usr/lib/python2.7/bsddb/dbtables.pyt	put_bytesscSsOt|d}|jj|d|d|}|dk	rK|jd}n|S(Ns	iso8859-1RBRF(R8RAtgetR9R:(R	RERBRFR<((s$/usr/lib/python2.7/bsddb/dbtables.pyRJs
cSs+t|d}|jj|d|d|S(Ns	iso8859-1RBRF(R8RARJ(R	RERBRF((s$/usr/lib/python2.7/bsddb/dbtables.pyt	get_bytesscSs%t|d}|jj|d|S(Ns	iso8859-1RB(R8RAtdelete(R	RERB((s$/usr/lib/python2.7/bsddb/dbtables.pyRLscSs
|jjS(N(RAR6(R	((s$/usr/lib/python2.7/bsddb/dbtables.pyR6sN(RRRR9RCRDRGRIRJRKRLR6((R3(s$/usr/lib/python2.7/bsddb/dbtables.pyR@s	RDRIRBN(#R9Rt	DB_THREADt	DB_CREATEt
DB_INIT_MPOOLtDB_INIT_LOCKtDB_INIT_LOGtDB_INIT_TXNtDB_AUTO_COMMITtAttributeErrort
DB_RECOVERtDBEnvtenvt
set_lk_detecttDB_LOCK_DEFAULTtopentDB_TRUNCATEtDBtset_get_returns_nonet	set_flagstDB_DUPtDB_BTREEt
dbfilenametsystversion_infotobjectt	txn_beginR>R0RGtpickletdumpstaborttcommitt_bsdTableDB__tablecolumns(R	tfilenametdbhometcreatettruncatetmodetrecovertdbflagstmyflagstflagsforenvR@RB((R3s$/usr/lib/python2.7/bsddb/dbtables.pyRsF		"
 	'#

cCs|jdS(N(R6(R	((s$/usr/lib/python2.7/bsddb/dbtables.pyt__del__scCsT|jdk	r(|jjd|_n|jdk	rP|jjd|_ndS(N(RR9R6RW(R	((s$/usr/lib/python2.7/bsddb/dbtables.pyR6s

cCs|jj|dS(N(RWttxn_checkpoint(R	tmins((s$/usr/lib/python2.7/bsddb/dbtables.pyt
checkpointscCs|jjdS(N(Rtsync(R	((s$/usr/lib/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/lib/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/lib/python2.7/bsddb/dbtables.pytCreateTable5s<
'



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/lib/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/lib/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]}|||<qWtj|}x*|D]"}||kr|j|qqW||krL|jj|d|t|jd|jj|t	j|dd|n|jd}|j|Wqtjk
r}	|r|jntjd	krt|	dqt|	jdqXnXdS(
sCreateOrExtendTable(table, columns)

        Create a new table in the database.

        If a table of this name already exists, extend it to have any
        additional columns present in the given list as well as
        all of its current columns.
        RKRBRFRIiiiN(ii(RRRRRR9R%RWReRfRR>RRJRtcopyRRLRGRgRit_bsdTableDB__load_column_infoRRhRbRcRR(
R	R$RRBRt
oldcolumnlistt
oldcolumnhashtct
newcolumnlistR((s$/usr/lib/python2.7/bsddb/dbtables.pytCreateOrExtendTables@	
'




cCsy+t|jd|jjt|}Wn$tjk
rQtd|fnX|sktd|fntj||j|<dS(s'initialize the self.__tablecolumns dictRKsunknown table: %rN(	R>RRJR%R{RRfRRj(R	R$ttcolpickles((s$/usr/lib/python2.7/bsddb/dbtables.pyt__load_column_infoscCsd}x|sg}x-ttD]}|jtjddq"Wtjdt|}tjddkr|j	d}ny/|j
jt||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/lib/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/lib/python2.7/bsddb/dbtables.pytInserts.)


cCsyA|j|g|}|j}x|jD]}d}yx|D]}|jj}yJ|jjt|||d|}	|jjt|||d|Wntj	k
rd}	nX|||	}	|	dk	r|jj
t||||	d|n|jd}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/lib/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|jd}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/lib/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/lib/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||<n|r?||||<q?qB||kr5||=n|||<n|
j\}}qWWqQtjk
r}|jdtjkrQqQqQqQXqQW|
j~t|dkrx|j	D]\}}x|D]}||krqny&|jjt|||||<Wqtjk
r{}tjd
krR|dtjkrnqnn|jdtjkrnnd||<qXqWqWn|S(s__Select() - Used to implement Select and Delete (above)
        Returns a dictionary keyed on rowids containing dicts
        holding the row data for columns listed in the columns param
        that match the given conditions.
        * conditions is a dictionary keyed on column names
        containing callable conditions expecting the data string as an
        argument and returning a boolean.
        sunknown column: %rcSs|d}|d}t|t|krd}t|trrt|trr|t|jt|jSt|trt|tr|t|jt|jSdSt|trdSt|trdSt|trdSt|trdSdS(NicSs$||krdS||kr dSdS(Niii((tatb((s$/usr/lib/python2.7/bsddb/dbtables.pytcmps
ii(ttypeRRRRRRR
(tatupletbtupleRRR((s$/usr/lib/python2.7/bsddb/dbtables.pytcmp_conditionss$

	iiiiiN(ii(ii(RjRR9ttablecolumnsRRRRbRcRtsortt	enumeratetinsertRRRCR*R7RRR=RRtDB_NOTFOUNDR6RJR)(R	R$RRRRtrejected_rowidsRt
conditionlisttitjtktrR|t
column_numt	conditiont	searchkeytsavethiscolumndataRER}R(Rtrowdata((s$/usr/lib/python2.7/bsddb/dbtables.pyt__Selects
	
	




		c	Cs6d}y|jj}|jjt|d||jj|}t|}xXy|j|\}}Wntj	k
rPnX|t
| |krPn|jqUt|}xXy|j|\}}Wntj	k
rPnX|t
| |krPn|jq|jt
jt|jd|jjtd|dtj}y|j|Wntk
r{nX|jjtd|t|jd|jjtt
j|dd||jd}||jkr|j|=nWn<tjk
r1}|r|jnt|jdnXdS(s(Remove an entire table from the databaseRBRKRFRIiN(R9RWReRRLR%RCR+R7R{RR.R6RfRR>RJR0RtremoveRRGRgRiRjRRhRR(	R	R$RBR|t	table_keyRER}RR((s$/usr/lib/python2.7/bsddb/dbtables.pytDropsT





(RRRRtR6RwRxR~RRRRRRRRRRRR(((s$/usr/lib/python2.7/bsddb/dbtables.pyR2s&	r					0			:			,6-	(ii((()t_cvsidRRbRRRRcRftcPickletwarningstcatch_warningstwt	__enter__tfilterwarningstDeprecationWarningt__exit__tbsddb3RtImportErrortbsddbt
StandardErrorRRRR
RRRR0R#R%R&R,RR)R*R+R-R.R1R2(((s$/usr/lib/python2.7/bsddb/dbtables.pyt<module>sV