X7ROOT File Manager
Current Path:
/opt/alt/python37/lib/python3.7/site-packages/jsons/serializers
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
jsons
/
serializers
/
📁
..
📄
__init__.py
(189 B)
📁
__pycache__
📄
default_complex.py
(244 B)
📄
default_date.py
(593 B)
📄
default_datetime.py
(909 B)
📄
default_decimal.py
(294 B)
📄
default_dict.py
(3.22 KB)
📄
default_enum.py
(612 B)
📄
default_iterable.py
(2.82 KB)
📄
default_list.py
(1.53 KB)
📄
default_object.py
(13.03 KB)
📄
default_path.py
(540 B)
📄
default_primitive.py
(1.06 KB)
📄
default_time.py
(487 B)
📄
default_timedelta.py
(379 B)
📄
default_timezone.py
(524 B)
📄
default_tuple.py
(1.48 KB)
📄
default_union.py
(1.45 KB)
📄
default_uuid.py
(393 B)
📄
default_zone_info.py
(365 B)
Editing: default_primitive.py
from typing import Optional, Any, NewType from jsons.exceptions import SerializationError def default_primitive_serializer(obj: object, cls: Optional[type] = None, **kwargs) -> object: """ Serialize a primitive; simply return the given ``obj``. :param obj: the primitive. :param cls: the type of ``obj``. :return: ``obj``. """ result = obj cls_ = cls if _is_newtype(cls): cls_ = cls.__supertype__ if cls_ and obj is not None and not isinstance(obj, cls_): try: result = cls_(obj) except ValueError as err: raise SerializationError('Could not cast "{}" into "{}"' .format(obj, cls_.__name__)) from err return result def _is_newtype(cls: Any) -> bool: try: # isinstance(cls, NewType) only works as of Python3.10. result = isinstance(cls, NewType) except TypeError: result = hasattr(cls, '__supertype__') return result
Upload File
Create Folder