11import json
22from typing import Dict , List
33
4+ from jsonpickle import encode
5+ from jsonpickle .unpickler import Unpickler
6+
47from azure .storage .blob import BlockBlobService , Blob , PublicAccess
5- from botbuilder .core import Storage , StoreItem
8+ from botbuilder .core import Storage
69
710# TODO: sanitize_blob_name
811
@@ -59,7 +62,7 @@ async def read(self, keys: List[str]) -> Dict[str, object]:
5962
6063 return items
6164
62- async def write (self , changes : Dict [str , StoreItem ]):
65+ async def write (self , changes : Dict [str , object ]):
6366 self .client .create_container (self .settings .container_name )
6467 self .client .set_container_acl (
6568 self .settings .container_name , public_access = PublicAccess .Container
@@ -71,10 +74,11 @@ async def write(self, changes: Dict[str, StoreItem]):
7174 )
7275 if e_tag :
7376 item .e_tag = e_tag .replace ('"' , '\\ "' )
77+ item_str = self ._store_item_to_str (item )
7478 self .client .create_blob_from_text (
7579 container_name = self .settings .container_name ,
7680 blob_name = name ,
77- text = str ( item ) ,
81+ text = item_str ,
7882 if_match = e_tag ,
7983 )
8084
@@ -95,8 +99,12 @@ async def delete(self, keys: List[str]):
9599 container_name = self .settings .container_name , blob_name = key
96100 )
97101
98- def _blob_to_store_item (self , blob : Blob ) -> StoreItem :
102+ def _blob_to_store_item (self , blob : Blob ) -> object :
99103 item = json .loads (blob .content )
100104 item ["e_tag" ] = blob .properties .etag
101105 item ["id" ] = blob .name
102- return StoreItem (** item )
106+ result = Unpickler ().restore (item )
107+ return result
108+
109+ def _store_item_to_str (self , item : object ) -> str :
110+ return encode (item )
0 commit comments