swh.web.api.serializers module#

class swh.web.api.serializers.SoftLimitsIntegerField(*args, **kwargs)[source]#

Bases: IntegerField

An IntegerField that soft-enforce min/max values.

When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.

to_internal_value(data) int[source]#

Before returning data limit its value to min_value & max_value.

Parameters:

data – a string representation of a value

Returns:

An integer between min_value & max_value

class swh.web.api.serializers.SWHIDField(*args, **kwargs)[source]#

Bases: CharField

A SWHID field.

When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.

to_internal_value(data: str) str[source]#

Validate a SWHID.

Parameters:

value – a string

Raises:

serializers.ValidationError – invalid SWHID

Returns:

a string

class swh.web.api.serializers.IRIField(*args, **kwargs)[source]#

Bases: CharField

An Internationalized Resource Identifier field.

Requires a valid IRI value and limits its length to 4096, can be used to handle origin URLS.

Defaults max_length to 4096.

to_internal_value(data: str) str[source]#

Validate the IRI.

Parameters:

data – a string

Raises:

serializers.ValidationError – invalid IRI

Returns:

an URI