Skip to content

Commit

Permalink
Serialize bytes (#341)
Browse files Browse the repository at this point in the history
* encode bytes

* test

* lint

* version
  • Loading branch information
rogelioLpz authored Dec 27, 2023
1 parent 970c352 commit 27d73ed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cuenca_validations/validators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import datetime as dt
from enum import Enum
from typing import Any, Callable, List, Union
Expand Down Expand Up @@ -30,6 +31,8 @@ def sanitize_item(item: Any, default: Callable = None) -> Any:
sanitize_dict(e) if isinstance(e, dict) else sanitize_item(e)
for e in item
]
elif isinstance(item, bytes):
rv = base64.b64encode(item).decode('utf-8')
elif isinstance(item, Enum):
rv = item.value
elif hasattr(item, 'to_dict'):
Expand Down
2 changes: 1 addition & 1 deletion cuenca_validations/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.11.21'
__version__ = '0.11.22'
1 change: 1 addition & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_count(count, truth):
(today, today.isoformat()),
(now, utcnow.isoformat()),
(TestClass(uno='uno'), dict(uno='uno', dos='dos')),
(b'test', 'dGVzdA=='), # b64 encode
],
)
def test_json_encoder(value, result):
Expand Down

0 comments on commit 27d73ed

Please sign in to comment.