importpprintimportosimportasabimportasab.storageasab.Config.add_defaults({'asab:storage':{'type':'mongodb','aes_key':os.urandom(24)}})classMyApplication(asab.Application):asyncdefinitialize(self):# Loading the web service moduleself.add_module(asab.storage.Module)asyncdefmain(self):storage=self.get_service("asab.StorageService")# Obtain upsertor object which is associated with given "test-collection"# To create new object we keep default `version` to zerou=storage.upsertor("test-collection")u.set("foo","bar")object_id=awaitu.execute()# Get the object by its idobj=awaitstorage.get("test-collection",object_id)# Obtain upsertor object for update - specify existing `version` numberu=storage.upsertor("test-collection",obj_id=object_id,version=obj['_v'])u.set("foo","buzz")object_id=awaitu.execute()# See the resultsobj=awaitstorage.get("test-collection",object_id)print(f"Result of get by id: {object_id}")pprint.pprint(obj)# Encrypt some datau=storage.upsertor("test-collection",obj_id=object_id,version=obj['_v'])secret_message="This is a super secret message!"# Convert the message to binary format before encryptingu.set("super_secret",secret_message.encode("ascii"),encrypt=True)object_id=awaitu.execute()# See the encrypted dataobj=awaitstorage.get("test-collection",object_id)print("Encrypted data: {}".format(obj.get("super_secret")))# See the decrypted dataobj=awaitstorage.get("test-collection",object_id,decrypt=["super_secret"])print("Decrypted data: {}".format(obj.get("super_secret")))# Test the StorageService.collection() methodcoll=awaitstorage.collection("test-collection")cursor=coll.find({})print("Result of list")whileawaitcursor.fetch_next:obj=cursor.next_object()pprint.pprint(obj)awaitstorage.delete("test-collection",object_id)self.stop()if__name__=='__main__':app=MyApplication()app.run()