Skip to content

Commit

Permalink
feat: add configurable factories for pickle and json byte wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwhalen committed Dec 4, 2024
1 parent 689d0f6 commit 4906f8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions dol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def ihead(store, n=1):
chain_get, # a function to perform chained get operations (i.e. path keys get)
written_bytes, # transform a file-writing function into a bytes-writing function
written_key, # writes an object to a key and returns the key.
read_from_bytes, # transform a file-reading function into a bytes-reading function
)

from dol.trans import (
Expand Down
16 changes: 16 additions & 0 deletions dol/filesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,22 @@ class TextFiles(FileStringPersister):
json_bytes_wrap = wrap_kvs(obj_of_data=json.loads, data_of_obj=json.dumps)


# And two factories to make the above more configurable:
def mk_pickle_bytes_wrap(*, loads_kwargs: dict, dumps_kwargs: dict) -> Callable:
""""""
return wrap_kvs(
obj_of_data=partial(pickle.loads, **loads_kwargs),
data_of_obj=partial(pickle.dumps, **dumps_kwargs),
)


def mk_json_bytes_wrap(*, loads_kwargs: dict, dumps_kwargs: dict) -> Callable:
return wrap_kvs(
obj_of_data=partial(json.loads, **loads_kwargs),
data_of_obj=partial(json.dumps, **dumps_kwargs),
)


@pickle_bytes_wrap
class PickleFiles(Files):
"""A store of pickles"""
Expand Down

0 comments on commit 4906f8f

Please sign in to comment.