8000 Blob seriaslization with jsonpickle · guidotorresmx/botbuilder-python@b1b9a4f · GitHub
[go: up one dir, main page]

Skip to content

Commit b1b9a4f

Browse files
committed
Blob seriaslization with jsonpickle
1 parent 843edfc commit b1b9a4f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

libraries/botbuilder-azure/botbuilder/azure/blob_storage.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import json
22
from typing import Dict, List
33

4+
from jsonpickle import encode
5+
from jsonpickle.unpickler import Unpickler
6+
47
from 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(< 8000 span class="pl-s1">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

Comments
 (0)
0