2016-06-21 03:00:02 -04:00
|
|
|
try:
|
|
|
|
import btree
|
2016-07-30 19:29:05 -04:00
|
|
|
import uio
|
2016-06-21 03:00:02 -04:00
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
|
|
|
import sys
|
|
|
|
sys.exit()
|
|
|
|
|
2016-07-30 19:29:05 -04:00
|
|
|
#f = open("_test.db", "w+b")
|
|
|
|
f = uio.BytesIO()
|
|
|
|
db = btree.open(f)
|
|
|
|
|
2016-06-21 03:00:02 -04:00
|
|
|
db[b"foo3"] = b"bar3"
|
|
|
|
db[b"foo1"] = b"bar1"
|
|
|
|
db[b"foo2"] = b"bar2"
|
|
|
|
db[b"bar1"] = b"foo1"
|
|
|
|
|
|
|
|
print(db[b"foo2"])
|
|
|
|
try:
|
|
|
|
print(db[b"foo"])
|
|
|
|
except KeyError:
|
|
|
|
print("KeyError")
|
|
|
|
print(db.get(b"foo"))
|
|
|
|
print(db.get(b"foo", b"dflt"))
|
|
|
|
|
|
|
|
del db[b"foo2"]
|
|
|
|
try:
|
|
|
|
del db[b"foo"]
|
|
|
|
except KeyError:
|
|
|
|
print("KeyError")
|
|
|
|
|
|
|
|
for k, v in db.items():
|
|
|
|
print((k, v))
|
|
|
|
|
|
|
|
print("---")
|
|
|
|
for k, v in db.items(None, None):
|
|
|
|
print((k, v))
|
|
|
|
|
|
|
|
print("---")
|
|
|
|
for k, v in db.items(b"f"):
|
|
|
|
print((k, v))
|
|
|
|
|
|
|
|
print("---")
|
|
|
|
for k, v in db.items(b"f", b"foo3"):
|
|
|
|
print((k, v))
|
|
|
|
|
|
|
|
print("---")
|
|
|
|
for k, v in db.items(None, b"foo3"):
|
|
|
|
print((k, v))
|
|
|
|
|
|
|
|
print("---")
|
|
|
|
for k, v in db.items(b"f", b"foo3", btree.INCL):
|
|
|
|
print((k, v))
|
|
|
|
|
|
|
|
print("---")
|
|
|
|
for k, v in db.items(None, None, btree.DESC):
|
|
|
|
print((k, v))
|
|
|
|
|
|
|
|
print(list(db.keys()))
|
|
|
|
print(list(db.values()))
|
2016-06-24 16:43:20 -04:00
|
|
|
|
|
|
|
for k in db:
|
|
|
|
print(k)
|
2016-07-23 17:30:32 -04:00
|
|
|
|
|
|
|
db.close()
|
2016-07-30 19:29:05 -04:00
|
|
|
f.close()
|