OXIESEC PANEL
- Current Dir:
/
/
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
jsons
/
serializers
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
03/16/2023 12:57:19 PM
rwxr-xr-x
📄
__init__.py
189 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📁
__pycache__
-
03/16/2023 12:57:19 PM
rwxr-xr-x
📄
default_complex.py
244 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_date.py
593 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_datetime.py
909 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_decimal.py
294 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_dict.py
3.22 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_enum.py
612 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_iterable.py
2.82 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_list.py
1.53 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_object.py
13.03 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_path.py
540 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_primitive.py
1.06 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_time.py
487 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_timedelta.py
379 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_timezone.py
524 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_tuple.py
1.48 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_union.py
1.45 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_uuid.py
393 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
default_zone_info.py
365 bytes
03/16/2023 12:57:19 PM
rw-r--r--
Editing: default_union.py
Close
from typing import Union from jsons._common_impl import get_class_name, NoneType from jsons._compatibility_impl import get_union_params from jsons._dump_impl import dump from jsons.exceptions import JsonsError, SerializationError def default_union_serializer(obj: object, cls: Union, **kwargs) -> object: """ Serialize an object to any matching type of the given union. The first successful serialization is returned. :param obj: The object that is to be serialized. :param cls: The Union type with a generic (e.g. Union[str, int]). :param kwargs: Any keyword arguments that are passed through the serialization process. :return: An object of the first type of the Union that could be serialized successfully. """ sub_types = get_union_params(cls) # Cater for Optional[...]/Union[None, ...] first to avoid blindly # string-ifying None in later serializers. if obj is None and NoneType in sub_types: return obj for sub_type in sub_types: try: return dump(obj, sub_type, **kwargs) except JsonsError: pass # Try the next one. else: args_msg = ', '.join([get_class_name(cls_) for cls_ in get_union_params(cls)]) err_msg = ('Could not match the object of type "{}" to any type of ' 'the Union: {}'.format(type(obj), args_msg)) raise SerializationError(err_msg)