Exemplo n.º 1
0
def loaddb():
    for ii in xrange(0,10):
        db.put("key" + str(ii), "data" + str(ii))
    flags = bsddb.db.DB_NODUPDATA
#    flags = bsddb.db.DB_NOOVERWRITE
    for ii in xrange(0,10):
        db.put("multikey", "multidata" + str(ii), None, flags)
Exemplo n.º 2
0
def test4():
    print "attempt to start a new transaction while another transaction is open"
    txn1 = env.txn_begin(None, txn_flags)
    print "read records in empty database"
    print_records(db, txn1)
    print "add record with txn1"
    db.put("test4 key1", "test4 data1", txn1)
    print "read records with txn1"
    print_records(db, txn1)
    print "start a new transaction"
    txn2 = env.txn_begin(None, txn_flags)
    print "add record with txn2"
    db.put("test4 key2", "test4 data2", txn2)
    print "read records with txn2"
    print_records(db, txn2)
Exemplo n.º 3
0
def new_user(l,s,f):

    if len(l)==0:
	return '-BAD_USR'
	
    if len(l)==1:
	return '-BAD_PSSWD'

    user=l[0]
    pswd=l[1]
    
    if not re_str.search(user):
	return '-BAD_USR'

    if not re_str.search(pswd):
	return '-BAD_PSSWD'

    key='USR_' + user
    db=start_db()
    
    if db.has_key(key):
	db.delete(key)
	return '-USR_ALREADY_EXST'

    if db.put(key,str(h(pswd))) == None:
	return '+OK'
	
    return '-ISE: Unknown error'
Exemplo n.º 4
0
def test5():
    print "attempt to read the db without a txn while another transaction is open"
    txn1 = env.txn_begin(None, txn_flags)
    print "read records in empty database"
    print_records(db, txn1)
    print "read records without txn"
    print_records(db)
    print "add record with txn1"
    db.put("test5 key1", "test5 data1", txn1)
    print "read records with txn1"
    print_records(db, txn1)
    print "read records without txn"
    print_records(db)
    print "commit txn"
    txn1.commit()
    print "read records without txn"
    print_records(db)
Exemplo n.º 5
0
def test1():
    print "test 1 - abort child txn but commit parent txn"
    print_records(db)
    print "create parent txn"
    partxn = env.txn_begin(None, txn_flags)
    print "do a write inside the parent before the child"
    db.put("parent before key", "parent before data", partxn)
    print_records(db, partxn)
    uidnum = uidseq.get(1, partxn)
    print "uidnumber is", uidnum

    print "create child transaction"
    chitxn = env.txn_begin(partxn, txn_flags)

    print "do a write inside the child"
    db.put("child key", "child data", chitxn)
    print_records(db,chitxn)
    usnnum = usnseq.get(1, chitxn)
    print "usn is", usnnum

    print "abort the child txn"
    chitxn.abort()

    print_records(db,partxn)
    print "do a write inside the parent after the child"
    db.put("parent after key", "parent after data", partxn)
    print_records(db,partxn)

    print "commit the transaction"
    partxn.commit()
    print_records(db)
Exemplo n.º 6
0
def test3():
    print "test 3 - commit child and parent"
    print "create parent txn"
    partxn = env.txn_begin(None, txn_flags)
    print "read records in empty database"
    print_records(db, partxn)
#print_records(db)
    print "do a write inside the parent before the child"
    db.put("parent before key3", "parent before data3", partxn)
#print "run db_stat -C A and press Enter"
#null = sys.stdin.readline()
#print "read records"
    print_records(db, partxn)
#print "run db_stat -C A and press Enter"
#null = sys.stdin.readline()
    uidnum = uidseq.get(1, partxn)
    print "uidnumber is", uidnum
#print_records(db)
    print "create child transaction"
    chitxn = env.txn_begin(partxn, txn_flags)
    print "read records"
    print_records(db, chitxn)
    print_records(db, partxn)
#print_records(db)
    print "do a write inside the child"
    db.put("child key3", "child data3", chitxn)
    print "read records"
    print_records(db, chitxn)
    print_records(db, partxn)
#print_records(db)
    usnnum = usnseq.get(1, chitxn)
    print "usn is", usnnum
    print "commit the child txn"
    chitxn.commit()
    print "read records"
    print_records(db, partxn)
#print_records(db)
    print "do a write inside the parent after the child"
    db.put("parent after key3", "parent after data3", partxn)
    print "read records"
    print_records(db, partxn)
#print_records(db)
    print "commit the transaction"
    partxn.commit()
    print "read records"
    print_records(db)
    uidnum = uidseq.get()
    print "uidnumber is", uidnum
    usnnum = usnseq.get()
    print "usn is", usnnum
Exemplo n.º 7
0
def msg_send(l,s,f):
    if len(l)<1:
	return '-ISE:Too few params!'
	
    to=l[0]
	
    s.send("+GO_AHEAD\n")
    msg=''
    a=f.readline().strip("\r\n")
    while(a!="+0"):
	msg+=a+"\n"
	a=f.readline().strip("\r\n")
    
    db=start_db()
    
    mid=random.randint(0,2345543466359044543)
    while (db.has_key('MSG_' + str(mid))):
	mid=random.randint(0,2345543466359044543)

    db.put('MSG_' + str(mid),msg)
    msgs_dumps=db.get('MSG_USR_' + to)
    
    if msgs_dumps:
	db.delete('MSG_USR_' + to)
	msgs=pickle.loads(msgs_dumps)
    else:
	msgs={}

    msgs[mid]=1
    
    msgs_dumps=pickle.dumps(msgs)

    db.put('MSG_USR_' + to, msgs_dumps)
    db.put('MSG_FROM_' + str(mid),login)

    return '+OK'