22from typing import List
33from typing import Optional
44
5+ from cryptojwt .utils import as_bytes
56from cryptojwt .utils import importer
67from cryptojwt .utils import qualified_name
78
@@ -17,8 +18,11 @@ def __init__(self):
1718 pass
1819
1920 def dump_attr (self , cls , item , exclude_attributes : Optional [List [str ]] = None ) -> dict :
20- if cls in [None , 0 , "" , [], {}, bool ]:
21- val = item
21+ if cls in [None , 0 , "" , [], {}, bool , b'' ]:
22+ if cls == b'' :
23+ val = as_bytes (item )
24+ else :
25+ val = item
2226 elif isinstance (item , Message ):
2327 val = {qualified_name (item .__class__ ): item .to_dict ()}
2428 elif cls == object :
@@ -53,11 +57,13 @@ def dump(self, exclude_attributes: Optional[List[str]] = None) -> dict:
5357 def local_load_adjustments (self , ** kwargs ):
5458 pass
5559
56- def load_attr (self ,
57- cls : Any ,
58- item : dict ,
59- init_args : Optional [dict ] = None ,
60- load_args : Optional [dict ] = None ) -> Any :
60+ def load_attr (
61+ self ,
62+ cls : Any ,
63+ item : dict ,
64+ init_args : Optional [dict ] = None ,
65+ load_args : Optional [dict ] = None ,
66+ ) -> Any :
6167 if load_args :
6268 _kwargs = {"load_args" : load_args }
6369 _load_args = load_args
@@ -68,8 +74,11 @@ def load_attr(self,
6874 if init_args :
6975 _kwargs ["init_args" ] = init_args
7076
71- if cls in [None , 0 , "" , [], {}, bool ]:
72- val = item
77+ if cls in [None , 0 , "" , [], {}, bool , b'' ]:
78+ if cls == b'' :
79+ val = as_bytes (item )
80+ else :
81+ val = item
7382 elif cls == object :
7483 val = importer (item )
7584 elif isinstance (cls , list ):
@@ -98,9 +107,7 @@ def load_attr(self,
98107
99108 return val
100109
101- def load (self , item : dict ,
102- init_args : Optional [dict ] = None ,
103- load_args : Optional [dict ] = None ):
110+ def load (self , item : dict , init_args : Optional [dict ] = None , load_args : Optional [dict ] = None ):
104111
105112 if load_args :
106113 _kwargs = {"load_args" : load_args }
0 commit comments