Skip to content

Utils

IIIFBuildError

Bases: Exception

An error class that should be thrown during the build process if something goes wrong.

Source code in ckanext/iiif/builders/utils.py
32
33
34
35
36
37
38
39
40
41
42
43
class IIIFBuildError(Exception):
    """
    An error class that should be thrown during the build process if something goes
    wrong.
    """

    def __init__(self, identifier: str, message: str):
        """
        :param identifier: the IIIF resource identifier
        :param message: the error message
        """
        super().__init__(f'Failed to build {identifier} due to {message}')

__init__(identifier, message)

Parameters:

Name Type Description Default
identifier str

the IIIF resource identifier

required
message str

the error message

required
Source code in ckanext/iiif/builders/utils.py
38
39
40
41
42
43
def __init__(self, identifier: str, message: str):
    """
    :param identifier: the IIIF resource identifier
    :param message: the error message
    """
    super().__init__(f'Failed to build {identifier} due to {message}')

create_id_url(identifier)

Given the identifier of a IIIF resource, creates the full URL for it.

Parameters:

Name Type Description Default
identifier str

the IIIF resource ID

required

Returns:

Type Description
str

the full URL for the IIIF resource (e.g. a manifest)

Source code in ckanext/iiif/builders/utils.py
 6
 7
 8
 9
10
11
12
13
def create_id_url(identifier: str) -> str:
    """
    Given the identifier of a IIIF resource, creates the full URL for it.

    :param identifier: the IIIF resource ID
    :returns: the full URL for the IIIF resource (e.g. a manifest)
    """
    return toolkit.url_for('iiif.resource', identifier=identifier, _external=True)

wrap_language(value, language='none')

Wraps the given value in the appropriate structure required by IIIF to convey language options.

Parameters:

Name Type Description Default
value Union[str, List[str]]

the value/values

required
language

the language, defaults to 'none'

'none'

Returns:

Type Description
Dict[str, List[str]]

the value in the right IIIF language format

Source code in ckanext/iiif/builders/utils.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def wrap_language(
    value: Union[str, List[str]], language='none'
) -> Dict[str, List[str]]:
    """
    Wraps the given value in the appropriate structure required by IIIF to convey
    language options.

    :param value: the value/values
    :param language: the language, defaults to 'none'
    :returns: the value in the right IIIF language format
    """
    if not isinstance(value, list):
        value = [value]
    return {language: value}