zodb存储的只读包装
readonlystorage的Python项目详细描述
只读存储器
普通ZODB存储的简单只读包装。
importZODB# Let's set a read-write DemoStoragerw_storage=ZODB.DemoStorage.DemoStorage()rw_db=ZODB.DB(rw_storage)# And now, let's set a ReadOnlyStorage around it.ro_storage=readonlystorage.ReadOnlyStorage(rw_storage)ro_db=ZODB.DB(ro_storage)# Now, add some datarw_conn=rw_db.open()rw_conn.root()["foo"]="bar"rw_conn.transaction_manager.commit()rw_conn.close()# Read the dataro_conn=ro_db.open()assert"bar"==ro_conn.root()["foo"]ro_conn.root()["foo"]="anything"ro_conn.transaction_manager.commit()# This one would emit a ZODB.POSException.ReadOnlyError!ro_conn.close()