sob/model.py
def marshal(
    data: abc.MarshallableTypes,
    types: Union[Iterable[Union[type, abc.Property]], abc.Types, None] = None,
    value_types: Union[
        Iterable[Union[type, abc.Property]], abc.Types, None
    ] = None,
    item_types: Union[
        Iterable[Union[type, abc.Property]], abc.Types, None
    ] = None,
) -> abc.JSONTypes:
    """
    Recursively converts data which is not serializable using the `json` module
    into formats which *can* be represented as JSON.
    """
    marshalled_data: abc.JSONTypes
    if isinstance(data, Decimal):
        # Instances of `decimal.Decimal` can'ts be serialized as JSON, so we
        # convert them to `float`
        marshalled_data = float(data)
    elif (data is None) or isinstance(data, (str, int, float)):
        # Don't do anything with `None`--this just means an attributes is not
        # used for this instance (an explicit `null` would be passed as
        # `sob.properties.types.NULL`).
        marshalled_data = data
    elif data is NULL:
        marshalled_data = None
    elif isinstance(data, abc.Model):
        marshalled_data = getattr(data, "_marshal")()
    elif types is not None:
        marshalled_data = _marshal_typed(data, types)
    elif isinstance(data, (date, datetime)):
        marshalled_data = data.isoformat()
    elif isinstance(data, (bytes, bytearray)):
        # Convert `bytes` to base-64 encoded strings
        marshalled_data = str(b64encode(data), "ascii")
    elif isinstance(data, Collection):
        marshalled_data = _marshal_collection(
            data, value_types=value_types, item_types=item_types
        )
    elif isinstance(data, SupportsBytes):
        # Convert objects which can be *cast* as `bytes` to
        # base-64 encoded strings
        marshalled_data = str(b64encode(bytes(data)), "ascii")
    else:
        raise ValueError(f"Cannot unmarshal: {repr(data)}")
    return marshalled_data

    Recursively converts data which is not serializable using the `json` module
    into formats which *can* be represented as JSON.
    
Recursively converts data which is not serializable using the `json` module
into formats which *can* be represented as JSON.
Recursively converts data which is not serializable using the ` json ` module into formats which * can * be represented as JSON .
def marshal(
    data: abc.MarshallableTypes,
    types: Union[Iterable[Union[type, abc.Property]], abc.Types, None] = None,
    value_types: Union[
        Iterable[Union[type, abc.Property]], abc.Types, None
    ] = None,
    item_types: Union[
        Iterable[Union[type, abc.Property]], abc.Types, None
    ] = None,
) -> abc.JSONTypes:
    marshalled_data: abc.JSONTypes
    if isinstance(data, Decimal):
        marshalled_data = float(data)
    elif (data is None) or isinstance(data, (str, int, float)):
        marshalled_data = data
    elif data is NULL:
        marshalled_data = None
    elif isinstance(data, abc.Model):
        marshalled_data = getattr(data, "_marshal")()
    elif types is not None:
        marshalled_data = _marshal_typed(data, types)
    elif isinstance(data, (date, datetime)):
        marshalled_data = data.isoformat()
    elif isinstance(data, (bytes, bytearray)):
        marshalled_data = str(b64encode(data), "ascii")
    elif isinstance(data, Collection):
        marshalled_data = _marshal_collection(
            data, value_types=value_types, item_types=item_types
        )
    elif isinstance(data, SupportsBytes):
        marshalled_data = str(b64encode(bytes(data)), "ascii")
    else:
        raise ValueError(f"Cannot unmarshal: {repr(data)}")
    return marshalled_data
def marshal ( data : abc . MarshallableTypes , types : Union [ Iterable [ Union [ type , abc . Property ] ] , abc . Types , None ] = None , value_types : Union [ Iterable [ Union [ type , abc . Property ] ] , abc . Types , None ] = None , item_types : Union [ Iterable [ Union [ type , abc . Property ] ] , abc . Types , None ] = None , ) -> abc . JSONTypes : marshalled_data : abc . JSONTypes if isinstance ( data , Decimal ) : marshalled_data = float ( data ) elif ( data is None ) or isinstance ( data , ( str , int , float ) ) : marshalled_data = data elif data is NULL : marshalled_data = None elif isinstance ( data , abc . Model ) : marshalled_data = getattr ( data , "_marshal" ) ( ) elif types is not None : marshalled_data = _marshal_typed ( data , types ) elif isinstance ( data , ( date , datetime ) ) : marshalled_data = data . isoformat ( ) elif isinstance ( data , ( bytes , bytearray ) ) : marshalled_data = str ( b64encode ( data ) , "ascii" ) elif isinstance ( data , Collection ) : marshalled_data = _marshal_collection ( data , value_types = value_types , item_types = item_types ) elif isinstance ( data , SupportsBytes ) : marshalled_data = str ( b64encode ( bytes ( data ) ) , "ascii" ) else : raise ValueError ( f"Cannot unmarshal: {repr(data)}" ) return marshalled_data
Recursively converts data which is not serializable using the `json` module
into formats which *can* be represented as JSON.
Recursively converts data which is not serializable using the ` json ` module into formats which * can * be represented as JSON .
"""
    Recursively converts data which is not serializable using the `json` module
    into formats which *can* be represented as JSON.
    """ # Instances of `decimal.Decimal` can'ts be serialized as JSON, so we # convert them to `float` # Don't do anything with `None`--this just means an attributes is not # used for this instance (an explicit `null` would be passed as # `sob.properties.types.NULL`). # Convert `bytes` to base-64 encoded strings # Convert objects which can be *cast* as `bytes` to # base-64 encoded strings
data
abc.MarshallableTypes
types
Union[Iterable[Union[type, abc.Property]], abc.Types, None]
value_types
Union[
        Iterable[Union[type, abc.Property]], abc.Types, None
    ]
item_types
Union[
        Iterable[Union[type, abc.Property]], abc.Types, None
    ]